Skip to content

Conversation

@joergdietrich
Copy link
Contributor

@joergdietrich joergdietrich commented Apr 4, 2017

Strip non-numeric version name extensions like 'dev' or rc1 from version string if LooseVersion() is used for version comparison. This fixes #5814 and adds a first test suite for minversion().

assert isinstancemethod(MyClass, MyClass.an_instancemethod)


def _minversion_test():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't this just be part of test_minversion()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid code repetition when both pkg_resources.parse_version and distutils.version.LooseVersion are tested.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you still plan to add more tests to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. _minversion_test() is called twice already, at least on systems that have pkg_resources. Once inside the if clause to trigger an ImportError if pkg_resources is present to fall back on distutils and once after the if clause to use pkg_resources.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes. I see that now. Thanks for the clarification! 😄

@pllim pllim added the utils label Apr 5, 2017
@pllim
Copy link
Member

pllim commented Apr 5, 2017

This also needs a change log for v2.0 under "API change".

@pllim pllim added this to the v2.0.0 milestone Apr 5, 2017
@joergdietrich
Copy link
Contributor Author

This also needs a change log for v2.0 under "API change".

Done (not an expert on rst, though). Let me know whether this is good and/or the commits need squashing.

CHANGES.rst Outdated

- ``astropy.utils``

- On systems that do not have ``pkg_resources`` non-numerical additions to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not an API change, right? It seems more like a bugfix. Not sure though, I generally struggle with these classifications. 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right. I did tag the original issue as a bug two months ago. So, please move this to v1.3.3 under "Bug Fix". Sorry for the inconvenience.

from distutils.version import LooseVersion as parse_version
# LooseVersion raises a TypeError when strings like dev, rc1 are part
# of the version number. Match the dotted numbers only.
expr = '^([1-9]\\d*!)?(0|[1-9]\\d*)(\\.(0|[1-9]\\d*))*'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems overly complicated, e.g why not have [0-9] instead of 0|[1-9] or \d?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex is lifted straight from PEP440, which defines valid version numbers. I had the same question as you when I read it but decided to go with the "official" version in case I had missed something. My brain's regex parser is notoriously unreliable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the comment, adding a link to where that is defined in PEP440 would be nice.

@pllim pllim modified the milestones: v1.3.3, v2.0.0 Apr 5, 2017
@MSeifert04
Copy link
Contributor

I think it would be a good idea to squash the commits because it's a fairly small change and most commits are 1-2 lines changed.

However let's wait if someone else thinks different before doing so (currently it's easy to see/review what changed in each commit :) ).

@pllim
Copy link
Member

pllim commented Apr 5, 2017

I would recommend a squash and let the CI run one more time.

@joergdietrich
Copy link
Contributor Author

Squashed and all green.

@pllim pllim requested a review from astrofrog April 5, 2017 23:17
@bsipocz bsipocz merged commit 3205324 into astropy:master Apr 20, 2017
@bsipocz
Copy link
Member

bsipocz commented Apr 20, 2017

Thanks again @joergdietrich!

@joergdietrich joergdietrich deleted the #5814 branch April 20, 2017 11:17
bsipocz added a commit that referenced this pull request May 23, 2017
strip non-numeric/non-dot characters from version string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

minversion should return true for a final release if required version is 1.00dev

4 participants