diff options
author | Nate Coraor <nate@bx.psu.edu> | 2016-02-02 18:18:04 -0500 |
---|---|---|
committer | Nate Coraor <nate@bx.psu.edu> | 2016-02-02 18:18:04 -0500 |
commit | 6e77793f678f196df64e073f7b76728cb43395f0 (patch) | |
tree | 289a71c24c363ef10b807667b0dfdff7a17c0362 | |
parent | facb3a9f80af9e8f13eb121ff27d20a8c5f8b57a (diff) | |
download | wheel-6e77793f678f196df64e073f7b76728cb43395f0.tar.gz |
Additional support for forcing setting of the platform tag (standardizes the
option on both types of wheels, makes it work for non-pure wheels).
-rw-r--r-- | wheel/bdist_wheel.py | 20 | ||||
-rw-r--r-- | wheel/pep425tags.py | 10 | ||||
-rw-r--r-- | wheel/test/test_tagopt.py | 69 |
3 files changed, 81 insertions, 18 deletions
diff --git a/wheel/bdist_wheel.py b/wheel/bdist_wheel.py index e858649..8920fce 100644 --- a/wheel/bdist_wheel.py +++ b/wheel/bdist_wheel.py @@ -132,31 +132,27 @@ class bdist_wheel(Command): safer_version(self.distribution.get_version()))) def get_tag(self): - supported_tags = pep425tags.get_supported() + plat_tag = self.plat_tag or self.plat_name + if plat_tag: + plat_tag = plat_tag.replace('-', '_').replace('.', '_') + supported_tags = pep425tags.get_supported(supplied_platform=plat_tag) if self.root_is_pure: if self.universal: impl = 'py2.py3' else: impl = self.python_tag - if self.plat_tag: - plat_tag = self.plat_tag.replace('-', '_').replace('.', '_') - else: + if not plat_tag: plat_tag = 'any' tag = (impl, 'none', plat_tag) else: - plat_name = self.plat_tag - if plat_name is None: - if self.plat_name: - plat_name = self.plat_name - else: - plat_name = get_platform() - plat_name = plat_name.replace('-', '_').replace('.', '_') impl_name = get_abbr_impl() impl_ver = get_impl_ver() # PEP 3149 abi_tag = str(get_abi_tag()).lower() - tag = (impl_name + impl_ver, abi_tag, plat_name) + if not plat_tag: + plat_tag = get_platform().replace('-', '_').replace('.', '_') + tag = (impl_name + impl_ver, abi_tag, plat_tag) # XXX switch to this alternate implementation for non-pure: assert tag == supported_tags[0] return tag diff --git a/wheel/pep425tags.py b/wheel/pep425tags.py index 2fe8510..106c879 100644 --- a/wheel/pep425tags.py +++ b/wheel/pep425tags.py @@ -103,7 +103,7 @@ def get_platform(): return distutils.util.get_platform().replace('.', '_').replace('-', '_') -def get_supported(versions=None): +def get_supported(versions=None, supplied_platform=None): """Return a list of supported tags for each version specified in `versions`. @@ -139,11 +139,15 @@ def get_supported(versions=None): abis.append('none') - arch = get_platform() + platforms = [] + if supplied_platform: + platforms.append(supplied_platform) + platforms.append(get_platform()) # Current version, current API (built specifically for our Python): for abi in abis: - supported.append(('%s%s' % (impl, versions[0]), abi, arch)) + for arch in platforms: + supported.append(('%s%s' % (impl, versions[0]), abi, arch)) # No abi / arch, but requires our implementation: for i, version in enumerate(versions): diff --git a/wheel/test/test_tagopt.py b/wheel/test/test_tagopt.py index 300fcf9..a8de089 100644 --- a/wheel/test/test_tagopt.py +++ b/wheel/test/test_tagopt.py @@ -10,27 +10,39 @@ import tempfile import subprocess SETUP_PY = """\ -from setuptools import setup +from setuptools import setup, Extension setup( name="Test", version="1.0", author_email="author@example.com", py_modules=["test"], + {ext_modules} ) """ +EXT_MODULES = "ext_modules=[Extension('_test', sources=['test.c'])]," + @pytest.fixture -def temp_pkg(request): +def temp_pkg(request, ext=False): tempdir = tempfile.mkdtemp() def fin(): shutil.rmtree(tempdir) request.addfinalizer(fin) temppath = py.path.local(tempdir) temppath.join('test.py').write('print("Hello, world")') - temppath.join('setup.py').write(SETUP_PY) + if ext: + temppath.join('test.c').write('#include <stdio.h>') + setup_py = SETUP_PY.format(ext_modules=EXT_MODULES) + else: + setup_py = SETUP_PY.format(ext_modules='') + temppath.join('setup.py').write(setup_py) return temppath +@pytest.fixture +def temp_ext_pkg(request): + return temp_pkg(request, ext=True) + def test_default_tag(temp_pkg): subprocess.check_call([sys.executable, 'setup.py', 'bdist_wheel'], cwd=str(temp_pkg)) @@ -110,3 +122,54 @@ def test_legacy_wheel_section_in_setup_cfg(temp_pkg): assert wheels[0].basename.startswith('Test-1.0-py2.py3-') assert wheels[0].ext == '.whl' +def test_plat_tag_purepy(temp_pkg): + subprocess.check_call( + [sys.executable, 'setup.py', 'bdist_wheel', '--plat-tag=testplat.pure'], + cwd=str(temp_pkg)) + dist_dir = temp_pkg.join('dist') + assert dist_dir.check(dir=1) + wheels = dist_dir.listdir() + assert len(wheels) == 1 + assert wheels[0].basename.endswith('-testplat_pure.whl') + assert wheels[0].ext == '.whl' + +def test_plat_tag_ext(temp_ext_pkg): + try: + subprocess.check_call( + [sys.executable, 'setup.py', 'bdist_wheel', '--plat-tag=testplat.arch'], + cwd=str(temp_ext_pkg)) + except subprocess.CalledProcessError: + pytest.skip("Cannot compile C Extensions") + dist_dir = temp_ext_pkg.join('dist') + assert dist_dir.check(dir=1) + wheels = dist_dir.listdir() + assert len(wheels) == 1 + assert wheels[0].basename.endswith('-testplat_arch.whl') + assert wheels[0].ext == '.whl' + +def test_plat_tag_purepy_in_setupcfg(temp_pkg): + temp_pkg.join('setup.cfg').write('[bdist_wheel]\nplat_tag=testplat.pure') + subprocess.check_call( + [sys.executable, 'setup.py', 'bdist_wheel'], + cwd=str(temp_pkg)) + dist_dir = temp_pkg.join('dist') + assert dist_dir.check(dir=1) + wheels = dist_dir.listdir() + assert len(wheels) == 1 + assert wheels[0].basename.endswith('-testplat_pure.whl') + assert wheels[0].ext == '.whl' + +def test_plat_tag_ext_in_setupcfg(temp_ext_pkg): + temp_ext_pkg.join('setup.cfg').write('[bdist_wheel]\nplat_tag=testplat.arch') + try: + subprocess.check_call( + [sys.executable, 'setup.py', 'bdist_wheel'], + cwd=str(temp_ext_pkg)) + except subprocess.CalledProcessError: + pytest.skip("Cannot compile C Extensions") + dist_dir = temp_ext_pkg.join('dist') + assert dist_dir.check(dir=1) + wheels = dist_dir.listdir() + assert len(wheels) == 1 + assert wheels[0].basename.endswith('-testplat_arch.whl') + assert wheels[0].ext == '.whl' |