Skip to content

Commit f2cadf9

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 1947798 commit f2cadf9

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
@@ -192,15 +192,13 @@ class _WheelBuilder():
192192
def __init__(
193193
self,
194194
project: Project,
195-
metadata: Optional[pyproject_metadata.StandardMetadata],
196195
source_dir: pathlib.Path,
197196
install_dir: pathlib.Path,
198197
build_dir: pathlib.Path,
199198
sources: Dict[str, Dict[str, Any]],
200199
copy_files: Dict[str, str],
201200
) -> None:
202201
self._project = project
203-
self._metadata = metadata
204202
self._source_dir = source_dir
205203
self._install_dir = install_dir
206204
self._build_dir = build_dir
@@ -293,13 +291,13 @@ def wheel(self) -> bytes:
293291
@property
294292
def entrypoints_txt(self) -> bytes:
295293
"""dist-info entry_points.txt."""
296-
if not self._metadata:
294+
if not self._project.metadata:
297295
return b''
298296

299-
data = self._metadata.entrypoints.copy()
297+
data = self._project.metadata.entrypoints.copy()
300298
data.update({
301-
'console_scripts': self._metadata.scripts,
302-
'gui_scripts': self._metadata.gui_scripts,
299+
'console_scripts': self._project.metadata.scripts,
300+
'gui_scripts': self._project.metadata.gui_scripts,
303301
})
304302

305303
text = ''
@@ -553,7 +551,7 @@ def _install_path(
553551

554552
def _wheel_write_metadata(self, whl: mesonpy._wheelfile.WheelFile) -> None:
555553
# add metadata
556-
whl.writestr(f'{self.distinfo_dir}/METADATA', self._project.metadata)
554+
whl.writestr(f'{self.distinfo_dir}/METADATA', bytes(self._project.metadata.as_rfc822()))
557555
whl.writestr(f'{self.distinfo_dir}/WHEEL', self.wheel)
558556
if self.entrypoints_txt:
559557
whl.writestr(f'{self.distinfo_dir}/entry_points.txt', self.entrypoints_txt)
@@ -894,7 +892,6 @@ def _validate_metadata(self) -> None:
894892
def _wheel_builder(self) -> _WheelBuilder:
895893
return _WheelBuilder(
896894
self,
897-
self._metadata,
898895
self._source_dir,
899896
self._install_dir,
900897
self._build_dir,
@@ -1002,10 +999,10 @@ def version(self) -> str:
1002999
"""Project version."""
10031000
return str(self._metadata.version)
10041001

1005-
@cached_property
1006-
def metadata(self) -> bytes:
1007-
"""Project metadata as an RFC822 message."""
1008-
return bytes(self._metadata.as_rfc822())
1002+
@property
1003+
def metadata(self) -> pyproject_metadata.StandardMetadata:
1004+
"""Project metadata."""
1005+
return self._metadata
10091006

10101007
@property
10111008
def license_file(self) -> Optional[pathlib.Path]:
@@ -1075,8 +1072,9 @@ def sdist(self, directory: Path) -> pathlib.Path:
10751072
pkginfo_info = tarfile.TarInfo(f'{dist_name}/PKG-INFO')
10761073
if mtime:
10771074
pkginfo_info.mtime = mtime
1078-
pkginfo_info.size = len(self.metadata)
1079-
tar.addfile(pkginfo_info, fileobj=io.BytesIO(self.metadata))
1075+
metadata = bytes(self._metadata.as_rfc822())
1076+
pkginfo_info.size = len(metadata)
1077+
tar.addfile(pkginfo_info, fileobj=io.BytesIO(metadata))
10801078

10811079
return sdist
10821080

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(), 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)