Skip to content

Use Version object for version comparison#12138

Merged
scheibelp merged 1 commit intospack:developfrom
adamjstewart:packages/ver-python3
Jul 29, 2019
Merged

Use Version object for version comparison#12138
scheibelp merged 1 commit intospack:developfrom
adamjstewart:packages/ver-python3

Conversation

@adamjstewart
Copy link
Copy Markdown
Member

Previously, we were doing string to int comparison like (1, 3) > ('1', '2'). This is incredibly buggy:

$ python2
>>> '10' > 9
True
>>> 10 > '9'
False
>>> '9' < 10
False
>>> 9 < '10'
True

Also, this does not work at all in Python 3. You get the following error message when trying to install qt@4 platform=darwin:

==> Error: TypeError: '>=' not supported between instances of 'str' and 'int'

This PR makes use of the Version class for version comparison.


depends_on('py-appnope', type=('build', 'run'),
when=sys.platform == 'darwin' and
int(platform.mac_ver()[0].split('.')[1]) >= 9)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think this works, right? You can't use a when= that evaluates to True or False, it has to be a string, right?

Copy link
Copy Markdown
Member

@scheibelp scheibelp Jul 29, 2019

Choose a reason for hiding this comment

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

Yes - it must be a string (or spec) (see below)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CORRECTION: I'm wrong, it can be a boolean. We have unit tests for this.

if not ((platform.system() == "Darwin") and
(platform.mac_ver()[0] == '10.12')):
(Version(platform.mac_ver()[0]).up_to(2) == Version(
'10.12'))):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

platform.mac_ver() usually returns a 3-digit string, which will never be equal to 10.12

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

platform.mac_ver returns ('10.14.5', ('', '', ''), 'x86_64') for me, so I assume you mean a 3-part version (vs. a 3-digit version). The logic here makes sense in that case.

@alalazo alalazo requested review from healther and lee218llnl July 26, 2019 07:28
@scheibelp scheibelp merged commit 9af155f into spack:develop Jul 29, 2019
@adamjstewart adamjstewart deleted the packages/ver-python3 branch July 29, 2019 22:09
@scheibelp scheibelp mentioned this pull request Jul 30, 2019
5 tasks
dev-zero pushed a commit to dev-zero/spack that referenced this pull request Aug 13, 2019
* Fix Mac platform check for dependency in py-ipython package: 'when'
  constraints in Spack directives must be Specs (either a Spec
  object or a Spec in string format)
* Fix Mac version check in py-numpy: platform.mac_ver() returns a
  3-part string as its first tuple item so the check as written would
  never pass; use Spack Version object to simplify check.
* Fix Mac version check in qt package (the check was incorrectly
  comparing ints and strings) and use Spack version object to
  simplify check.
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.

3 participants