From 3998aedddeb82ad427224ba2b624de97329fbe12 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 29 Aug 2018 10:51:42 -0400 Subject: [PATCH 1/2] don't print release URL in verbose mode if not necessary Fixes #73 --- hashin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/hashin.py b/hashin.py index c2a4a0d..12918f7 100755 --- a/hashin.py +++ b/hashin.py @@ -364,15 +364,17 @@ def get_package_data(package, verbose=False): def get_releases_hashes(releases, algorithm, verbose=False): for found in releases: - url = found['url'] - if verbose: - _verbose('Found URL', url) digests = found['digests'] try: found['hash'] = digests[algorithm] + if verbose: + _verbose('Found hash for', found['url']) except KeyError: # The algorithm is NOT in the 'digests' dict. # We have to download the file and use pip + url = found['url'] + if verbose: + _verbose('Found URL', url) download_dir = tempfile.gettempdir() filename = os.path.join( download_dir, @@ -390,7 +392,6 @@ def get_releases_hashes(releases, algorithm, verbose=False): if verbose: _verbose(' Hash', found['hash']) yield { - 'url': url, 'hash': found['hash'] } From d9d3207e4fc4d00ae1267dc0ac6cfc7e0ae3fad3 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 29 Aug 2018 11:07:16 -0400 Subject: [PATCH 2/2] tests and changelog update --- README.rst | 5 +++++ tests/test_cli.py | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.rst b/README.rst index 91b83ea..4be9060 100644 --- a/README.rst +++ b/README.rst @@ -221,6 +221,11 @@ put it directly into ``pip``. Version History =============== +0.13.x + + * Don't show URLs when using ``--verbose`` if files don't need to be + downloaded. See https://github.com/peterbe/hashin/issues/73 + 0.13.3 * Makes it possible to install ``nltk`` on Windows. `Thanks @chrispbailey! `_ diff --git a/tests/test_cli.py b/tests/test_cli.py index 336eb2e..ad4ecfb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -417,7 +417,7 @@ def mocked_get(url, **options): out_lines[1] ) self.assertTrue( - 'Found URL https://pypi.org/packages' in out_lines[1], + 'Found hash for https://pypi.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl' in out_lines[1], out_lines[1] ) # hash it got @@ -986,15 +986,12 @@ def mocked_get(url, **options): 'version': '0.10', 'hashes': [ { - 'url': 'https://pypi.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl', 'hash': 'aaaaa' }, { - 'url': 'https://pypi.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl', 'hash': 'bbbbb' }, { - 'url': 'https://pypi.org/packages/source/p/hashin/hashin-0.10.tar.gz', 'hash': 'ccccc' } ] @@ -1047,10 +1044,17 @@ def mocked_get(url, **options): murlopen.side_effect = mocked_get - result = hashin.get_package_hashes( - package='hashin', - version='0.10', - algorithm='sha512', + my_stdout = StringIO() + with redirect_stdout(my_stdout): + result = hashin.get_package_hashes( + package='hashin', + version='0.10', + algorithm='sha512', + verbose=True, + ) + out_lines = my_stdout.getvalue().splitlines() + self.assertTrue( + 'Found URL https://pypi.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl' in out_lines[1] ) expected = { @@ -1058,15 +1062,12 @@ def mocked_get(url, **options): 'version': '0.10', 'hashes': [ { - 'url': 'https://pypi.org/packages/3.3/p/hashin/hashin-0.10-py3-none-any.whl', 'hash': '0d63bf4c115154781846ecf573049324f06b021a1d4b92da4fae2bf491da2b83a13096b14d73e73cefad36855f4fa936bac4b2357dabf05a2b1e7329ff1e5455' }, { - 'url': 'https://pypi.org/packages/2.7/p/hashin/hashin-0.10-py2-none-any.whl', 'hash': '45d1c5d2237a3b4f78b4198709fb2ecf1f781c8234ce3d94356f2100a36739433952c6c13b2843952f608949e6baa9f95055a314487cd8fb3f9d76522d8edb50' }, { - 'url': 'https://pypi.org/packages/source/p/hashin/hashin-0.10.tar.gz', 'hash': 'c32e6d9fb09dc36ab9222c4606a1f43a2dcc183a8c64bdd9199421ef779072c174fa044b155babb12860cf000e36bc4d358694fa22420c997b1dd75b623d4daa' } ]