Skip to content

Commit

Permalink
handle versions with leading zeros, fixes #39 (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Bengtsson authored Jul 10, 2017
1 parent 150daa0 commit 469e16c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ put it directly into ``pip``.
Version History
===============

0.11.0
* Cope with leading zeros in version numbers when figuring out what
the latest version is.
See https://github.com/peterbe/hashin/issues/39

0.10.0
* Latest version is now figured out by looking at all version numbers
in the list of releases from the JSON payload. The pre releases are
Expand Down
4 changes: 2 additions & 2 deletions hashin.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ def get_latest_version(data):
for version in data['releases']:
v = parse(version)
if not v.is_prerelease:
all_versions.append(v)
all_versions.append((v, version))
all_versions.sort(reverse=True)
# return the highest non-pre-release version
return str(all_versions[0])
return str(all_versions[0][1])


def expand_python_version(version):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name='hashin',
version='0.10.0',
version='0.11.0',
description='Edits your requirements.txt by hashing them in',
long_description=open(path.join(_here, 'README.rst')).read(),
author='Peter Bengtsson',
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ def test_get_latest_version_non_pre_release(self, murlopen):
})
self.assertEqual(version, '0.999')

@mock.patch('hashin.urlopen')
def test_get_latest_version_non_pre_release_leading_zeros(self, murlopen):
version = hashin.get_latest_version({
'info': {
'version': '0.3',
},
'releases': {
'0.04.13': {},
'0.04.21': {},
'0.04.09': {},
}
})
self.assertEqual(version, '0.04.21')

@mock.patch('hashin.urlopen')
def test_get_hashes_error(self, murlopen):

Expand Down

0 comments on commit 469e16c

Please # to comment.