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

Support passing dist-info-dir to bdist_wheel #612

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@
None,
"Python tag (cp32|cp33|cpNN) for abi3 wheel tag" " (default: false)",
),
(
"dist-info-dir=",
None,
"directory where a pre-generated dist-info can be found (e.g. as a "
"result of calling the PEP517 'prepare_metadata_for_build_wheel' "
"method)",
),
]

boolean_options = ["keep-temp", "skip-build", "relative", "universal"]
Expand All @@ -231,6 +238,7 @@
self.format = "zip"
self.keep_temp = False
self.dist_dir = None
self.dist_info_dir = None
self.egginfo_dir = None
self.root_is_pure = None
self.skip_build = None
Expand All @@ -249,8 +257,9 @@
bdist_base = self.get_finalized_command("bdist").bdist_base
self.bdist_dir = os.path.join(bdist_base, "wheel")

egg_info = self.distribution.get_command_obj("egg_info")
egg_info.ensure_finalized() # needed for correct `wheel_dist_name`
if self.dist_info_dir is None:
egg_info = self.distribution.get_command_obj("egg_info")
egg_info.ensure_finalized() # needed for correct `wheel_dist_name`

Check warning on line 262 in src/wheel/bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/bdist_wheel.py#L260-L262

Added lines #L260 - L262 were not covered by tests

self.data_dir = self.wheel_dist_name + ".data"
self.plat_name_supplied = self.plat_name is not None
Expand Down Expand Up @@ -412,12 +421,21 @@
)

self.set_undefined_options("install_egg_info", ("target", "egginfo_dir"))

distinfo_dirname = (
f"{safer_name(self.distribution.get_name())}-"
f"{safer_version(self.distribution.get_version())}.dist-info"
)
distinfo_dir = os.path.join(self.bdist_dir, distinfo_dirname)
self.egg2dist(self.egginfo_dir, distinfo_dir)
if self.dist_info_dir:

Check warning on line 430 in src/wheel/bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/bdist_wheel.py#L430

Added line #L430 was not covered by tests
# Use the given dist-info directly.
shutil.copytree(self.dist_info_dir, distinfo_dir)

Check warning on line 432 in src/wheel/bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/bdist_wheel.py#L432

Added line #L432 was not covered by tests
# Egg info is still generated, so remove it now to avoid it getting
# copied into the wheel.
shutil.rmtree(self.egginfo_dir)

Check warning on line 435 in src/wheel/bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/bdist_wheel.py#L435

Added line #L435 was not covered by tests
else:
# Convert the generated egg-info into dist-info.
self.egg2dist(self.egginfo_dir, distinfo_dir)

Check warning on line 438 in src/wheel/bdist_wheel.py

View check run for this annotation

Codecov / codecov/patch

src/wheel/bdist_wheel.py#L438

Added line #L438 was not covered by tests

self.write_wheelfile(distinfo_dir)

Expand Down
28 changes: 28 additions & 0 deletions tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,34 @@ def license_paths(self):
assert "UTF-8 描述 説明" in metadata


def test_dist_info_provided(dummy_dist, monkeypatch, tmp_path):
monkeypatch.chdir(dummy_dist)
distinfo = tmp_path / "dummy_dist.dist-info"
distinfo.mkdir()
(distinfo / "METADATA").write_text("name: helloworld", encoding="utf-8")

# We don't control the metadata. According to PEP-517, "The hook MAY also
# create other files inside this directory, and a build frontend MUST
# preserve".
(distinfo / "FOO").write_text("bar", encoding="utf-8")
subprocess.check_call(
[
sys.executable,
"setup.py",
"bdist_wheel",
"-b",
str(tmp_path),
"--universal",
"--dist-info-dir",
str(distinfo),
],
)
with WheelFile("dist/dummy_dist-1.0-py2.py3-none-any.whl") as wf:
with wf.open("dummy_dist-1.0.dist-info/METADATA") as fh:
assert fh.read() == b"name: helloworld"
assert "dummy_dist-1.0.dist-info/FOO" in list(wf.namelist())


def test_licenses_default(dummy_dist, monkeypatch, tmp_path):
monkeypatch.chdir(dummy_dist)
subprocess.check_call(
Expand Down