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

avoid string version comparisons in external.qt #2831

Merged
merged 5 commits into from Jan 28, 2013

Conversation

minrk
Copy link
Member

@minrk minrk commented Jan 22, 2013

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.
@takluyver
Copy link
Member

LooseVersion is not necessarily comparable on Python 3 (whereas StrictVersion is). Something like V('1.0.dev') > V('1.0.3') will throw a TypeError. I don't know what kind of pre-release version numbers PySide & PyQt use, though.

@minrk
Copy link
Member Author

minrk commented Jan 22, 2013

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')
@minrk
Copy link
Member Author

minrk commented Jan 25, 2013

I added a NumericalVersion that should always be comparable, regardless of version string and Python version.

@takluyver
Copy link
Member

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 0.13.dev > 0.13.1, but we ourselves use 0.13.dev < 0.13.1 for IPython. That's probably why LooseVersion isn't always comparable - there's no right way to do it.

Looking at their source code, it looks like PySide pre-releases would have a version like 1.1.2~alpha1 - which is comparable, but strictly less than 1.1.2. (ref). PyQt appears to go with snapshot-4.10-f0118624625e (from a development snapshot tarball) - which can't sensibly be compared to anything.

@minrk
Copy link
Member Author

minrk commented Jan 25, 2013

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 ourselves use 0.13.dev < 0.13.1 for IPython

We actually use 0.13dev on both sides of 0.13.0. But the case remains that nobody using X.Y.dev of any version other than today's is valid. It seems to me to always be appropriate to interpret dev as 'latest'.

@takluyver
Copy link
Member

Fair enough. I'd be inclined to compare LooseVersion and catch the error, but I think this should work fine as well.

@minrk
Copy link
Member Author

minrk commented Jan 27, 2013

If we went with LooseVersion, what should we do if the comparison fails?

@takluyver
Copy link
Member

From your description, I think we can just silence the error, so it accepts
any pre-release version that it can't compare.

@minrk
Copy link
Member Author

minrk commented Jan 27, 2013

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.
@minrk
Copy link
Member Author

minrk commented Jan 27, 2013

check_version added instead of NumericalVersion

@takluyver
Copy link
Member

Yep, that looks good to me.

Do we want to leave NumericalVersion and version_tuple around, or just use check_version wherever we want to do this?

@minrk
Copy link
Member Author

minrk commented Jan 27, 2013

I'll remove NumericalVersion

@minrk
Copy link
Member Author

minrk commented Jan 27, 2013

unused code removed, should be ready to merge.

@takluyver
Copy link
Member

Looks good to me, merging now.

takluyver added a commit that referenced this pull request Jan 28, 2013
avoid string version comparisons in external.qt
@takluyver takluyver merged commit 8f74907 into ipython:master Jan 28, 2013
@minrk minrk mentioned this pull request Jan 28, 2013
2 tasks
minrk added a commit that referenced this pull request Mar 10, 2013
We have learned from pyzmq that one should *always* parse version strings
before comparing them.
minrk added a commit that referenced this pull request Mar 12, 2013
We have learned from pyzmq that one should *always* parse version strings
before comparing them.
minrk added a commit that referenced this pull request Mar 20, 2013
We have learned from pyzmq that one should *always* parse version strings
before comparing them.
@minrk minrk deleted the qtversions branch March 31, 2014 23:36
yarikoptic added a commit to yarikoptic/ipython that referenced this pull request May 2, 2014
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
  ...
yarikoptic added a commit to yarikoptic/ipython that referenced this pull request May 2, 2014
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
  ...
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
avoid string version comparisons in external.qt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants