File tree 4 files changed +483
-1
lines changed
4 files changed +483
-1
lines changed Original file line number Diff line number Diff line change 46
46
- name : ' namespace_pkg_all_import: import from .all of a namespace package'
47
47
hint : |
48
48
Sage library code should not import from sage.PAC.KAGE.all when sage.PAC.KAGE is an implicit
49
- Hint: namespace package. Type import_statements("SOME_IDENTIFIER") to find a more specific import.
49
+ Hint: namespace package. Type import_statements("SOME_IDENTIFIER") to find a more specific import,
50
+ Hint: or use 'sage --fiximports' to fix automatically in the source file.
51
+ # Keep in sync with SAGE_ROOT/src/sage/misc/replace_dot_all.py
50
52
pattern : ' from\s+sage(|[.](arith|categories|combinat|ext|graphs(|[.]decompositions)|interfaces|libs|matrix|misc|numerical(|[.]backends)|rings|sets))[.]all\s+import'
51
53
filePattern : ' .*[.](py|pyx|pxi)$'
52
54
error : false # Make this a warning instead of an error for now
Original file line number Diff line number Diff line change @@ -479,6 +479,13 @@ usage_advanced() {
479
479
echo " Sage documentation for \" string\" ."
480
480
echo " --search_src ... -- same as --grep"
481
481
echo " --search_doc ... -- same as --grepdoc"
482
+ echo " --fixdoctests file.py"
483
+ echo " -- Run doctests and replace output of failing doctests"
484
+ echo " with actual output."
485
+ echo " --fiximports <files|dir>"
486
+ echo " -- Replace imports from sage.PAC.KAGE.all by specific"
487
+ echo " imports when sage.PAC.KAGE is an implicit namespace"
488
+ echo " package"
482
489
fi
483
490
echo " --sh [...] -- run a shell with Sage environment variables"
484
491
echo " as they are set in the runtime of Sage"
@@ -974,6 +981,11 @@ if [ "$1" = '-startuptime' -o "$1" = '--startuptime' ]; then
974
981
exec sage-startuptime.py " $@ "
975
982
fi
976
983
984
+ if [ " $1 " = ' -fiximports' -o " $1 " = ' --fiximports' ]; then
985
+ shift
986
+ exec sage-python -m sage.misc.replace_dot_all " $@ "
987
+ fi
988
+
977
989
if [ " $1 " = ' -tox' -o " $1 " = ' --tox' ]; then
978
990
shift
979
991
if [ -n " $SAGE_SRC " -a -f " $SAGE_SRC /tox.ini" ]; then
Original file line number Diff line number Diff line change @@ -274,6 +274,10 @@ distribution -- which then must be declared as a run-time dependency.
274
274
the ``sage: `` prompt. In particular, no Sage library code should import from
275
275
:mod: `sage.rings.all `.
276
276
277
+ To audit the Sage library for such imports, use ``sage --tox -e relint ``.
278
+ In most cases, the imports can be fixed automatically using the
279
+ tool ``sage --fiximports ``.
280
+
277
281
- Replace module-level imports by method-level imports. Note that
278
282
this comes with a small runtime overhead, which can become
279
283
noticeable if the method is called in tight inner loops.
You can’t perform that action at this time.
0 commit comments