Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace relative imports by absolute ones in sage.{algebras,arith,categories,cpython,data_structures,misc,modular,rings,sat,symbolic} #36666

Merged
merged 3 commits into from
Dec 10, 2023

Conversation

mkoeppe
Copy link
Member

@mkoeppe mkoeppe commented Nov 6, 2023

Final chunk of the cherry-pick from #35095 for #36228, see also #36572 (comment)

This PR overlaps with #36572, #36588, #36589, but it does not touch .all* files (no changes there are needed for #36228), thus avoiding conflicts with #35095 (see also #36524 (comment))

📝 Checklist

  • 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

@tobiasdiez
Copy link
Contributor

So you don't want to resolve merge conflicts with your PR, but instead force me to do it?!

@mkoeppe
Copy link
Member Author

mkoeppe commented Nov 7, 2023

So you don't want to resolve merge conflicts with your PR, but instead force me to do it?!

Tobias, I know that you know all of the following -- but I'll explain it for the audience:
This is a "common denominator PR", which I prepared carefully so that it avoids conflicts.
Indeed, I have just rebased your #36572, #36588, #36589 on top of it, simply by typing gh pr checkout 36572, then git rebase absolute_cimport_sage_arith, then git push --force. The rebase happened automatically, with no need for conflict resolution.

Copy link
Contributor

@dcoudert dcoudert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and passes tests on Fedora 35.

@tobiasdiez
Copy link
Contributor

So you don't want to resolve merge conflicts with your PR, but instead force me to do it?!

Tobias, I know that you know all of the following -- but I'll explain it for the audience: This is a "common denominator PR", which I prepared carefully so that it avoids conflicts. Indeed, I have just rebased your #36572, #36588, #36589 on top of it, simply by typing gh pr checkout 36572, then git rebase absolute_cimport_sage_arith, then git push --force. The rebase happened automatically, with no need for conflict resolution.

And how is that helping with these PRs being in conflict with #35095? You have to resolve these conflicts eventually so why not now?

@dcoudert
Copy link
Contributor

dcoudert commented Nov 7, 2023

I'm not setting this to positive review yet as the priority is to clarify the situation with respect to #36572, #36588, and #36589.

@mkoeppe
Copy link
Member Author

mkoeppe commented Nov 7, 2023

Tobias, again you are abusing your privileges as a member of the Triage group.

@jhpalmieri
Copy link
Member

I'm a little puzzled by the goal here. If I do git grep 'from [.]' src/sage/categories, I get some hits (in algebra_ideals.py, for instance), so you have not replaced all relative imports. As far as I can tell, you have not touched any all.py files, which are filled with relative imports. Can you clarify?

@jhpalmieri
Copy link
Member

jhpalmieri commented Nov 7, 2023

In the meantime, is the main disagreement about which changes get merged first? The other branches have been rebased on top of this one, so why not proceed with this one?

@tobiasdiez
Copy link
Contributor

Tobias, again you are abusing your privileges as a member of the Triage group.

Sorry, just clicked the wrong button. Didn't meant to close the pr

@mkoeppe
Copy link
Member Author

mkoeppe commented Nov 7, 2023

I'm a little puzzled by the goal here. If I do git grep 'from [.]' src/sage/categories, I get some hits (in algebra_ideals.py, for instance), so you have not replaced all relative imports. As far as I can tell, you have not touched any all.py files, which are filled with relative imports. Can you clarify?

Only relative imports and cimports in Cython files are relevant for the purpose of resolving the problems of current Cython 3.0.x with namespace packages. I made these changes back in September or so in #35095 because of an acute need for this in the modularization. I opened PR #36228 for the task of upstreaming this into mainline Sage.

Changes to all.py files are irrelevant for the Cython issue. Moreover, in #35095, many all.py files are completely restructured for modularization purposes, so changes there have to be done separately from changes in Sage develop.

This PR is a cherry-pick from my branch in #35095, the three commits indicated #36572 (comment), with any conflicts in cherry picking resolved to "no change".

@jhpalmieri
Copy link
Member

