mirror of https://github.com/pypa/pip
Provide a reasonable error on invalid scheme keys
Originally we would throw an `AttributeError` if a bad scheme key was used. After refactoring we would throw a `KeyError`, which isn't much better. Now we call out the wheel being processed, scheme key we didn't recognize, and provide a list of the valid scheme keys. This would likely be useful for people developing/testing the wheel.
This commit is contained in:
parent
864f0e0efa
commit
3f9b326c11
|
@ -592,7 +592,19 @@ def _install_wheel(
|
||||||
).format(wheel_path, record_path)
|
).format(wheel_path, record_path)
|
||||||
raise InstallationError(message)
|
raise InstallationError(message)
|
||||||
|
|
||||||
scheme_path = scheme_paths[scheme_key]
|
try:
|
||||||
|
scheme_path = scheme_paths[scheme_key]
|
||||||
|
except KeyError:
|
||||||
|
valid_scheme_keys = ", ".join(sorted(scheme_paths))
|
||||||
|
message = (
|
||||||
|
"Unknown scheme key used in {}: {} (for file {!r}). .data"
|
||||||
|
" directory contents should be in subdirectories named"
|
||||||
|
" with a valid scheme key ({})"
|
||||||
|
).format(
|
||||||
|
wheel_path, scheme_key, record_path, valid_scheme_keys
|
||||||
|
)
|
||||||
|
raise InstallationError(message)
|
||||||
|
|
||||||
dest_path = os.path.join(scheme_path, dest_subpath)
|
dest_path = os.path.join(scheme_path, dest_subpath)
|
||||||
assert_no_path_traversal(scheme_path, dest_path)
|
assert_no_path_traversal(scheme_path, dest_path)
|
||||||
return ZipBackedFile(record_path, dest_path, zip_file)
|
return ZipBackedFile(record_path, dest_path, zip_file)
|
||||||
|
|
|
@ -699,3 +699,18 @@ def test_wheel_with_file_in_data_dir_has_reasonable_error(
|
||||||
"install", "--no-index", str(wheel_path), expect_error=True
|
"install", "--no-index", str(wheel_path), expect_error=True
|
||||||
)
|
)
|
||||||
assert "simple-0.1.0.data/{}".format(name) in result.stderr
|
assert "simple-0.1.0.data/{}".format(name) in result.stderr
|
||||||
|
|
||||||
|
|
||||||
|
def test_wheel_with_unknown_subdir_in_data_dir_has_reasonable_error(
|
||||||
|
script, tmpdir
|
||||||
|
):
|
||||||
|
wheel_path = make_wheel(
|
||||||
|
"simple",
|
||||||
|
"0.1.0",
|
||||||
|
extra_data_files={"unknown/hello.txt": "hello world"}
|
||||||
|
).save_to_dir(tmpdir)
|
||||||
|
|
||||||
|
result = script.pip(
|
||||||
|
"install", "--no-index", str(wheel_path), expect_error=True
|
||||||
|
)
|
||||||
|
assert "simple-0.1.0.data/unknown/hello.txt" in result.stderr
|
||||||
|
|
Loading…
Reference in New Issue