sagemath/sage

Refactoring tool to fix modularization anti-patterns

Closed this issue · 40 comments

The new command sage --fiximports replaces imports from sage.PAC.KAGE.all by more specific imports when sage.PAC.KAGE is an implicit namespace package.

Part of Meta-ticket #34201

Depends on #34849

CC: @alexchandler100

Component: scripts

Author: Alex Chandler, Matthias Koeppe

Branch/Commit: u/mkoeppe/replace_dot_all @ e74dbf6

Reviewer: Matthias Koeppe, Alex Chandler

Issue created by migration from https://trac.sagemath.org/ticket/34945

Branch pushed to git repo; I updated commit sha1. New commits:

7a54612New command 'sage --fiximports', invokes sage.misc.replace_dot_all
294e3e9src/sage/misc/replace_dot_all.py: Break some long lines

Changed commit from 294e3e9 to b8b4372

Branch pushed to git repo; I updated commit sha1. New commits:

057dfb5src/sage/misc/replace_dot_all.py: Pass package_regex, not regex including 'import '
b8b4372src/sage/misc/replace_dot_all.py (make_replacements_in_file): Add optional arg 'output'

Changed commit from b8b4372 to 01efec0

Branch pushed to git repo; I updated commit sha1. New commits:

46a15bfsrc/sage/misc/replace_dot_all.py: Pass package_regex, not regex including 'import ' (fixup)
2cbbf2dsrc/sage/misc/replace_dot_all.py: Use more 'with open'
29e5ddbsrc/sage/misc/replace_dot_all.py: Replace sort_log_messages by print_log_messages
01efec0src/sage/misc/replace_dot_all.py: Use endswith()

Branch pushed to git repo; I updated commit sha1. New commits:

810d982src/sage/misc/replace_dot_all.py: Replace -l with positional argument, handle multiple files/dirs, do not use directory prefix

Changed commit from 01efec0 to 810d982

Changed commit from 810d982 to dbcccc1

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

dbcccc1src/sage/misc/replace_dot_all.py: Replace -l with positional argument, handle multiple files/dirs, do not use directory prefix

Branch pushed to git repo; I updated commit sha1. This was a forced push. New commits:

491805dsrc/sage/misc/replace_dot_all.py: Replace -l with positional argument, handle multiple files/dirs, do not use directory prefix

Changed commit from dbcccc1 to 491805d

Changed commit from 491805d to bf5e6d2

Branch pushed to git repo; I updated commit sha1. New commits:

8cef447src/sage/misc/replace_dot_all.py: Restore print_log_messages lost in previous commit
aa5f1e4src/sage/misc/replace_dot_all.py: Clean docstrings, uncamelcaps
202cdc5src/sage/misc/replace_dot_all.py: Update doctests
bf5e6d2src/sage/misc/replace_dot_all.py: Simplify some 'if' conditions

Changed commit from bf5e6d2 to b426778

Branch pushed to git repo; I updated commit sha1. New commits:

b426778src/sage/misc/replace_dot_all.py: Doc updates, pycodestyle fixes

Branch pushed to git repo; I updated commit sha1. New commits:

685680bsrc/sage/misc/replace_dot_all.py: Use isinstance instead of type(...) == ...

Changed commit from b426778 to 685680b

Changed commit from 685680b to 0b8dd2f

Branch pushed to git repo; I updated commit sha1. New commits:

0b8dd2fsrc/sage/misc/replace_dot_all.py: Fixup

Changed commit from 0b8dd2f to 1c19d43

Branch pushed to git repo; I updated commit sha1. New commits:

d296b7csrc/sage/misc/replace_dot_all.py: Replace 'row number', 'line number' by :
ac83a49src/sage/misc/replace_dot_all.py: Use __import__
fe617e9src/sage/misc/replace_dot_all.py: Fold parse_arguments into main
1c19d43src/sage/misc/replace_dot_all.py: Fix doctests

Reviewer: Matthias Koeppe, ...

Changed author from Alex Chandler to Alex Chandler, Matthias Koeppe

Branch pushed to git repo; I updated commit sha1. New commits:

23dff24src/sage/misc/replace_dot_all.py: Simplify print_log_messages, fold into main

Changed commit from 1c19d43 to 23dff24

Changed commit from 23dff24 to 568c538

Branch pushed to git repo; I updated commit sha1. New commits:

568c538src/sage/misc/replace_dot_all.py: Use os.path.join more

Branch pushed to git repo; I updated commit sha1. New commits:

eef9cd5src/doc/en/developer/packaging_sage_library.rst: Mention relint, sage --fiximports

Changed commit from 568c538 to eef9cd5

comment:17

Alex, your code works well. I have only made minor changes that bring the command line interface in line with similar tools, and some style changes.

It has proper doctest coverage now and passes the code style tests.

If you have a chance to look through my changes, you can add your name to "Reviewers"

Changed commit from eef9cd5 to e74dbf6

Branch pushed to git repo; I updated commit sha1. New commits:

e74dbf6src/sage/misc/replace_dot_all.py: Add copyright notice

Description changed:

--- 
+++ 
@@ -1 +1,3 @@
+The new command `sage --fiximports` replaces imports from `sage.PAC.KAGE.all` by more specific imports when `sage.PAC.KAGE` is an implicit namespace package.
 
+Part of Meta-ticket #34201

Dependencies: #34849

comment:20

The Lint and Build&Test failures are unrelated to the changes here.

comment:21

I've taken a look, and the changes all look great to me. I've added my name to the reviewers.

Changed reviewer from Matthias Koeppe, ... to Matthias Koeppe, Alex Chandler

Merged in 10.0.beta0