-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
WIP: Use .pth file to import distutils from setuptools #2260
Conversation
ddc542e
to
f79d6af
Compare
6ff3a30
to
2feb180
Compare
I've updated this to use the module import-time hook described in this comment. Theoretically we could replace the I could easily imagine a situation where a redistributor decides to forego the |
2feb180
to
85a0a90
Compare
I've restored the warnings now, since in the new Also I'm not sure how best to test this stuff. Any ideas @jaraco? Given that you brought up the |
I've mainly tested it by ensuring that
I believe you can simply build a wheel and then set I've also observed that the I'd forgotten that Hmm. I do notice that That still won't address the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, I'm inclined to move forward with this approach and just not support the early importer hack with setuptools
installed as an editable install.
In e371422, I've pushed my suggestions, and I've confirmed the behavior works as intended:
Interestingly, when using pip-run to test, I encounter an error:
That's fixed in 2986be4.
|
Ok, I'll take a look in the morning. I think it's fine to basically fall back to the "you must import setuptools first" behavior if the end user can remedy this themselves by installing setuptools a different way. The main thing I'm concerned about is if there is a reasonable / supported workflow where end users will start seeing breakages due to import order in packages they don't control and can't easily fix. I think that with PEP 517/518 and the fact that you can always fix this by installing setuotools in a normal way, we're probably fine. Not sure how well tested any of this is, though... |
@jaraco Looks like the changes you made make it so that you either get the |
@jaraco OK, so I like the idea of moving the
What do you think? |
That wasn't my intention. I would have expected this line to cause the hack to be invoked unconditionally. And I confirm it works as intended:
Can you share where the behavior misses your expectation?
That's fair. I'll do that.
My main reason for doing this with I don't know any way to do that without also implicitly enacting that behavior when triggered from the
I do think it makes sense to consolidate all of the behavior into I'll work on another draft, but if you have ideas on how to eliminate |
Sorry, I did figure out that it worked as intended after I left that comment, then I guess I forgot that I had actually hit "send".
Can we do a multiline disable? With We could also presumably switch to At the end of the day, I don't like the idea of contorting our code just to satisfy linters, I find linters useful until they get in my way, at which point I ruthlessly disable them. I think there are probably real benefits to keeping this hack in a single file, and only minor benefits to keeping the linter rule in place on that file. |
Yes. I'm not opposed to any number of lines that appear in one contiguous block, so a block-based enable/disable would be fine. What I really want to avoid is more touch points at different points in the code.
It may have been me. I use
I'd be okay with disabling it for the file, but I'm pretty sure that can't happen without a discontinuous line or a line in another file, adding another touch point (and cross-file dependency). I does not appear as if flake8 has per-file ignores that can be declared inline.
Switching to pylint would require a divergence from the practices I follow in other projects or would require transitioning those projects to pylint. Either of those approaches greatly expands the scope of this effort and creates a dependency I'd like to avoid. I'd be willing to consider such a transition separately, and if it can be accepted, utilize it to remove the extraneous import. In df0adbd, I've reduced the
In my experience, having linters is of minimal value for individual projects, but serves its main value in settling what would otherwise be bikeshedding over subjective preferences. Linters have cost me much more time than they've ever saved, but at least they allow me to offload those decisions. I do my best to honor the preferences of the linters, even when they violate my sensibilities. At this point, the hack 99% in a single file with only one small shim for override. I think that's good enough to proceed and we can iterate more if appropriate. |
df0adbd
to
6c6d69e
Compare
Yeah, that's a fair compromise. I'll start another issue for the One last thing, possibly bikeshedding, but should we rename this from Happy to do those changes myself if you want. |
Also this seems like a lot of commits, we should probably rewrite the history a bit. If you don't want to, I'm happy to merge all the related changes into 2-3 commits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM. Make whatever edits you wish to the docstring, module name, and commit history, add a changelog entry, and let's get this merged. Thanks!
Hm, I found a major problem here. Apparently we've been testing Since editable installs don't install the I think before we merge this we should refactor the tests to make it possible to test when not using an editable installation, and ensuring that we test as installed. |
To clarify, I think we should probably do that in a separate PR, since this one is already a bit complicated and I've got a half-refactored history sitting around semi-blocked on this. |
I did one-off test the behavior using pip-run in #2260 (comment) and repeated that test with the latest code. In my opinion, that's sufficient, though I wouldn't object to there being a test for the installed package. |
This puts non-distutils imports first and removes one unused import.
I don't think that is sufficient. Redistributors also need to be able to run the tests, and we need to be confident in our ability to accept PRs from contributors who are going to make changes to this code. We also need confidence that it works on all supported platforms. Relying on one-off testing will dramatically slow our velocity on probably one of the most trickiest features we've released in a long time. It's unfortunate that our tech debt is coming due when we'd like to get these changes out, but when you're in a hole it's probably best to stop digging. |
…e. Generate distutils-precedence.pth inline.
…enabled' logic is duplicated in pth file).
6c6d69e
to
a5ddcd4
Compare
I started writing tests for this functionality, but when I did, I began running into bugs in pytest-virtualenv and ran out of steam before I found a solution. More importantly, the behavior that's most essential is that setuptools runs as intended in a system site-packages environment, functionality that's never been part of the test suite. I'm open to more tests, but I'm not excited about the prospect, given that once this functionality is working as intended and the bugs have been worked through, I don't expect this code to change much and expect it to be deprecated as soon as possible. In other words, it's not inherent to the design, but an artifact of a transition effort. That's why I'm okay with releasing it as best-effort and incidentally tested. That said, I'd welcome tests for it - I'm just not sure it's worth the investment or the delay in making the functionality available. By the way, what is the status of the rewrite? It looks like tests are failing everywhere. Do you have plans to investigate the emergent issues? |
Yes, that's the "technical debt" that I was referring to. We should have never been testing it in any other way, and now we have a major, high-importance and high-profile feature that was rolled out without tests which breaks many things and where it's very difficult to iterate on solutions because we can't even run the test suite in a way where the change takes effect. The problem here is not that I'm requesting an unreasonable standard, the problem is that we never had this standard in the first place, and that we rolled out the
The biggest issues here are that we need tests to be able to make changes with confidence. The issue with
Again, I strongly disagree. To be honest, I think almost all consumers of this project don't care whether or not they use the
I think this is blocked on us getting the test suite working, which I don't have much time for right now. If the current situation is untenable my opinion is that we should roll back the distutils adoption and try to fix it when we have our ducks in a row. |
I can't help but feel that if we back out the distutils patch, we're allowing perfect to be the enemy of good. There are these mitigating factors I see:
I agree this decision isn't easy, but I just can't see backing out the change or leaving it degraded. We've already backed out the change to be opt-in and validated that the opt-in behavior is working as intended. If we don't have the resources to produce the desired outcome, we should eek by with what we can achieve. I'm all for rigor, and we can ratchet up the rigor in subsequent changes (presumably before attempting major refactoring). There are lots of steps ahead of us, including at least reconciling the monkey patches, identifying and presenting a minimal distutils interface, supplanting and removing the stdlib implementation, and eventually deprecating the distutils interface altogether. To that end and with some regret, I'll proceed with the draft where the tests were passing (plus the meta_path patch cherry-picked). I've pushed that to the distutils-import-hack branch and will submit that as a different PR. I realize it doesn't represent a clean history of how we wish we'd approached it, but it does appear to achieve the goal and address the issue. |
I strongly disagree with this decision. Until this project is actually well-tested I don't think we can consider rolling out a change of this magnitude. I appreciate the desire to make forward progress but moving distutils from a project with excellent testing infrastructure (CPython) to a completely untested project is a major regression. Particularly when we are already getting a reputation for churn. Switching to the old pre-rebase version is even worse, because the history isn't even clean. Very unfortunate. I will probably personally recommend to everyone that they pin setuptools to a pre-distutuls-adoption version indefinitely at this point. |
Summary of changes
This is a WIP proof of concept for #2259.
It looks to be a bit tricky to pull it off — at the moment, this breaks everything because the circular import can't resolve
distutils.core
. The two broad-strokes options I see for resolving this:distutils
withinsetuptools
to point to._distutils
.setuptools._distutils
into_distutils_importer/distutils-shim-package
.There may be other options, though.
Pull Request Checklist