I'm a little puzzled by the goal here. If I do git grep 'from [.]' src/sage/categories, I get some hits (in algebra_ideals.py, for instance), so you have not replaced all relative imports. As far as I can tell, you have not touched any all.py files, which are filled with relative imports. Can you clarify?

Only relative imports and cimports in Cython files are relevant for the purpose of resolving the problems of current Cython 3.0.x with namespace packages. I made these changes back in September or so in #35095 because of an acute need for this in the modularization. I opened PR #36228 for the task of upstreaming this into mainline Sage.

Changes to all.py files are irrelevant for the Cython issue. Moreover, in #35095, many all.py files are completely restructured for modularization purposes, so changes there have to be done separately from changes in Sage develop.

This PR is a cherry-pick from my branch in #35095, the three commits indicated #36572 (comment), with any conflicts in cherry picking resolved to "no change".

Got it, thank you. The changes look good to me, too, so I will echo the approval from @dcoudert.

@tobiasdiez
Copy link
Contributor

In the meantime, is the main disagreement about which changes get merged first? The other branches have been rebased on top of this one, so why not proceed with this one?

Of course, I can always open a PR that contains various subsets of changes proposed in other PRs. But there is only value in doing this if there is a problem with the original PRs (otherwise these other PRs could be directly merged). The only problem that has been pointed out so far is that Matthias doesn't want to resolve the merge conflicts in 'all.py' files introduced in these PRs. But someone has to resolve this conflicts at some point, so why not do it now?

@mkoeppe
Copy link
Member Author

mkoeppe commented Nov 15, 2023

Thanks!

@tobiasdiez
Copy link
Contributor

That is only one of the points in #36666 (comment).

@mkoeppe
Copy link
Member Author

mkoeppe commented Nov 16, 2023

That is only one of the points in #36666 (comment).

Would you clarify for us: Do you mean that you are also doubling down on your false claim of authorship (the 2nd point in your list)?

@mkoeppe
Copy link
Member Author

mkoeppe commented Nov 29, 2023

That is only one of the points in #36666 (comment).

Would you clarify for us: Do you mean that you are also doubling down on your false claim of authorship (the 2nd point in your list)?

@tobiasdiez My question does require an answer.

@tobiasdiez
Copy link
Contributor

That is only one of the points in #36666 (comment).

Would you clarify for us: Do you mean that you are also doubling down on your false claim of authorship (the 2nd point in your list)?

@tobiasdiez My question does require an answer.

Sorry, I read that as a rhetoric question. We both know that I didn't authored these commits, and I never claimed I did. Your little rebase experiment should have convinced you that (all?/most of?) your changes here were already contained in my PRs. So I think a bit of attribution does not hurt.

@mkoeppe
Copy link
Member Author

mkoeppe commented Dec 5, 2023

That is only one of the points in #36666 (comment).

Would you clarify for us: Do you mean that you are also doubling down on your false claim of authorship (the 2nd point in your list)?

@tobiasdiez My question does require an answer.

Sorry, I read that as a rhetoric question. We both know that I didn't authored these commits,

Yes, we both do know that.
The problem is that you have tried to mislead the public about it.

and I never claimed I did.

As part of setting the status back to "needs work", you demanded in #36666 (comment):

Add me as coauthor for proper attribution

Using the word "proper" here means that you were accusing me of improperly withholding attribution.

Your little rebase experiment

That's patronizing language, unwelcome here.

should have convinced you that (all?/most of?) your changes here were already contained in my PRs. So I think a bit of attribution does not hurt.

Here again you are writing to mislead the public.

When you opened #36572 on Oct 29, the same day I informed you in #36572 (comment) that I made the changes to the Cython files already in #35095 for the whole Sage library. (On Oct 30, I added the precise commits to this comment for reference.)

On Oct 30, nevertheless you opened #36588 and #36589, which overlap with my changes. (Apparently you were unconcerned about attribution at that time!)

On Nov 3, I informed you in #36588 (comment) and #36589 (comment) that "The only thing that is needed to solve the problem with Cython is to take care of relative cimports, not imports. Doing this in one PR creates lots of gratuitous merge conflicts with #35095." (Note that I did not demand any changes.)

