Skip to content

Commit

Permalink
pyproject: only pass metadata_directory when it's not empty
Browse files Browse the repository at this point in the history
Passing empty `metadata_directory` to `build_wheel` or `build_editable` can
cause some PEP 517 backends to create a wheel without metadata.

Fix #2880
  • Loading branch information
masenf committed Jan 18, 2023
1 parent d9091ea commit 935e7eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions docs/changelog/2880.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
When building a ``wheel`` or ``editable`` package with a PEP 517 backend, no
longer pass an empty ``metadata_directory`` to the backend ``build_wheel`` or
``build_editable`` endpoint.

Some backends, such as PDM and poetry, will not generate package metadata in
the presence of a ``metadata_directory``, even if it is empty.

Prior to this change, attempting to install a wheel created by tox using PDM or
poetry would return an error like ``There is no item named
'my-package.0.1.dist-info/WHEEL' in the archive`` - by :user:`masenf`.
10 changes: 9 additions & 1 deletion src/tox/tox_env/python/virtual_env/package/pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ def meta_folder(self) -> Path:
meta_folder.mkdir(exist_ok=True)
return meta_folder

@property
def meta_folder_if_populated(self) -> Path | None:
"""Return the metadata directory if it contains any files, otherwise None."""
meta_folder = self.meta_folder
if meta_folder.exists() and tuple(meta_folder.iterdir()):
return meta_folder
return None

def register_run_env(self, run_env: RunToxEnv) -> Generator[tuple[str, str], PackageToxEnv, None]:
yield from super().register_run_env(run_env)
build_type = run_env.conf["package"]
Expand Down Expand Up @@ -210,7 +218,7 @@ def perform_packaging(self, for_env: EnvConfigSet) -> list[Package]:
with self._pkg_lock:
wheel = getattr(self._frontend, method)(
wheel_directory=self.pkg_dir,
metadata_directory=self.meta_folder,
metadata_directory=self.meta_folder_if_populated,
config_settings=self._wheel_config_settings,
).wheel
wheel = create_session_view(wheel, self._package_temp_path)
Expand Down

0 comments on commit 935e7eb

Please sign in to comment.