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

Dont print release url in verbose mode if not necessary #74

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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! <https://github.com/peterbe/hashin/pull/72>`_
Expand Down
9 changes: 5 additions & 4 deletions hashin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -390,7 +392,6 @@ def get_releases_hashes(releases, algorithm, verbose=False):
if verbose:
_verbose(' Hash', found['hash'])
yield {
'url': url,
'hash': found['hash']
}

Expand Down
23 changes: 12 additions & 11 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
}
]
Expand Down Expand Up @@ -1047,26 +1044,30 @@ 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 = {
'package': 'hashin',
'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'
}
]
Expand Down