Skip to content
Open
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
4 changes: 4 additions & 0 deletions aws_lambda_builders/workflows/python_pip/packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,10 @@ def name(self):
@property
def data_dir(self):
# The directory format is {distribution}-{version}.data
if self.dist_type == "wheel":
# Use the escaped name from the wheel filename (PEP 427), e.g. foo_bar,
# not the PEP 503 normalized name (foo-bar) the wheel never uses.
return "%s-%s.data" % tuple(self.filename.split("-")[:2])
return "%s-%s.data" % (self._name, self._version)

def _normalize_name(self, name):
Expand Down
22 changes: 22 additions & 0 deletions tests/functional/workflows/python_pip/test_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,28 @@ def test_can_expand_platlib_and_purelib(self, tmpdir, pip_runner, osutils):
for req in reqs:
assert req in installed_packages

def test_can_expand_purelib_whl_with_underscore_in_name(self, tmpdir, pip_runner, osutils):
# The .data directory is named after the escaped distribution name in
# the wheel filename (foo_bar), not the PEP 503 normalized name (foo-bar).
reqs = ["foo_bar"]
pip, runner = pip_runner
appdir, builder = self._make_appdir_and_dependency_builder(reqs, tmpdir, runner)
requirements_file = os.path.join(appdir, "requirements.txt")
pip.packages_to_download(
expected_args=["-r", requirements_file, "--dest", mock.ANY, "--exists-action", "i"],
packages=["foo_bar-1.2-cp39-cp39-manylinux1_x86_64.whl"],
whl_contents=["foo_bar-1.2.data/purelib/foo_bar/"],
)

site_packages = os.path.join(appdir, ".chalice.", "site-packages")
with osutils.tempdir() as scratch_dir:
builder.build_site_packages(requirements_file, site_packages, scratch_dir)
installed_packages = os.listdir(site_packages)

pip.validate()
for req in reqs:
assert req in installed_packages

def test_does_ignore_data(self, tmpdir, pip_runner, osutils):
# Make sure the wheel installer does not copy the data directory
# up to the root.
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/workflows/python_pip/test_packager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,8 @@ def test_package_invalid_sdist_extension(self):

def test_package_data_dir_property(self):
pkg = Package("", "test_package-1.2.3-py3-none-any.whl", sys.executable)
# The data_dir uses the normalized name and version
assert pkg.data_dir == "test-package-1.2.3.data"
# The data_dir uses the escaped name from the wheel filename, not the normalized name
assert pkg.data_dir == "test_package-1.2.3.data"


class TestSubprocessPipEdgeCases(object):
Expand Down