-
-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Improve version comparison for non released versions #7980
Comments
This is the deprecated version comparison which does not support PEP0440 (for example the regex does not support beta it seems). The new one is there: |
@lesteve that is the same link... |
Oops copy and paste gone wrong https://github.com/pypa/packaging/blob/master/packaging/version.py#L159. |
I want to work on the issue. Could you please help me get started on it? |
The idea is to take the code we need from https://github.com/pypa/packaging/blob/master/packaging/version.py (and possibly simplify it, we can probably get rid of legacy versions and classes that implement |
@lesteve, is this issue still relevant? Also, is the related PR a reusable solution for someone willing to help on this? Thanks for your help! |
I think it is still somewhat relevant but the cost/benefit ratio seems to be in favour of a "won't fix":
The simplest thing to do for the PR writer seems to make scikit-learn depend on setuptools and use The #8301 PR went the consensual way (at the time) to copy the necessary code from setuptools into |
yes, it is. Just run into it today. And after digging through CPython issues https://bugs.python.org/issue14894 it doesn't look like distutils.version.LooseVersion is ever going to be fixed, so we shouldn't use it.
Yeah, setuptools is already a build dependency. I'm also undecided between making it a runtime dependency or vendoring the part from pkg_utils/packaging under Went with the first solution in scikit-learn-contrib/scikit-learn-extra#42 but has a much smaller user base, so an extra dependency doesn't matter. Actually what we could do is to make add a wrapper that would use |
I did not think of this and this sounds a very reasonable approach indeed! So something like this somewhere in sklearn/utils could be a start: try:
from pkg_resources import parse_version
except ImportError:
parse_version = LooseVersion After that you would need to replace all the LooseVersion and other ways we compare versions in scikit-learn (see my old comment #8301 (comment) which may still be relevant). A bit tedious, but maybe this is a reasonable one for the sprint after all! |
Yes, I think we could just adapt #8301 I imagine most of the replacements there are still relevant. |
I have tried to create a new conda env with I have also tried to install a Same in So I am pretty sure that at least 99% of our our users will have the |
I want to tackle this issue. The approach is to add code like the following (mentioned by @lesteve): try:
from pkg_resources import parse_version
except ImportError:
parse_version = LooseVersion and fix lines using version comparison function. Is it good? |
@hs-nazuna yes! |
@hs-nazuna The idea is to define a |
@rth Thank you for your comment. I will do so. |
@hs-nazuna hard to tell which strategy is the best without actually doing it, but if I were you, I would create a PR from scratch since #8301 has a lot of conflicts and it may be a bit painful to fix all of them. If you feel more optimistic than me, the alternative is to try to rebase #8301 on master and try to fix conflicts for 15 (maybe 30) minutes. If you don't succeed in this much time, start a PR from scratch. |
I would say more like 10. It's much better to merge upstream/master in to sync, rather than rebase as that leads to fewer conflicts that needs to be resolved. With rebase one would need to fix conflicts for each commit in that PR.. |
I think so too. And now I am trying to create a new PR. |
Moved from #7902.
Our code comparing versions (for example in
sklearn.utils.fixes
which implement backports of older numpy, scipy, etc... functionalities) doesn't deal very well with non-released versions:sklearn.utils.fixes._parse_version
parses a version string into a tuple and comparing the tuple afterwards. This will either give the wrong answer or raise an exception:
distutils.version.LooseVersion
doesn't deal correctly with beta version either:
pkg_resources.parse_version
does deal with beta versions:
Making scikit-learn depend on setuptools is controversial so porting a reasonable implementation in sklearn.utils was deemed the best option in #7902 (comment).
The text was updated successfully, but these errors were encountered: