def test_bugfix_release_platform_tag(self, monkeypatch, capsys): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(sysconfig, "get_platform", return_factory("macosx-10.9-x86_64")) monkeypatch.setattr( os, "walk", return_factory([( dylib_dir, [], [ "test_lib_10_6.dylib", "test_lib_10_6_fat.dylib", "test_lib_10_10_10.dylib", ], )]), ) assert get_platform(dylib_dir) == "macosx_10_10_x86_64" captured = capsys.readouterr() assert "This wheel needs a higher macOS version than" in captured.err monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.9") assert get_platform(dylib_dir) == "macosx_10_10_x86_64" captured = capsys.readouterr() assert "This wheel needs a higher macOS version than" in captured.err
def test_bump_platform_tag_by_env_variable(self, monkeypatch, capsys): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64")) monkeypatch.setattr(os, "walk", return_factory( [(dylib_dir, [], ["test_lib_10_6.dylib", "test_lib_10_6_fat.dylib"])] )) assert get_platform(dylib_dir) == "macosx_10_9_x86_64" monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.10") assert get_platform(dylib_dir) == "macosx_10_10_x86_64" captured = capsys.readouterr() assert captured.err == ""
def test_version_bump(self, monkeypatch, capsys): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64")) assert get_platform(dylib_dir) == "macosx_11_0_x86_64" captured = capsys.readouterr() assert "[WARNING] This wheel needs a higher macOS version than" in captured.err
def test_simple(self, monkeypatch): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(sysconfig, "get_platform", return_factory("macosx-11.0-x86_64")) assert get_platform(dylib_dir) == "macosx_11_0_x86_64"
def get_tag(self): # originally get_tag would branch for 'root_is_pure" and return # tags suitable for wheels running on any py3/py2 system. So # setting the attribute in finalize_options was enough. But # In the 3.5 instead of the attribute, # self.distribution.is_pure() is called, so we have to overwrite # the complete functions... supported_tags = pep425tags.get_supported() plat_name = self.plat_name if plat_name is None: plat_name = get_platform() plat_name = plat_name.replace('-', '_').replace('.', '_') impl_name = get_abbr_impl() impl_ver = get_impl_ver() # PEP 3149 -- no SOABI in Py 2 # For PyPy? # "pp%s%s" % (sys.pypy_version_info.major, # sys.pypy_version_info.minor) abi_tag = sysconfig.get_config_vars().get('SOABI', 'none') if abi_tag.startswith('cpython-'): abi_tag = 'cp' + abi_tag.rsplit('-', 1)[-1] tag = (impl_name + impl_ver, abi_tag, plat_name) # XXX switch to this alternate implementation for non-pure: assert tag == supported_tags[0] return tag
def test_get_platform_bigsur_platform(self, monkeypatch): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-11-x86_64")) monkeypatch.setattr(os, "walk", return_factory( [(dylib_dir, [], ["test_lib_10_6.dylib", "test_lib_10_10_fat.dylib"])] )) assert get_platform(dylib_dir) == "macosx_11_0_x86_64"
def get_tags(): """Get proper tags using wheel's package implementation of PEP427.""" impl = wheel_tags.interpreter_name() + wheel_tags.interpreter_version() abi = pep.get_abi_tag() try: arch = pep.safer_name(pep.get_platform(None)) except: arch = pep.safer_name(pep.get_platform()) if arch == "linux_x86_64": arch = 'manylinux2014_x86_64' elif arch == "linux_i686": arch = 'manylinux2014_i686' elif arch == "linux_aarch64": arch = 'manylinux2014_aarch64' if 'macosx' in arch: arch = arch.replace('.', '_') tags = f'{impl}-{abi}-{arch}' return tags
def test_warning_on_to_low_env_variable(self, monkeypatch, capsys): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64")) monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.8") monkeypatch.setattr(os, "walk", return_factory( [(dylib_dir, [], ["test_lib_10_6.dylib", "test_lib_10_6_fat.dylib"])] )) assert get_platform(dylib_dir) == "macosx_10_9_x86_64" captured = capsys.readouterr() assert "MACOSX_DEPLOYMENT_TARGET is set to a lower value (10.8) than the" in captured.err
def test_information_about_problematic_files_python_version(self, monkeypatch, capsys): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64")) monkeypatch.setattr(os, "walk", return_factory( [(dylib_dir, [], ["test_lib_10_6.dylib", "test_lib_10_10_fat.dylib"])] )) assert get_platform(dylib_dir) == "macosx_10_10_x86_64" captured = capsys.readouterr() assert "[WARNING] This wheel needs a higher macOS version than" in captured.err assert "the version your Python interpreter is compiled against." in captured.err assert "test_lib_10_10_fat.dylib" in captured.err
def finalize_options(self): _bdist_wheel.finalize_options(self) # Mark us as not a pure python package (we have platform specific ctpse lib) if self.plat_name != "any": self.root_is_pure = False plat_name = (self.plat_name or get_platform()).replace('-', '_').replace('.', '_') if plat_name == "linux_x86_64" or plat_name == "manylinux1_x86_64": self.distribution.package_data[""] = ["ctpse/LinuxDataCollect64.so"] elif plat_name == "win32": self.distribution.package_data[""] = ["ctpse/WinDataCollect32.dll"] elif plat_name == "win_amd64": self.distribution.package_data[""] = ["ctpse/WinDataCollect64.dll"]
def run(self): self.run_command('bdist_app') # Encode targeted macOS plaftorm in the filename. from wheel.bdist_wheel import get_platform platform = get_platform('dist/Plover.app') args = '{out!r}, {name!r}, {settings!r}, lookForHiDPI=True'.format( out='dist/%s-%s.dmg' % (PACKAGE, platform), name=__software_name__.capitalize(), settings='osx/dmg_resources/settings.py', ) log.info('running dmgbuild(%s)', args) script = "__import__('dmgbuild').build_dmg(" + args + ')' subprocess.check_call((sys.executable, '-u', '-c', script))
def test_information_about_problematic_files_env_variable(self, monkeypatch, capsys): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(distutils.util, "get_platform", return_factory("macosx-10.9-x86_64")) monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "10.8") monkeypatch.setattr(os, "walk", return_factory( [(dylib_dir, [], ["test_lib_10_6.dylib", "test_lib_10_10_fat.dylib"])] )) assert get_platform(dylib_dir) == "macosx_10_10_x86_64" captured = capsys.readouterr() assert "[WARNING] This wheel needs a higher macOS version than" in captured.err assert "is set in MACOSX_DEPLOYMENT_TARGET variable." in captured.err assert "test_lib_10_10_fat.dylib" in captured.err
def test_get_platform_bigsur_env(self, monkeypatch): dirname = os.path.dirname(__file__) dylib_dir = os.path.join(dirname, "testdata", "macosx_minimal_system_version") monkeypatch.setattr(sysconfig, "get_platform", return_factory("macosx-10.9-x86_64")) monkeypatch.setenv("MACOSX_DEPLOYMENT_TARGET", "11") monkeypatch.setattr( os, "walk", return_factory([ (dylib_dir, [], ["test_lib_10_6.dylib", "test_lib_10_10_fat.dylib"]) ]), ) assert get_platform(dylib_dir) == "macosx_11_0_x86_64"
def finalize_options(self): # pragma: no cover """Set platform dependent wheel tag. |cslug| packages contain binaries but they don't use :c:`#include <Python.h>` like traditional Python extensions do. This makes wheels dependent OS but not Python version dependent. """ # Tag setting is done by ``bdist_wheel.get_tag()`` later in the # build but overloading that means reimplementing some rather # complex platform normalisation. Injecting the platform name here, # before the normalisation, ensures that it gets normalised. # Setting ``plat_name`` is equivalent to using the ``--plat`` CLI # option. import platform from wheel.bdist_wheel import get_platform self.plat_name = get_platform(self.bdist_dir) if platform.system() == "Darwin": # If on mac, deal with the x86_64/arm64/universal2 shenanigans # and the deployment target. self.plat_name = _macos_platform_tag(self.plat_name) super().finalize_options()
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # This unit exists purely to work around the ever-churning API of the wheel # package. Because it's a 0.x version it's API is subject to change, and it # does ... frequently. try: from wheel import bdist_wheel except ImportError: from wheel import pep425tags as bdist_wheel try: bdist_wheel.get_platform() except TypeError: def get_platform(archive_root=None): return bdist_wheel.get_platform(archive_root) else: get_platform = bdist_wheel.get_platform try: get_impl_ver = bdist_wheel.get_impl_ver except AttributeError: from wheel.vendored.packaging.tags import interpreter_version as get_impl_ver get_abi_tag = bdist_wheel.get_abi_tag
def finalize_options(self): super().finalize_options() self.plat_name_supplied = True self.plat_name = get_platform(self.bdist_dir)
def get_platform(archive_root=None): return bdist_wheel.get_platform(archive_root)
def finalize_options(self): if parse_version(wheel.__version__) >= parse_version('0.34.0'): self.plat_name = get_platform(self.bdist_dir) else: self.plat_name = get_platform() bdist_wheel.finalize_options(self)
def get_tag(self): # bdist sets self.plat_name if unset, we should only use it for purepy # wheels if the user supplied it. if self.plat_name_supplied: plat_name = self.plat_name elif self.root_is_pure: plat_name = 'any' else: # macosx contains system version in platform name so need special handle if self.plat_name and not self.plat_name.startswith("macosx"): plat_name = self.plat_name else: # on macosx always limit the platform name to comply with any # c-extension modules in bdist_dir, since the user can specify # a higher MACOSX_DEPLOYMENT_TARGET via tools like CMake # on other platforms, and on macosx if there are no c-extension # modules, use the default platform name. plat_name = get_platform(self.bdist_dir) if plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize == 2147483647: plat_name = 'linux_i686' # To allow uploading to pypi, we need the wheel name # to contain 'manylinux1'. # The wheel which will be uploaded to pypi will be # built on RHEL7, so it doesn't completely qualify for # manylinux1 support, but it's the minimum requirement # for building Qt. We only enable this for x64 limited # api builds (which are the only ones uploaded to # pypi). # TODO: Add actual distro detection, instead of # relying on limited_api option. if (plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize > 2147483647 and (self.py_limited_api or sys.version_info[0] == 2)): plat_name = 'manylinux1_x86_64' plat_name = plat_name.replace('-', '_').replace('.', '_') if self.root_is_pure: if self.universal: impl = 'py2.py3' else: impl = self.python_tag tag = (impl, 'none', plat_name) else: impl_name = tags.interpreter_name() impl_ver = tags.interpreter_version() impl = impl_name + impl_ver # We don't work on CPython 3.1, 3.0. if self.py_limited_api and (impl_name + impl_ver).startswith('cp3'): impl = self.py_limited_api abi_tag = "abi3" if sys.platform != "win32" else "none" else: abi_tag = str(get_abi_tag()).lower() tag = (impl, abi_tag, plat_name) supported_tags = [(t.interpreter, t.abi, t.platform) for t in tags.sys_tags()] # XXX switch to this alternate implementation for non-pure: if (self.py_limited_api) or (plat_name in ('manylinux1_x86_64') and sys.version_info[0] == 2): return tag assert tag in supported_tags, ( "would build wheel with unsupported tag {}".format(tag)) return tag
def test_get_platform_linux(monkeypatch): monkeypatch.setattr(sysconfig, "get_platform", return_factory("linux-x86_64")) monkeypatch.setattr(sys, "maxsize", 2147483647) assert get_platform(None) == "linux_i686"
def finalize_options(self): self.plat_name = get_platform(None) # force a platform tag _bdist_wheel.finalize_options(self)
from setuptools import setup, find_packages, Extension from setuptools.command.build_ext import build_ext from wheel.bdist_wheel import get_platform, bdist_wheel def platform_ext(plat): if 'linux' in plat: return '.so' if 'macosx' in plat: return '.dylib' if 'win' in plat: return '.dll' raise RuntimeError('Invalid platform value: %s' % plat) platform = get_platform(None) class bdist_wheel_injected(bdist_wheel): def finalize_options(self): super(bdist_wheel_injected, self).finalize_options() self.root_is_pure = True def run(self): global platform platform = self.plat_name super(bdist_wheel_injected, self).run() class CopyNativeExtension(Extension): def __init__(self, name):
import os, sys, shutil, unittest, tempfile, tarfile, virtualenv, warnings from wheel.bdist_wheel import get_abi_tag, get_platform from packaging.tags import interpreter_name, interpreter_version sys.path.insert(0, "src") from from_file import versions_from_file import common pyver_major = "py%d" % sys.version_info[0] pyver = "py%d.%d" % sys.version_info[:2] # For binary wheels with native code impl, impl_ver = interpreter_name(), interpreter_version() abi = get_abi_tag() try: plat = get_platform(None) except TypeError: # wheel < 0.34 plat = get_platform() class _Invocations(common.Common): def setUp(self): if False: # when debugging, put the generated files in a predictable place self.testdir = os.path.abspath("t") if os.path.exists(self.testdir): return os.mkdir(self.testdir) else: self.testdir = tempfile.mkdtemp() os.mkdir(self.subpath("cache"))