Skip to content

Commit

Permalink
🐛 Fix wheel fname detection for older pip versions (#39)
Browse files Browse the repository at this point in the history
* 🔊 Add error logging when wheel is not found in whldir

* 🐛 Find wheel filenames based on package key

* ♻️ One less call to canonicalize_name
  • Loading branch information
ddelange committed Aug 7, 2020
1 parent abe78b2 commit 84a766d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/pipgrip/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def customsort(cls, tup):
order = ["name", "extras_name", "version", "pip_string"]
k, v = tup
if k in order:
return order.index(k)
return (str(order.index(k)), 0)
return tup

def export(self, node):
Expand Down
14 changes: 13 additions & 1 deletion src/pipgrip/pipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,23 @@ def _download_wheel(package, index_url, extra_index_url, pre, cache_dir):
if package.startswith("."):
fname = all_wheels[0]
else:
pkg = canonicalize_name(package)
fname = None
pkg = parse_req(package).key
for whl in all_wheels:
if pkg in canonicalize_name(whl):
fname = whl
break
if not fname:
logger.error(
"Failed to extract wheel filename from pip stdout: \n{}".format(
"\n".join(out[::-1])
)
)
raise RuntimeError(
"Failed to find wheel for {} in {}. Wheels found: {}".format(
package, whldir, all_wheels
)
)
else:
fname = fnames[0]
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ def default_environment():
],
),
(
["--tree", "--json", "--max-depth=1", "keras==2.2.2"],
["--tree", "--json", "keras==2.2.2"],
[
'[{"name": "keras", "extras_name": "keras", "version": "2.2.2", "pip_string": "keras==2.2.2"}]',
'[{"name": "keras", "extras_name": "keras", "version": "2.2.2", "pip_string": "keras==2.2.2", "dependencies": [{"name": "h5py", "extras_name": "h5py", "version": "2.10.0", "pip_string": "h5py", "dependencies": [{"name": "numpy", "extras_name": "numpy", "version": "1.16.6", "pip_string": "numpy>=1.7"}, {"name": "six", "extras_name": "six", "version": "1.13.0", "pip_string": "six"}]}, {"name": "keras-applications", "extras_name": "keras-applications", "version": "1.0.4", "pip_string": "keras-applications==1.0.4", "dependencies": [{"name": "h5py", "extras_name": "h5py", "version": "2.10.0", "pip_string": "h5py", "dependencies": [{"name": "numpy", "extras_name": "numpy", "version": "1.16.6", "pip_string": "numpy>=1.7"}, {"name": "six", "extras_name": "six", "version": "1.13.0", "pip_string": "six"}]}, {"name": "keras", "extras_name": "keras", "version": "2.2.2", "pip_string": "keras>=2.1.6", "cyclic": true}, {"name": "numpy", "extras_name": "numpy", "version": "1.16.6", "pip_string": "numpy>=1.9.1"}]}, {"name": "keras-preprocessing", "extras_name": "keras-preprocessing", "version": "1.0.2", "pip_string": "keras-preprocessing==1.0.2", "dependencies": [{"name": "keras", "extras_name": "keras", "version": "2.2.2", "pip_string": "keras>=2.1.6", "cyclic": true}, {"name": "numpy", "extras_name": "numpy", "version": "1.16.6", "pip_string": "numpy>=1.9.1"}, {"name": "scipy", "extras_name": "scipy", "version": "1.2.2", "pip_string": "scipy>=0.14", "dependencies": [{"name": "numpy", "extras_name": "numpy", "version": "1.16.6", "pip_string": "numpy>=1.8.2"}]}, {"name": "six", "extras_name": "six", "version": "1.13.0", "pip_string": "six>=1.9.0"}]}, {"name": "numpy", "extras_name": "numpy", "version": "1.16.6", "pip_string": "numpy>=1.9.1"}, {"name": "pyyaml", "extras_name": "pyyaml", "version": "5.3", "pip_string": "pyyaml"}, {"name": "scipy", "extras_name": "scipy", "version": "1.2.2", "pip_string": "scipy>=0.14", "dependencies": [{"name": "numpy", "extras_name": "numpy", "version": "1.16.6", "pip_string": "numpy>=1.8.2"}]}, {"name": "six", "extras_name": "six", "version": "1.13.0", "pip_string": "six>=1.9.0"}]}]',
],
),
(
Expand Down Expand Up @@ -245,7 +245,7 @@ def default_environment():
"--tree-ascii (cyclic)",
"--tree --json --sort (cyclic)",
"--tree --json --sort --max-depth=1 (cyclic)",
"--tree --json --max-depth=1 (cyclic)",
"--tree --json (cyclic)",
"--tree-json (cyclic)",
"--tree-json-exact (cyclic)",
"keras_preprocessing (underscore)",
Expand Down

0 comments on commit 84a766d

Please sign in to comment.