Commit e398b04c by Sébastien Eustace

Fix wheels not getting information from the virtualenv

parent 8d84573f
# Change Log # Change Log
[Unreleased]
### Fixed
- Fixed built wheels not getting information from the virtualenv.
[0.6.2] - 2018-03-19 [0.6.2] - 2018-03-19
### Changed ### Changed
......
...@@ -11,7 +11,6 @@ from pprint import pformat ...@@ -11,7 +11,6 @@ from pprint import pformat
from typing import List from typing import List
from poetry.packages import Dependency from poetry.packages import Dependency
from poetry.version.helpers import format_python_constraint
from ..utils.helpers import normalize_file_permissions from ..utils.helpers import normalize_file_permissions
...@@ -19,6 +18,7 @@ from .builder import Builder ...@@ -19,6 +18,7 @@ from .builder import Builder
SETUP = """\ SETUP = """\
# -*- coding: utf-8 -*-
from distutils.core import setup from distutils.core import setup
{before} {before}
......
...@@ -203,10 +203,10 @@ class WheelBuilder(Builder): ...@@ -203,10 +203,10 @@ class WheelBuilder(Builder):
def tag(self): def tag(self):
if self._package.build: if self._package.build:
platform = get_platform().replace('.', '_').replace('-', '_') platform = get_platform().replace('.', '_').replace('-', '_')
impl_name = get_abbr_impl() impl_name = get_abbr_impl(self._venv)
impl_ver = get_impl_ver() impl_ver = get_impl_ver(self._venv)
impl = impl_name + impl_ver impl = impl_name + impl_ver
abi_tag = str(get_abi_tag()).lower() abi_tag = str(get_abi_tag(self._venv)).lower()
tag = (impl, abi_tag, platform) tag = (impl, abi_tag, platform)
else: else:
platform = 'any' platform = 'any'
......
"""Generate and work with PEP 425 Compatibility Tags.""" """Generate and work with PEP 425 Compatibility Tags."""
import distutils.util import distutils.util
import platform
import sys import sys
import sysconfig
import warnings import warnings
def get_config_var(var): def get_abbr_impl(venv):
try:
return sysconfig.get_config_var(var)
except IOError as e:
warnings.warn("{0}".format(e), RuntimeWarning)
return None
def get_abbr_impl():
"""Return abbreviated implementation name.""" """Return abbreviated implementation name."""
impl = platform.python_implementation() impl = venv.python_implementation
if impl == 'PyPy': if impl == 'PyPy':
return 'pp' return 'pp'
elif impl == 'Jython': elif impl == 'Jython':
...@@ -30,29 +21,29 @@ def get_abbr_impl(): ...@@ -30,29 +21,29 @@ def get_abbr_impl():
raise LookupError('Unknown Python implementation: ' + impl) raise LookupError('Unknown Python implementation: ' + impl)
def get_impl_ver(): def get_impl_ver(venv):
"""Return implementation version.""" """Return implementation version."""
impl_ver = get_config_var("py_version_nodot") impl_ver = venv.config_var("py_version_nodot")
if not impl_ver or get_abbr_impl() == 'pp': if not impl_ver or get_abbr_impl(venv) == 'pp':
impl_ver = ''.join(map(str, get_impl_version_info())) impl_ver = ''.join(map(str, get_impl_version_info(venv)))
return impl_ver return impl_ver
def get_impl_version_info(): def get_impl_version_info(venv):
"""Return sys.version_info-like tuple for use in decrementing the minor """Return sys.version_info-like tuple for use in decrementing the minor
version.""" version."""
if get_abbr_impl() == 'pp': if get_abbr_impl(venv) == 'pp':
# as per https://github.com/pypa/pip/issues/2882 # as per https://github.com/pypa/pip/issues/2882
return (sys.version_info[0], sys.pypy_version_info.major, return venv.version_info[:3]
sys.pypy_version_info.minor)
else: else:
return sys.version_info[0], sys.version_info[1] return venv.version_info[:2]
def get_flag(var, fallback, expected=True, warn=True): def get_flag(venv, var, fallback, expected=True, warn=True):
"""Use a fallback method for determining SOABI flags if the needed config """Use a fallback method for determining SOABI flags if the needed config
var is unset or unavailable.""" var is unset or unavailable."""
val = get_config_var(var) val = venv.config_var(var)
if val is None: if val is None:
if warn: if warn:
warnings.warn("Config variable '{0}' is unset, Python ABI tag may " warnings.warn("Config variable '{0}' is unset, Python ABI tag may "
...@@ -61,31 +52,34 @@ def get_flag(var, fallback, expected=True, warn=True): ...@@ -61,31 +52,34 @@ def get_flag(var, fallback, expected=True, warn=True):
return val == expected return val == expected
def get_abi_tag(): def get_abi_tag(venv):
"""Return the ABI tag based on SOABI (if available) or emulate SOABI """Return the ABI tag based on SOABI (if available) or emulate SOABI
(CPython 2, PyPy).""" (CPython 2, PyPy)."""
soabi = get_config_var('SOABI') soabi = venv.config_var('SOABI')
impl = get_abbr_impl() impl = get_abbr_impl(venv)
if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'): if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'):
d = '' d = ''
m = '' m = ''
u = '' u = ''
if get_flag('Py_DEBUG', if get_flag(venv,
'Py_DEBUG',
lambda: hasattr(sys, 'gettotalrefcount'), lambda: hasattr(sys, 'gettotalrefcount'),
warn=(impl == 'cp')): warn=(impl == 'cp')):
d = 'd' d = 'd'
if get_flag('WITH_PYMALLOC', if get_flag(venv,
'WITH_PYMALLOC',
lambda: impl == 'cp', lambda: impl == 'cp',
warn=(impl == 'cp')): warn=(impl == 'cp')):
m = 'm' m = 'm'
if get_flag('Py_UNICODE_SIZE', if get_flag(venv,
'Py_UNICODE_SIZE',
lambda: sys.maxunicode == 0x10ffff, lambda: sys.maxunicode == 0x10ffff,
expected=4, expected=4,
warn=(impl == 'cp' and warn=(impl == 'cp' and
sys.version_info < (3, 3))) \ venv.version_info < (3, 3))) \
and sys.version_info < (3, 3): and venv.version_info < (3, 3):
u = 'u' u = 'u'
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u) abi = '%s%s%s%s%s' % (impl, get_impl_ver(venv), d, m, u)
elif soabi and soabi.startswith('cpython-'): elif soabi and soabi.startswith('cpython-'):
abi = 'cp' + soabi.split('-')[1] abi = 'cp' + soabi.split('-')[1]
elif soabi: elif soabi:
...@@ -105,7 +99,7 @@ def get_platform(): ...@@ -105,7 +99,7 @@ def get_platform():
return result return result
def get_supported(versions=None, supplied_platform=None): def get_supported(venv, versions=None, supplied_platform=None):
"""Return a list of supported tags for each version specified in """Return a list of supported tags for each version specified in
`versions`. `versions`.
:param versions: a list of string versions, of the form ["33", "32"], :param versions: a list of string versions, of the form ["33", "32"],
...@@ -116,17 +110,17 @@ def get_supported(versions=None, supplied_platform=None): ...@@ -116,17 +110,17 @@ def get_supported(versions=None, supplied_platform=None):
# Versions must be given with respect to the preference # Versions must be given with respect to the preference
if versions is None: if versions is None:
versions = [] versions = []
version_info = get_impl_version_info() version_info = get_impl_version_info(venv)
major = version_info[:-1] major = version_info[:-1]
# Support all previous minor Python versions. # Support all previous minor Python versions.
for minor in range(version_info[-1], -1, -1): for minor in range(version_info[-1], -1, -1):
versions.append(''.join(map(str, major + (minor,)))) versions.append(''.join(map(str, major + (minor,))))
impl = get_abbr_impl() impl = get_abbr_impl(venv)
abis = [] abis = []
abi = get_abi_tag() abi = get_abi_tag(venv)
if abi: if abi:
abis[0:0] = [abi] abis[0:0] = [abi]
......
import os import os
import platform
import subprocess import subprocess
import sys import sys
import sysconfig
import warnings
from contextlib import contextmanager from contextlib import contextmanager
from pathlib import Path from pathlib import Path
...@@ -39,6 +42,7 @@ class Venv: ...@@ -39,6 +42,7 @@ class Venv:
self._bin_dir = self._venv / bin_dir self._bin_dir = self._venv / bin_dir
self._version_info = None self._version_info = None
self._python_implementation = None
@classmethod @classmethod
def create(cls, io, name=None) -> 'Venv': def create(cls, io, name=None) -> 'Venv':
...@@ -123,27 +127,78 @@ class Venv: ...@@ -123,27 +127,78 @@ class Venv:
return self._bin('pip') return self._bin('pip')
@property @property
def version_info(self): def version_info(self) -> tuple:
if self._version_info is not None: if self._version_info is not None:
return self._version_info return self._version_info
if not self.is_venv(): if not self.is_venv():
self._version_info = sys.version_info self._version_info = sys.version_info
else: else:
output = self.run('python', '--version') output = self.run('python', '--version', shell=True)
version = output.split(' ') version = output.split(' ')
self._version_info = version[1].strip().split('.') self._version_info = tuple([
int(s) for s in version[1].strip().split('.')
])
return self._version_info return self._version_info
@property
def python_implementation(self):
if self._python_implementation is not None:
return self._python_implementation
if not self.is_venv():
impl = platform.python_implementation()
else:
impl = self.run(
'python', '-c',
'"import platform; print(platform.python_implementation())"',
shell=True
).strip()
self._python_implementation = impl
return self._python_implementation
def config_var(self, var):
if not self.is_venv():
try:
return sysconfig.get_config_var(var)
except IOError as e:
warnings.warn("{0}".format(e), RuntimeWarning)
return None
try:
value = self.run(
'python', '-c',
f'"import sysconfig; print(sysconfig.get_config_var(\'{var}\'))"',
shell=True
).strip()
except VenvCommandError as e:
warnings.warn("{0}".format(e), RuntimeWarning)
return None
if value == 'None':
value = None
elif value == '1':
value = 1
elif value == '0':
value = 0
return value
def run(self, bin: str, *args, **kwargs) -> str: def run(self, bin: str, *args, **kwargs) -> str:
""" """
Run a command inside the virtual env. Run a command inside the virtual env.
""" """
cmd = [self._bin(bin)] + list(args) cmd = [self._bin(bin)] + list(args)
shell = kwargs.get('shell', False)
try: try:
if shell:
cmd = ' '.join(cmd)
output = subprocess.check_output( output = subprocess.check_output(
cmd, stderr=subprocess.STDOUT, cmd, stderr=subprocess.STDOUT,
**kwargs **kwargs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment