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
avoid string version comparisons in external.qt #2831
Conversation
We have learned from pyzmq that one should *always* parse version strings before comparing them.
|
so I guess we have to write our own version comparison? I hate Python 3's strict comparison rules so much. Something like: import re
component_re = re.compile(r'(\d+ | [a-z]+ )', re.VERBOSE)
def V(vstr):
vlist = component_re.findall(vstr)
for i in range(len(vlist)):
try:
vlist[i] = int(vlist[i])
except ValueError:
vlist[i] = float('inf')
return tuple(vlist) which would always give a tuple of numbers, interpreting any text ('dev', etc) as infinite (2.1dev will always evaluate as greater than 2.1.x). |
all version strings are comparable by casting string elements to float('inf')
I added a NumericalVersion that should always be comparable, regardless of version string and Python version. |
There isn't really a consistent way to compare pre-release versions without knowing about the project's practices. e.g. your implementation implies that Looking at their source code, it looks like PySide pre-releases would have a version like |
I don't actually care that dev versions get compared correctly, as long as they don't raise an error or get interpreted as too old. Anyone running a dev version other than current latest of any given package should not be considered a supported use case. In this way, a snapshot will always pass the minimum version check, and rightly so.
We actually use |
Fair enough. I'd be inclined to compare |
If we went with LooseVersion, what should we do if the comparison fails? |
From your description, I think we can just silence the error, so it accepts |
like this? def check_version(v, check):
"""check version string v ≥ check
if dev tags result in TypeError for string-number comparison,
it is assumed that the dependency is satisfied.
Users on dev branches are responsible for keeping their own packages up to date.
"""
try:
return LooseVersion(v) >= LooseVersion(check)
except TypeError:
return True |
using LooseVersion and explicitly catching TypeError, rather than the NumericalVersion subclass.
check_version added instead of NumericalVersion |
Yep, that looks good to me. Do we want to leave |
I'll remove NumericalVersion |
unused code removed, should be ready to merge. |
Looks good to me, merging now. |
avoid string version comparisons in external.qt
We have learned from pyzmq that one should *always* parse version strings before comparing them.
We have learned from pyzmq that one should *always* parse version strings before comparing them.
We have learned from pyzmq that one should *always* parse version strings before comparing them.
release 0.13.2 * tag 'rel-0.13.2': (65 commits) release 0.13.2 add release date fix dot syntax error in inheritance diagram only upload sdists (backported from master) 0.13.2 rc2 update whatsnew Backport PR ipython#3118: don't give up on weird os names Backport PR ipython#3117: propagate automagic change to shell Backport PR ipython#3097: PyQt 4.10: use self._document = self.document() note latest backports Backport PR ipython#2224: fix css typo avoid references to fiel out of directory reimport HTML in different section add width:100% to vbox for webkit / FF consistency (0.13.2) 0.13.2.rc1 generate whatsnew for 0.13.2 Backport PR ipython#3008: fix cython module so extension for multiarched python Backport PR ipython#3013: py3 workaround for reload in cythonmagic Backport PR ipython#2831: avoid string version comparisons in external.qt Backport PR ipython#2994: expanduser on %%file targets ...
release 0.13.2 * tag 'rel-0.13.2': (65 commits) release 0.13.2 add release date fix dot syntax error in inheritance diagram only upload sdists (backported from master) 0.13.2 rc2 update whatsnew Backport PR ipython#3118: don't give up on weird os names Backport PR ipython#3117: propagate automagic change to shell Backport PR ipython#3097: PyQt 4.10: use self._document = self.document() note latest backports Backport PR ipython#2224: fix css typo avoid references to fiel out of directory reimport HTML in different section add width:100% to vbox for webkit / FF consistency (0.13.2) 0.13.2.rc1 generate whatsnew for 0.13.2 Backport PR ipython#3008: fix cython module so extension for multiarched python Backport PR ipython#3013: py3 workaround for reload in cythonmagic Backport PR ipython#2831: avoid string version comparisons in external.qt Backport PR ipython#2994: expanduser on %%file targets ...
avoid string version comparisons in external.qt
We have learned from pyzmq that one should always parse version strings
before comparing them.