You responded in #36588 (comment): "my main motivation is making it work with pytest. For this the normal imports have to be changed as well." (You seemed unconcerned about my workload of resolving the resulting merge conflicts: "I'm sorry for the merge conflicts, but they should be easy to resolve.")

I opened the present PR, which is cherry-picked carefully from #35095 and does not create merge conflicts. The rest can be read above.

Copy link

github-actions bot commented Dec 6, 2023

Documentation preview for this PR (built with commit b2222c3; changes) is ready! 🎉

@mkoeppe
Copy link
Member Author

mkoeppe commented Dec 6, 2023

Regarding point 4 of #36666 (comment),

Revert your recent force pushes to my PRs

... last week Tobias undid the rebase of the branches of #36572, #36588, #36589, and today his original branches have been merged into develop.

@vbraun vbraun merged commit a45062c into sagemath:develop Dec 10, 2023
15 of 19 checks passed
@mkoeppe mkoeppe added this to the sage-10.3 milestone Dec 10, 2023
@mkoeppe mkoeppe deleted the absolute_cimport_sage_arith branch December 10, 2023 22:28
vbraun pushed a commit to vbraun/sage that referenced this pull request Dec 17, 2023
    
<!-- ^^^^^
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 -->

<!-- Why is this change required? What problem does it solve? -->
This makes the CI conda pass by marking affected files as "known
baseline failures", thus reducing the noise that this workflow makes on
PRs (including
sagemath#36666 (comment))

Less intrusive version of sagemath#36372.

In addition to the failure marked there, here we collect a number of
more failures observed over the course of a week in
https://github.com/sagemath/sage/actions/workflows/ci-
conda.yml?query=is%3Acompleted

<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- 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.
- [ ] The description explains in detail what this PR is about.
- [x] 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: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36678
Reported by: Matthias Köppe
Reviewer(s): Kwankyu Lee, Tobias Diez
@mkoeppe mkoeppe added the disputed PR is waiting for community vote, see https://groups.google.com/g/sage-devel/c/IgBYUJl33SQ label Dec 23, 2023
vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 5, 2024
…e relative by absolute imports

    
<!-- ^^^^^
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 -->
We restructure the `all.py` files for modularization.

Guided by the technical constraints outlined in
https://groups.google.com/g/sage-devel/c/ozh-7ZZ848s, sagemath#35095 defines
distribution packages (pip-installable packages) **sagemath-{brial,
combinat, eclib, flint, gap, giac, glpk, graphs, groups, homfly, lcalc,
libbraiding, libecm, linbox, modules, mpmath, ntl, pari, plot,
polyhedra, schemes, singular, standard-no-symbolics, symbolics}**.

When a namespace package such as `sage.misc` is filled by modules from
several distribution packages, we create modules named:
- `src/sage/misc/all__sagemath_environment.py`
- `src/sage/misc/all__sagemath_objects.py`
- `src/sage/misc/all__sagemath_repl.py`

Import statements are moved from `src/sage/misc/all.py` to these files
as appropriate, and `src/sage/misc/all.py` imports `*` from there.

Also some imports are replaced by lazy imports.

The new files provide the top level namespaces for the modularized
distribution packages, thus [enabling modularized testing](https://doc.s
agemath.org/html/en/developer/packaging_sage_library.html#testing-
distribution-packages).

This design was introduced in sagemath#29865 (merged in Jan 2022, early in the
Sage 9.6 development cycle).

<!-- 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". -->
- Copied from sagemath#35095.
- Part of sagemath#29705

Moreover, applied a one-line command to replace relative by absolute
imports, thus complementing sagemath#36666, which does not touch `.all*` files.

The changes to other files in `sage.modules` etc. come from the PRs
sagemath#36597, sagemath#36572, sagemath#36588, sagemath#36589 merged here and do not need review.

<!-- 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.
- [x] 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#36597 (merged here to resolve merge conflict)
- Depends on sagemath#36572 (merged here to
resolve merge conflict)
- Depends on sagemath#36588 (merged here to
resolve merge conflict)
- Depends on sagemath#36589 (merged here to
resolve merge conflict)
- Depends on sagemath#36449 (merged here to resolve merge conflict)

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36676
Reported by: Matthias Köppe
Reviewer(s): David Coudert, John H. Palmieri, Matthias Köppe, Tobias Diez
vbraun pushed a commit to vbraun/sage that referenced this pull request Mar 30, 2024
    
<!-- ^^^^^
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 -->
Author: @mkoeppe, based on @tobiasdiez's config in sagemath#36503.

Adding a configuration for the ruff linter as proposed in sagemath#36503 is
timely and uncontroversial.

However, sagemath#36503 bundled this gratuitously with the controversial design
of creating a `pyproject.toml` file in SAGE_ROOT.

`pyproject.toml` -- by definition in PEP 518, PEP 621 -- marks a
directory as a Python project, i.e., the source directory of a Python
distribution package
(sagemath#36503 (comment)).
Generalizing the use of `pyproject.toml` to "[non-package
projects](https://peps.python.org/pep-0735/#motivation)" is still
subject to discussion in the Python community in [PEP
735](https://peps.python.org/pep-0735/) (Nov 2023).

**The scope of PRs should be chosen to minimize friction, not to
maximize friction.**
sagemath#36726 (comment)
Here we remove the artificial friction from the gratuitous bundling, by
configuring ruff in `ruff.toml` instead. Configuration in ruff.toml and
pyproject.toml has equal validity / standing per [ruff
documentation](https://docs.astral.sh/ruff/configuration/#config-file-
discovery). And this is the location of most of our other linter
configuration files.

Reference on previous common denominator PRs:
sagemath#36666 (comment),
sagemath#36666 (comment),
sagemath#36572 (comment),
sagemath#36960 (comment),
sagemath#36960 (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". -->
<!-- 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.
- [x] 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: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#37452
Reported by: Matthias Köppe
Reviewer(s): Giacomo Pope, Matthias Köppe
vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 1, 2024
…e relative by absolute imports

    
<!-- ^^^^^
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 -->
We restructure the `all.py` files for modularization.

Guided by the technical constraints outlined in
https://groups.google.com/g/sage-devel/c/ozh-7ZZ848s, sagemath#35095 defines
distribution packages (pip-installable packages) **sagemath-{brial,
combinat, eclib, flint, gap, giac, glpk, graphs, groups, homfly, lcalc,
libbraiding, libecm, linbox, modules, mpmath, ntl, pari, plot,
polyhedra, schemes, singular, standard-no-symbolics, symbolics}**.

When a namespace package such as `sage.misc` is filled by modules from
several distribution packages, we create modules named:
- `src/sage/misc/all__sagemath_environment.py`
- `src/sage/misc/all__sagemath_objects.py`
- `src/sage/misc/all__sagemath_repl.py`

Import statements are moved from `src/sage/misc/all.py` to these files
as appropriate, and `src/sage/misc/all.py` imports `*` from there.

Also some imports are replaced by lazy imports.

The new files provide the top level namespaces for the modularized
distribution packages, thus [enabling modularized testing](https://doc.s
agemath.org/html/en/developer/packaging_sage_library.html#testing-
distribution-packages).

This design was introduced in sagemath#29865 (merged in Jan 2022, early in the
Sage 9.6 development cycle).

<!-- 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". -->
- Copied from sagemath#35095.
- Part of sagemath#29705

Moreover, applied a one-line command to replace relative by absolute
imports, thus complementing sagemath#36666, which does not touch `.all*` files.

The changes to other files in `sage.modules` etc. come from the PRs
sagemath#36597, sagemath#36572, sagemath#36588, sagemath#36589 merged here and do not need review.

<!-- 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.
- [x] 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#36597 (merged here to resolve merge conflict)
- Depends on sagemath#36572 (merged here to
resolve merge conflict)
- Depends on sagemath#36588 (merged here to
resolve merge conflict)
- Depends on sagemath#36589 (merged here to
resolve merge conflict)
- Depends on sagemath#36449 (merged here to resolve merge conflict)

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
    
URL: sagemath#36676
Reported by: Matthias Köppe
Reviewer(s): David Coudert, John H. Palmieri, Kwankyu Lee, Matthias Köppe, Tobias Diez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disputed PR is waiting for community vote, see https://groups.google.com/g/sage-devel/c/IgBYUJl33SQ t: refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants