Skip to content

Commit 882f3ad

Browse files
committed
MAINT: streamline project metadata handling some more
To support "dependencies" as a dynamic filed in pyproject.toml and implement build time dependencies pins we need to rewrite this part of the metadata in the wheel builder. Move the RFC 822 serialization of the metadata closer to where it is written to the wheel archive.
1 parent 2f8a128 commit 882f3ad

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

mesonpy/__init__.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,13 +219,11 @@ class _WheelBuilder():
219219
def __init__(
220220
self,
221221
project: Project,
222-
metadata: Optional[pyproject_metadata.StandardMetadata],
223222
source_dir: pathlib.Path,
224223
build_dir: pathlib.Path,
225224
sources: Dict[str, Dict[str, Any]],
226225
) -> None:
227226
self._project = project
228-
self._metadata = metadata
229227
self._source_dir = source_dir
230228
self._build_dir = build_dir
231229
self._sources = sources
@@ -316,13 +314,13 @@ def wheel(self) -> bytes:
316314
@property
317315
def entrypoints_txt(self) -> bytes:
318316
"""dist-info entry_points.txt."""
319-
if not self._metadata:
317+
if not self._project.metadata:
320318
return b''
321319

322-
data = self._metadata.entrypoints.copy()
320+
data = self._project.metadata.entrypoints.copy()
323321
data.update({
324-
'console_scripts': self._metadata.scripts,
325-
'gui_scripts': self._metadata.gui_scripts,
322+
'console_scripts': self._project.metadata.scripts,
323+
'gui_scripts': self._project.metadata.gui_scripts,
326324
})
327325

328326
text = ''
@@ -475,7 +473,7 @@ def _install_path(
475473

476474
def _wheel_write_metadata(self, whl: mesonpy._wheelfile.WheelFile) -> None:
477475
# add metadata
478-
whl.writestr(f'{self.distinfo_dir}/METADATA', self._project.metadata)
476+
whl.writestr(f'{self.distinfo_dir}/METADATA', bytes(self._project.metadata.as_rfc822()))
479477
whl.writestr(f'{self.distinfo_dir}/WHEEL', self.wheel)
480478
if self.entrypoints_txt:
481479
whl.writestr(f'{self.distinfo_dir}/entry_points.txt', self.entrypoints_txt)
@@ -792,7 +790,6 @@ def _validate_metadata(self) -> None:
792790
def _wheel_builder(self) -> _WheelBuilder:
793791
return _WheelBuilder(
794792
self,
795-
self._metadata,
796793
self._source_dir,
797794
self._build_dir,
798795
self._install_plan,
@@ -887,10 +884,10 @@ def version(self) -> str:
887884
"""Project version."""
888885
return str(self._metadata.version)
889886

890-
@cached_property
891-
def metadata(self) -> bytes:
892-
"""Project metadata as an RFC822 message."""
893-
return bytes(self._metadata.as_rfc822())
887+
@property
888+
def metadata(self) -> pyproject_metadata.StandardMetadata:
889+
"""Project metadata."""
890+
return self._metadata
894891

895892
@property
896893
def license_file(self) -> Optional[pathlib.Path]:
@@ -960,8 +957,9 @@ def sdist(self, directory: Path) -> pathlib.Path:
960957
pkginfo_info = tarfile.TarInfo(f'{dist_name}/PKG-INFO')
961958
if mtime:
962959
pkginfo_info.mtime = mtime
963-
pkginfo_info.size = len(self.metadata)
964-
tar.addfile(pkginfo_info, fileobj=io.BytesIO(self.metadata))
960+
metadata = bytes(self._metadata.as_rfc822())
961+
pkginfo_info.size = len(metadata)
962+
tar.addfile(pkginfo_info, fileobj=io.BytesIO(metadata))
965963

966964
return sdist
967965

tests/test_tags.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def wheel_builder_test_factory(monkeypatch, content):
5656
files = defaultdict(list)
5757
files.update({key: [(pathlib.Path(x), os.path.join('build', x)) for x in value] for key, value in content.items()})
5858
monkeypatch.setattr(mesonpy._WheelBuilder, '_wheel_files', files)
59-
return mesonpy._WheelBuilder(None, None, pathlib.Path(), pathlib.Path(), pathlib.Path())
59+
return mesonpy._WheelBuilder(None, pathlib.Path(), pathlib.Path(), pathlib.Path(), {})
6060

6161

6262
def test_tag_empty_wheel(monkeypatch):

0 commit comments

Comments
 (0)