Skip to content

Commit

Permalink
Fix #238: Add build tag to wheel metadata if specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsajip committed Feb 8, 2025
1 parent c6fc08e commit c768e36
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Released: Not yet.

- Add the ``interpret_parsed`` function.

- wheel

- Fix #238: Add build tag to wheel metadata if specified.


0.3.9
~~~~~

Expand Down
2 changes: 2 additions & 0 deletions distlib/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ def build(self, paths, tags=None, wheel_version=None):
'Generator: distlib %s' % __version__,
'Root-Is-Purelib: %s' % is_pure,
]
if self.buildver:
wheel_metadata.append('Build: %s' % self.buildver)
for pyver, abi, arch in self.tags:
wheel_metadata.append('Tag: %s-%s-%s' % (pyver, abi, arch))
p = os.path.join(distinfo, 'WHEEL')
Expand Down
34 changes: 32 additions & 2 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from compat import unittest
from support import DistlibTestCase

from distlib import DistlibException
from distlib import __version__, DistlibException
from distlib.compat import ZipFile, sysconfig, fsencode
from distlib.database import DistributionPath
from distlib.manifest import Manifest
Expand Down Expand Up @@ -405,6 +405,33 @@ def check_built_wheel(self, wheel, expected):
expected = b'#!python\n' + expected
self.assertTrue(data, expected)

def check_built_metadata(self, wheel):
# Check the metadata of the built wheel (see #238).
name, version = wheel.name, wheel.version
fn = os.path.join(wheel.dirname, wheel.filename)
self.assertTrue(os.path.exists(fn))
arcname = '%s-%s.dist-info/WHEEL' % (name, version)
with ZipFile(fn, 'r') as zf:
with zf.open(arcname) as bf:
data = bf.read().decode('utf-8')
if wheel.arch[0] == 'any':
is_pure = 'true'
else:
is_pure = 'false'
expected = {
'Wheel-Version': '%d.%d' % wheel.wheel_version,
'Generator': 'distlib %s' % __version__,
'Root-Is-Purelib': is_pure,
'Build': '1foobar',
'Tag': '%s-%s-%s' % (wheel.pyver[0], wheel.abi[0], wheel.arch[0]),
}
actual = {}
for line in data.splitlines():
i = line.find(':')
key, value = line[:i], line[i + 1:].lstrip()
actual[key] = value
self.assertEqual(actual, expected)

def test_build_tags(self):
workdir = tempfile.mkdtemp()
self.addCleanup(shutil.rmtree, workdir)
Expand Down Expand Up @@ -453,14 +480,17 @@ def test_build_tags(self):
self.check_built_wheel(wheel, expected)

# Make a non-pure wheel with default tags
# On this last build in the test, set a buildver and check the metadata
paths.pop('purelib')
paths['platlib'] = platlib
wheel.buildver = '1foobar'
wheel.build(paths)
expected['pyver'] = [IMPVER]
expected['abi'] = [ABI]
expected['arch'] = [ARCH]
expected['filename'] = 'dummy-0.1-%s-%s-%s.whl' % (IMPVER, ABI, ARCH)
expected['filename'] = 'dummy-0.1-%s-%s-%s-%s.whl' % (wheel.buildver, IMPVER, ABI, ARCH)
self.check_built_wheel(wheel, expected)
self.check_built_metadata(wheel)

def do_build_and_install(self, dist):
srcdir = tempfile.mkdtemp()
Expand Down

0 comments on commit c768e36

Please sign in to comment.