BLD, MAINT: hoist packaging import#3527
Conversation
* hoist the import of `packaging` outside of a Cython-focused `try`/`except` block to avoid a deceptive error message when `packaging` is missing, per discussion at: MDAnalysis#3398 (comment) * we may also want to consider removing the external dependency completely and vendoring the pertinent code since it is so small, but maybe not this close to a release; an example: https://github.com/scipy/scipy/blob/main/scipy/_lib/_pep440.py
Codecov Report
@@ Coverage Diff @@
## develop #3527 +/- ##
========================================
Coverage 94.10% 94.10%
========================================
Files 189 189
Lines 24596 24596
Branches 3305 3305
========================================
Hits 23146 23146
Misses 1404 1404
Partials 46 46 Continue to review full report at Codecov.
|
| import Cython | ||
| from Cython.Build import cythonize | ||
| cython_found = True | ||
| from packaging.version import Version |
There was a problem hiding this comment.
So thinking about it a bit more, this explicitly makes packaging a core requirement for user builds right?
I guess the question is - where do we stand on eventually making Cython a core dependency (rather than us shipping the C/C++ files)? If we want to keep things the way we usually do, then I think we should possibly try/except around the packaging import and just set it to either say that either cython or packaging isn't found?
There was a problem hiding this comment.
So thinking about it a bit more, this explicitly makes packaging a core requirement for user builds right?
What? I just moved the import so the error message would be better when packaging is absent--it was the MDA team who added this dependency months ago.
|
@MDAnalysis/coredevs please review - this will technically add a dependency. I don't personally think |
|
When is |
So my understanding is that if you pip install it'll pull it in as a build dependency (based on the project.toml), otherwise on a python setup.py call you'll need to have it installed (i.e. it'll need to be under I'm not sure which, but one of our core dependencies already pulls it in so we had added it in without ever really caring too much until now. |
|
Poking around a little bit, seems like we've already bought into using For example: I think we should just move ahead with putting |
|
If we imply it anyway, we should have it explicit. |
Huh? MDAnalysis added the |
@tylerjereddy - yeah you're right, but the problem we face is that Sorry about the confusing/confused messages, essentially my final point is that we probably should reflect this dependency in |
Honestly, it looks like the team accidentally added a runtime dependency and not just a build time dependency, which is a bit more serious, even for the average consumer of a pre-built binary for example. Given the increased gravity of a runtime dependency addition, and one that wasn't really discussed with the team IIUC, I'd probably vote for vendoring the module I mention above, which may also have the added benefit of avoiding chicken-and-egg problems with needing an external package to make (versioning) decisions about other external packages in the setup code. I'm not sure that any of the possible decisions really make a difference to this PR though--regardless of where the machinery comes from, and what else you tell It looks like there may have been an intention to make So, it still seems to me like this is one of the cases where vendoring a small chunk of external code may actually be the right choice to avoid some head-spinning dependency issues, and then a top-level import should always be safe anyway. |
|
One other point is that I'm not sure why we have such a low minimum version of Cython in Plus I've already set |
Yeah I think this is on me as the approver of that PR (I forgot Here's what I propose we do: 1 - In this PR add I realise this is an issue that happened before this PR, but if we can fix it now we can just push out 2.1.0. Does that sound sensible @tylerjereddy ? |
We need to get this moving so I'll merge this and follow up with a PR that explicitly adds packaging as a dependency. |
hoist the import of
packagingoutside of a Cython-focusedtry/exceptblock to avoid a deceptive error message whenpackagingis missing, per discussion at:BLD: comply with PEP518 #3398 (comment)
we may also want to consider removing the external dependency
completely and vendoring the pertinent code since it is so small, but
maybe not this close to a release; an example:
https://github.com/scipy/scipy/blob/main/scipy/_lib/_pep440.py
PR Checklist