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: plat_name = self.plat_name or get_platform() if plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize == 2147483647: plat_name = 'linux_i686' 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 = 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) supported_tags = pep425tags.get_supported( supplied_platform=plat_name if self.plat_name_supplied else None) # XXX switch to this alternate implementation for non-pure: assert tag == supported_tags[0], "%s != %s" % (tag, supported_tags[0]) return tag
def main_loop(self, queue, timeout=300): """ The main messaging loop. Sends the initial request, and dispatches replies via :meth:`handle_reply`. Implements a *timeout* for responses from the master and raises :exc:`MasterTimeout` if *timeout* seconds are exceeded. """ request = [ 'HELLO', self.config.timeout, pep425tags.get_impl_ver(), pep425tags.get_abi_tag(), pep425tags.get_platform(), self.label ] while True: queue.send_pyobj(request) start = time() while True: self.systemd.watchdog_ping() if queue.poll(60000): reply, *args = queue.recv_pyobj() request = self.handle_reply(reply, *args) break elif time() - start > timeout: self.logger.warning('Timed out waiting for master') if self.builder: self.logger.warning('Discarding current build') self.builder.clean() self.builder = None self.slave_id = None raise MasterTimeout()
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: plat_name = self.plat_name or get_platform() if plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize == 2147483647: plat_name = 'linux_i686' 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 = 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) supported_tags = pep425tags.get_supported( supplied_platform=plat_name if self. plat_name_supplied else None) # XXX switch to this alternate implementation for non-pure: assert tag == supported_tags[0], "%s != %s" % (tag, supported_tags[0]) return tag
def main_loop(self, queue, timeout=300): """ The main messaging loop. Sends the initial request, and dispatches replies via :meth:`handle_reply`. Implements a *timeout* for responses from the master and raises :exc:`MasterTimeout` if *timeout* seconds are exceeded. """ msg, data = 'HELLO', [ self.config.timeout, pep425tags.get_impl_ver(), pep425tags.get_abi_tag(), pep425tags.get_platform(), self.label ] while True: queue.send_msg(msg, data) start = time() while True: self.systemd.watchdog_ping() if queue.poll(1): msg, data = queue.recv_msg() msg, data = self.handle_reply(msg, data) break elif time() - start > timeout: self.logger.warning('Timed out waiting for master') raise MasterTimeout()
def bdist_wheel_get_tag(self): supplied = self.plat_name if self.plat_name_supplied else None supported_tags = pep425tags_get_supported(supplied_platform=supplied) if self.root_is_pure: if self.universal: impl = 'py2.py3' else: impl = self.python_tag tag = (impl, 'none', 'any') else: plat_name = self.plat_name if plat_name is None: plat_name = get_platforms(major_only=True)[0] 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) # XXX switch to this alternate implementation for non-pure: assert tag in supported_tags if plat_name in self.plat_compat and 'build' in self.plat_compat[ plat_name]: tag = (impl_name + impl_ver, abi_tag, self.plat_compat[plat_name]['build']) return tag
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: plat_name = self.plat_name or wheel_get_platform() 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 = get_abbr_impl() impl_ver = get_impl_ver() 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 = pep425tags.get_supported( supplied_platform=plat_name if self. plat_name_supplied else None) # 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 == supported_tags[0], "%s != %s" % (tag, supported_tags[0]) assert tag in supported_tags, ( "would build wheel with unsupported tag {}".format(tag)) return tag
def get_pytorch(): ##Install torch # http://pytorch.org/ if 'torch' not in sys.modules: from os import path from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag()) accelerator = 'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu' call(["pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.3.0.post4-{platform}-linux_x86_64.whl torchvision"])
def FromCurrentSystem(cls): """Fill a Uname from the currently running platform.""" uname = platform.uname() fqdn = socket.getfqdn() if fqdn == _LOCALHOST: # Avoid returning 'localhost' when there is a better value to use. fqdn = socket.gethostname() system = uname[0] architecture, _ = platform.architecture() if system == "Windows": service_pack = platform.win32_ver()[2] kernel = uname[3] # 5.1.2600 release = uname[2] # XP, 2000, 7 version = uname[3] + service_pack # 5.1.2600 SP3, 6.1.7601 SP1 elif system == "Darwin": kernel = uname[2] # 12.2.0 release = "OSX" # OSX version = platform.mac_ver()[0] # 10.8.2 elif system == "Linux": kernel = uname[2] # 3.2.5 release = distro.name() version = distro.version() # Emulate PEP 425 naming conventions - e.g. cp27-cp27mu-linux_x86_64. if pep425tags: try: # 0.33.6 pep_platform = pep425tags.get_platform() except TypeError: # 0.34.2 pep_platform = pep425tags.get_platform(None) pep425tag = "%s%s-%s-%s" % ( pep425tags.get_abbr_impl(), pep425tags.get_impl_ver(), str(pep425tags.get_abi_tag()).lower(), pep_platform) else: # For example: windows_7_amd64 pep425tag = "%s_%s_%s" % (system, release, architecture) return cls( system=system, architecture=architecture, release=release, version=version, machine=uname[4], # x86, x86_64 kernel=kernel, fqdn=fqdn, pep425tag=pep425tag, )
def get_server_info(): from distutils.version import LooseVersion import pip, sysconfig pipversion = LooseVersion(pip.__version__) if pipversion >= LooseVersion("19.3"): from wheel import pep425tags elif pipversion > LooseVersion("10"): from pip._internal import pep425tags else: from pip import pep425tags return { "impl_version_info": pep425tags.get_impl_version_info(), #(3,7) "abbr_impl": pep425tags.get_abbr_impl(), #'cp' "abi_tag": pep425tags.get_abi_tag(), #'cp37m' "platform": sysconfig.get_platform().replace("-", "_") #'win_amd64', 'linux_x86_64' }
def FromCurrentSystem(cls): """Fill a Uname from the currently running platform.""" uname = platform.uname() fqdn = socket.getfqdn() system = uname[0] architecture, _ = platform.architecture() if system == "Windows": service_pack = platform.win32_ver()[2] kernel = uname[3] # 5.1.2600 release = uname[2] # XP, 2000, 7 version = uname[3] + service_pack # 5.1.2600 SP3, 6.1.7601 SP1 elif system == "Darwin": kernel = uname[2] # 12.2.0 release = "OSX" # OSX version = platform.mac_ver()[0] # 10.8.2 elif system == "Linux": kernel = uname[2] # 3.2.5 release = platform.linux_distribution()[0] # Ubuntu version = platform.linux_distribution()[1] # 12.04 # Emulate PEP 425 naming conventions - e.g. cp27-cp27mu-linux_x86_64. if pep425tags: pep425tag = "%s%s-%s-%s" % ( pep425tags.get_abbr_impl(), pep425tags.get_impl_ver(), str(pep425tags.get_abi_tag()).lower(), pep425tags.get_platform(), ) else: # For example: windows_7_amd64 pep425tag = "%s_%s_%s" % (system, release, architecture) return cls( system=system, architecture=architecture, node=uname[1], release=release, version=version, machine=uname[4], # x86, x86_64 kernel=kernel, fqdn=fqdn, pep425tag=pep425tag, )
def FromCurrentSystem(cls): """Fill a Uname from the currently running platform.""" uname = platform.uname() fqdn = socket.getfqdn() system = uname[0] architecture, _ = platform.architecture() if system == "Windows": service_pack = platform.win32_ver()[2] kernel = uname[3] # 5.1.2600 release = uname[2] # XP, 2000, 7 version = uname[3] + service_pack # 5.1.2600 SP3, 6.1.7601 SP1 elif system == "Darwin": kernel = uname[2] # 12.2.0 release = "OSX" # OSX version = platform.mac_ver()[0] # 10.8.2 elif system == "Linux": kernel = uname[2] # 3.2.5 release = platform.linux_distribution()[0] # Ubuntu version = platform.linux_distribution()[1] # 12.04 # Emulate PEP 425 naming conventions - e.g. cp27-cp27mu-linux_x86_64. if pep425tags: pep425tag = "%s%s-%s-%s" % (pep425tags.get_abbr_impl(), pep425tags.get_impl_ver(), str(pep425tags.get_abi_tag()).lower(), pep425tags.get_platform()) else: # For example: windows_7_amd64 pep425tag = "%s_%s_%s" % (system, release, architecture) return cls( system=system, architecture=architecture, node=uname[1], release=release, version=version, machine=uname[4], # x86, x86_64 kernel=kernel, fqdn=fqdn, pep425tag=pep425tag, )
def tag(pure): """Return the tag part of a wheel filename for this version of Python. https://www.python.org/dev/peps/pep-0491/#file-name-convention describes the filename convention for wheels. 'tag' returns the {python tag}-{abi tag}-{platform tag} part of the filename that is compatible with the executing version of Python. Parameters: ----------- pure : boolean Whether the bundle only contains Python code (no C/C++) Returns: -------- str Dash-separated tag string, *e.g.*, **cp36-cp36m-win_amd64** """ # Code below is taken from wheel==0.29 bdist_wheel.py from wheel.pep425tags import get_impl_ver impl_ver = get_impl_ver() if pure: impl = "py" + impl_ver[0] abi = "none" platform = "any" else: from wheel.pep425tags import get_abbr_impl, get_abi_tag impl = get_abbr_impl() + impl_ver # get_abi_tag generates warning messages import warnings warnings.simplefilter("ignore", RuntimeWarning) abi = get_abi_tag() from distutils.util import get_platform platform = get_platform() def fix_name(name): return name.replace('-', '_').replace('.', '_') return "%s-%s-%s" % (fix_name(impl), fix_name(abi), fix_name(platform))
def from_current_system(cls, session=None): """Gets a Uname object populated from the current system""" uname = platform.uname() fqdn = socket.getfqdn() system = uname[0] architecture, _ = platform.architecture() if system == "Windows": service_pack = platform.win32_ver()[2] kernel = uname[3] # 5.1.2600 release = uname[2] # XP, 2000, 7 version = uname[3] + service_pack # 5.1.2600 SP3, 6.1.7601 SP1 elif system == "Darwin": kernel = uname[2] # 12.2.0 release = "OSX" # OSX version = platform.mac_ver()[0] # 10.8.2 elif system == "Linux": kernel = uname[2] # 3.2.5 release = platform.linux_distribution()[0] # Ubuntu version = platform.linux_distribution()[1] # 12.04 # Emulate PEP 425 naming conventions - e.g. cp27-cp27mu-linux_x86_64. pep425tag = "%s%s-%s-%s" % (pep425tags.get_abbr_impl(), pep425tags.get_impl_ver(), str(pep425tags.get_abi_tag()).lower(), pep425tags.get_platform()) return cls.from_keywords( session=session, system=system, architecture=architecture, node=uname[1], release=release, version=version, machine=uname[4], # x86, x86_64 kernel=kernel, fqdn=fqdn, pep425tag=pep425tag, )
from sys import argv from wheel import pep425tags as w assert len(argv) == 3 print("cuda%s-pygenn-%s-%s%s-%s-%s.whl" % (argv[1], argv[2], w.get_abbr_impl(), w.get_impl_ver(), w.get_abi_tag(), w.get_platform()))
def __bootstrap__(): import re __package__ = __name__.replace('.c_qdpxx_sdb', '') global __bootstrap__, __loader__, __file__ import sys, pkg_resources, imp version = [] # === try: import NPLQCD.UTIL.Location version = [NPLQCD.UTIL.Location.identify()] except Exception as e: import os import re module = re.sub('\.', '_', __package__) if module in os.environ: version = [os.environ[module]] #/// _V = [] # === try: # Utility script to print the python tag + the abi tag for a Python # See PEP 425 for exactly what these are, but an example would be: # cp27-cp27mu from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag from setuptools import distutils import re abi = "{0}{1}-{2}".format(get_abbr_impl(), get_impl_ver(), get_abi_tag()) platform_ = re.sub('[-.]', '_', distutils.util.get_platform()) _V = [f'{abi}-{platform_}'] except: import platform _V = [platform.python_version()] #/// so = '/'.join(['..', 'Cython-shared-library'] + version + _V + ['c_qdpxx_sdb.so']) __file__ = pkg_resources.resource_filename(__name__, so) __loader__ = None del __bootstrap__, __loader__ imp.load_dynamic(__name__, __file__)
malloc = False opts, args = getopt.getopt(sys.argv[1:], "p") for opt, val in opts: if opt == "-p": pure = True # Code below is taken from wheel==0.29 bdist_wheel.py from wheel.pep425tags import get_impl_ver impl_ver = get_impl_ver() if pure: impl = "py" + impl_ver abi = "none" platform = "any" else: from wheel.pep425tags import get_abbr_impl, get_abi_tag impl = get_abbr_impl() + impl_ver # get_abi_tag generates warning messages import warnings warnings.simplefilter("ignore", RuntimeWarning) abi = get_abi_tag() from distutils.util import get_platform platform = get_platform() def fix_name(name): return name.replace('-', '_').replace('.', '_') print("%s-%s-%s" % (fix_name(impl), fix_name(abi), fix_name(platform)))
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Utility script to print the python tag + the abi tag for a Python # See PEP 425 for exactly what these are, but an example would be: # cp27-cp27mu from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag print("{0}{1}-{2}".format(get_abbr_impl(), get_impl_ver(), get_abi_tag()))
# Exports interpreter PEP425 tags for shell processing. import sys from distutils.util import get_platform from wheel.pep425tags import ( get_impl_ver, get_abi_tag, get_abbr_impl, ) sys.stdout.write("%s%s-%s %s\n" % ( get_abbr_impl(), get_impl_ver(), get_abi_tag(), get_platform().replace('-', '_'), ))
def expected_wheel_name(fmt): return fmt.format(get_abbr_impl() + get_impl_ver(), get_abi_tag())
def pep425tags_get_supported(versions=None, supplied_platform=None): """Return a list of supported tags for each version specified in `versions`. :param versions: a list of string versions, of the form ["33", "32"], or None. The first version will be assumed to support our ABI. """ supported = [] # Versions must be given with respect to the preference if versions is None: versions = [] version_info = get_impl_version_info() major = version_info[:-1] # Support all previous minor Python versions. for minor in range(version_info[-1], -1, -1): versions.append(''.join(map(str, major + (minor, )))) impl = get_abbr_impl() abis = [] abi = get_abi_tag() if abi: abis[0:0] = [abi] abi3s = set() import imp for suffix in imp.get_suffixes(): if suffix[0].startswith('.abi'): abi3s.add(suffix[0].split('.', 2)[1]) abis.extend(sorted(list(abi3s))) abis.append('none') platforms = get_platforms(supplied=supplied_platform) # Current version, current API (built specifically for our Python): for abi in abis: 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): supported.append(('%s%s' % (impl, version), 'none', 'any')) if i == 0: # Tagged specifically as being cross-version compatible # (with just the major version specified) supported.append(('%s%s' % (impl, versions[0][0]), 'none', 'any')) # Major Python version + platform; e.g. binaries not using the Python API for arch in platforms: supported.append(('py%s' % (versions[0][0]), 'none', arch)) # No abi / arch, generic Python for i, version in enumerate(versions): supported.append(('py%s' % (version, ), 'none', 'any')) if i == 0: supported.append(('py%s' % (version[0]), 'none', 'any')) return supported
from os.path import exists from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag()) # cuda_output = !ldconfig -p|grep cudart.so|sed -e 's/.*\.\([0-10]*\)\.\([0-10]*\)$/cu\1\2/' # accelerator = cuda_output[0] if exists('/dev/nvidia0') else 'cpu' with open('cuda-info.txt', 'w') as f: f.write('''platform:{} cuda_output:{} accelerator:{} '''.format(platform, None, None))
import shutil from wheel.pep425tags import get_abi_tag, get_platform os.environ["PYTHONDONTWRITEBYTECODE"] = "1" def run(cmd): print(cmd) try: subprocess.check_call(cmd) except subprocess.CalledProcessError as e: sys.exit(e.returncode) venv = "test-venv-{}-{}".format(get_abi_tag(), get_platform()) if not exists(venv): print("-- Creating venv in {} --".format(venv)) run([sys.executable, "-m", "virtualenv", "-p", sys.executable, venv]) python_candidates = [ join(venv, "bin", "python"), join(venv, "Scripts", "python.exe"), ] for python_candidate in python_candidates: if exists(python_candidate): python_exe = python_candidate break else: raise RuntimeError("I don't understand this platform's virtualenv layout")