sage.{modular,schemes}: Modularization fixes for imports; update sage -fiximports, add relint pattern #35884
Conversation
SageMath version 10.1.beta7, Release Date: 2023-07-20
|
The Linter failure is unrelated and fixed in #35974 |
|
|
||
| import sage.matrix.all as matrix | ||
| from sage.matrix.constructor import Matrix as matrix | ||
| import sage.schemes.hyperelliptic_curves.monsky_washnitzer |
There was a problem hiding this comment.
why not just from sage.matrix.constructor import matrix?
There was a problem hiding this comment.
OK, done (in all places)
| from sage.structure.sage_object import SageObject | ||
|
|
||
| lazy_import('sage.rings.padics.factory', 'Qp', as_='pAdicField') | ||
|
|
There was a problem hiding this comment.
Why only this is lazy-imported while PrecisionError from sage.rings.padics.precision_error is just imported?
There was a problem hiding this comment.
sage.rings.padics.precision_error is shipped by sagemath-categories
One cannot do try: ... except ... with a LazyImport
|
|
||
| from . import hecke_operator | ||
| lazy_import('sage.modular.modsym', 'hecke_operator') | ||
|
|
There was a problem hiding this comment.
Why is this lazy-imported?
There was a problem hiding this comment.
IIRC, via .hecke it depends on .arithgroup, which I had some difficulties with
|
|
||
| from .heilbronn import HeilbronnCremona, HeilbronnMerel | ||
| lazy_import('sage.modular.modsym.heilbronn', ['HeilbronnCremona', 'HeilbronnMerel']) | ||
|
|
There was a problem hiding this comment.
How do you decide that this should be lazy-imported?
There was a problem hiding this comment.
It has a compile-time dependency on FLINT and won't be shipped in sagemath-schemes
There was a problem hiding this comment.
You meant sagemath-modular?
…xargs sed -i.bak 's/from sage.matrix.constructor import Matrix as matrix/from sage.matrix.constructor import matrix/'
| pattern: '^import\s+sage(|[.](combinat|crypto|databases|data_structures|dynamics|ext|game_theory|games|geometry|graphs|groups|interfaces|manifolds|matrix|matroids|misc|modules|monoids|numerical|probability|quadratic_forms|quivers|rings|sat|schemes|sets|stats|symbolic|tensor)[a-z0-9_.]*|[.]libs)[.]all' | ||
| # imports from .all are allowed in all.py; also allow in some modules that need sage.all | ||
| filePattern: '(.*/|)(?!(all|benchmark|dev_tools|parsing|sage_eval|explain_pickle|.*_test))[^/.]*[.](py|pyx|pxi)$' | ||
|
|
There was a problem hiding this comment.
You don't add explain_pickle also in L54?
src/sage/misc/replace_dot_all.py
Outdated
|
|
||
| def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex=None, verbose=False): | ||
| excluded_file_regex = 'auto-methods|replace_dot_all' | ||
|
|
There was a problem hiding this comment.
You may want r' like below
There was a problem hiding this comment.
Do we actually need L388? The argument excluded_file_regex of walkdir_replace_dot_all gets the default value. No?
|
To justify fixes of modularization-anti-pattern imports, I think each file should be annotated with the distribution which the file belongs to (is installed by). Do we already have a standard style for the annotation? For I think that the future incremental test workflow should run |
|
As more files of the sage library get included to newly born distributions, the work practice of a sage developer should change much, albeit there has been little change in the practice up to now. A developer would modify a file such that the file does not break in the distribution it belongs to. If doctests that need other distributions are added, then he needs to test the doctests in another sage install where the additional distributions are available as well. If the above is right, perhaps we should also update the developer manual to reflect the changing work practice. In the worst, a developer would feel like that he/she is expelled from their paradise (where one can import anything from anywhere), after they were scared by the huge flood of optional tags to doctests. |
Yes, that's |
Yes, that's for sure one of the tests to run, but sometimes one also may want to test with extras added to enable more tests.
Right. |
Yes, that's a great point. While #35749 is adding a detailed description of how to test in a modularized setting, something has yet to be added to the tutorials that describe the development workflow.
There is certainly a potential for developer frustration after we make failures of the modularized distributions hard errors. This is something to watch out for and mitigate. |
Certainly adding those annotations is a huge task and error-prone, and it is good that there is a one source of truth. That one source of truth should be Hence it would be nice that we can add the annotations automatically from the manifest files, perhaps as part of the bootstrap. I asked chatGPT how to do that. It answered But this does not work with me. Its second answer is This seems to work. I ran the command in Does this make sense? |
Right now, this is true to some extent, but it's a bit more complicated actually. Some of the I'm hoping to unify and simplify this soon; not sure if I really want to keep the MANIFEST mechanism.
This can't be part of the bootstrap because it would need to modify source files that are under version control. But it would be indeed be very useful as a developer tool when making changes to the contents of the distributions. I'm currently doing this with very primitive tools. |
A better command is |
We may use MANIFEST (or something renamed) as a tool to mass-add the file annotations, but use the file annotations as the one source of truth. From developer's point of view, I think both mechanisms would be useful. |
| import sage.rings.all | ||
| from sage.modules.free_module import FreeModule, is_FreeModule | ||
| from sage.rings.integer import Integer | ||
|
|
There was a problem hiding this comment.
Couldn't we get rid of is_FreeModule on the way?
There was a problem hiding this comment.
Perhaps not in this PR...
|
Please soothe the linter. Otherwise, looks good to me. |
|
Thank you! |
|
SageMath version 10.1.beta8, Release Date: 2023-07-30
SageMath version 10.1.beta9, Release Date: 2023-08-05
|
Documentation preview for this PR (built with commit bcd1d6e; changes) is ready! 🎉 |
sagemathgh-35884: `sage.{modular,schemes}`: Modularization fixes for imports; update `sage -fiximports`, add relint pattern <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes sagemath#12345", use "Add a new method to multiply two integers" --> ### 📚 Description <!-- Describe your changes here in detail. --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> - Part of: sagemath#29705 - Cherry-picked from: sagemath#35095 <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> - Depends on sagemath#35974 (to soothe the linter) <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#35884 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee, Matthias Köppe
sagemathgh-36135: `sage -fixdistributions` <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> This is a new maintenance command for adding/updating `# sage_setup: distribution` directives at the top of source files. Based on a discussion in sagemath#35884 (comment) <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> - Part of: sagemath#29705 - Cherry-picked from: sagemath#35095 <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> - Depends on sagemath#36533 (CI fix) <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36135 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee, Matthias Köppe
sagemathgh-36135: `sage -fixdistributions` <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes sagemath#1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> This is a new maintenance command for adding/updating `# sage_setup: distribution` directives at the top of source files. Based on a discussion in sagemath#35884 (comment) <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes sagemath#12345". --> - Part of: sagemath#29705 - Cherry-picked from: sagemath#35095 <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - sagemath#12345: short description why this is a dependency - sagemath#34567: ... --> - Depends on sagemath#36533 (CI fix) <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: sagemath#36135 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee, Matthias Köppe
📚 Description
📝 Checklist
⌛ Dependencies
src/sage/schemes/projective/proj_bdd_height.py: Fix markup #35974 (to soothe the linter)