|
17 | 17 | from compat import unittest
|
18 | 18 | from support import DistlibTestCase
|
19 | 19 |
|
20 |
| -from distlib import DistlibException |
| 20 | +from distlib import __version__, DistlibException |
21 | 21 | from distlib.compat import ZipFile, sysconfig, fsencode
|
22 | 22 | from distlib.database import DistributionPath
|
23 | 23 | from distlib.manifest import Manifest
|
@@ -405,6 +405,33 @@ def check_built_wheel(self, wheel, expected):
|
405 | 405 | expected = b'#!python\n' + expected
|
406 | 406 | self.assertTrue(data, expected)
|
407 | 407 |
|
| 408 | + def check_built_metadata(self, wheel): |
| 409 | + # Check the metadata of the built wheel (see #238). |
| 410 | + name, version = wheel.name, wheel.version |
| 411 | + fn = os.path.join(wheel.dirname, wheel.filename) |
| 412 | + self.assertTrue(os.path.exists(fn)) |
| 413 | + arcname = '%s-%s.dist-info/WHEEL' % (name, version) |
| 414 | + with ZipFile(fn, 'r') as zf: |
| 415 | + with zf.open(arcname) as bf: |
| 416 | + data = bf.read().decode('utf-8') |
| 417 | + if wheel.arch[0] == 'any': |
| 418 | + is_pure = 'true' |
| 419 | + else: |
| 420 | + is_pure = 'false' |
| 421 | + expected = { |
| 422 | + 'Wheel-Version': '%d.%d' % wheel.wheel_version, |
| 423 | + 'Generator': 'distlib %s' % __version__, |
| 424 | + 'Root-Is-Purelib': is_pure, |
| 425 | + 'Build': '1foobar', |
| 426 | + 'Tag': '%s-%s-%s' % (wheel.pyver[0], wheel.abi[0], wheel.arch[0]), |
| 427 | + } |
| 428 | + actual = {} |
| 429 | + for line in data.splitlines(): |
| 430 | + i = line.find(':') |
| 431 | + key, value = line[:i], line[i + 1:].lstrip() |
| 432 | + actual[key] = value |
| 433 | + self.assertEqual(actual, expected) |
| 434 | + |
408 | 435 | def test_build_tags(self):
|
409 | 436 | workdir = tempfile.mkdtemp()
|
410 | 437 | self.addCleanup(shutil.rmtree, workdir)
|
@@ -453,14 +480,17 @@ def test_build_tags(self):
|
453 | 480 | self.check_built_wheel(wheel, expected)
|
454 | 481 |
|
455 | 482 | # Make a non-pure wheel with default tags
|
| 483 | + # On this last build in the test, set a buildver and check the metadata |
456 | 484 | paths.pop('purelib')
|
457 | 485 | paths['platlib'] = platlib
|
| 486 | + wheel.buildver = '1foobar' |
458 | 487 | wheel.build(paths)
|
459 | 488 | expected['pyver'] = [IMPVER]
|
460 | 489 | expected['abi'] = [ABI]
|
461 | 490 | expected['arch'] = [ARCH]
|
462 |
| - expected['filename'] = 'dummy-0.1-%s-%s-%s.whl' % (IMPVER, ABI, ARCH) |
| 491 | + expected['filename'] = 'dummy-0.1-%s-%s-%s-%s.whl' % (wheel.buildver, IMPVER, ABI, ARCH) |
463 | 492 | self.check_built_wheel(wheel, expected)
|
| 493 | + self.check_built_metadata(wheel) |
464 | 494 |
|
465 | 495 | def do_build_and_install(self, dist):
|
466 | 496 | srcdir = tempfile.mkdtemp()
|
|
0 commit comments