Skip to content

Commit

Permalink
Cherry pick fixes from master (#416)
Browse files Browse the repository at this point in the history
* Update dummy eggs to hold the correct abi tag for Python 3.8 (#413)
* Pass the runtime version to from_epd_string (#414)
* Fix guess abi tag (#418)
* Fix legacy.guess_abi_tag to support python 3.8
* Fix _guess_abi_from_python to return the correct value on 3.8
* Fix okonomiyaki support for python 3.8 setuptools eggs
Make sure that python 3.8 setuptools eggs can be correctly parsed
into SetuptoolsEggMetadata
* Fix flake8 errors
  • Loading branch information
itziakos authored Jun 29, 2021
1 parent 7046f75 commit 1e844f5
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 90 deletions.
9 changes: 6 additions & 3 deletions okonomiyaki/file_formats/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ..errors import InvalidMetadataField
from ..platforms import PythonImplementation, default_abi

from ..versions import RuntimeVersion

# To parse the python field in our index and spec/depend
_PYVER_RE = re.compile(r"(?P<major>\d+)\.(?P<minor>\d+)")
Expand Down Expand Up @@ -35,8 +35,11 @@ def _guess_abi_tag(epd_platform, python_tag):
#
# In those cases, the mapping (platform pyver) -> ABI is unambiguous,
# as we only ever used one ABI for a given python version/platform.
pyver = _python_tag_to_python(python_tag)
return u"cp{0}{1}m".format(pyver[0], pyver[2])
pyver = RuntimeVersion.from_string(_python_tag_to_python(python_tag))
if pyver >= RuntimeVersion.from_string('3.8'):
return u"cp{0}{1}".format(pyver.major, pyver.minor)
else:
return u"cp{0}{1}m".format(pyver.major, pyver.minor)


def _guess_platform_abi(epd_platform, python_tag):
Expand Down
8 changes: 5 additions & 3 deletions okonomiyaki/file_formats/setuptools_egg.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def _guess_abi_from_python(python):
#
# In those cases, the mapping (platform pyver) -> ABI is unambiguous,
# as we only ever used one ABI for a given python version/platform.
return "cp{0}{1}m".format(python.major, python.minor)
if python.major >= 3 and python.minor >= 8:
# Python 3.8 has removed the `m` from the abi tag
return u"cp{0}{1}".format(python.major, python.minor)
else:
return u"cp{0}{1}m".format(python.major, python.minor)


def _guess_abi_from_running_python():
Expand All @@ -104,7 +108,6 @@ def _guess_abi_from_running_python():
def _guess_abi(platform, python):
if platform is None:
return None

if python is not None:
if (python.major, python.minor) != sys.version_info[:2]:
return _guess_abi_from_python(python)
Expand All @@ -128,7 +131,6 @@ def from_egg(cls, path, platform=None, python=_UNSPECIFIED,
abi_tag=_UNSPECIFIED):
filename = os.path.basename(path)
name, version, pyver, platform_string = parse_filename(filename)

if platform is None and platform_string is not None:
msg = ("Platform-specific egg detected: you need to specify a "
"platform argument that is not None to from_egg")
Expand Down
11 changes: 9 additions & 2 deletions okonomiyaki/file_formats/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from ... import repositories

DATA_DIR = os.path.join(os.path.dirname(repositories.__file__),
"tests", "data")
DATA_DIR = os.path.join(
os.path.dirname(repositories.__file__), "tests", "data")

ENSTALLER_EGG = os.path.join(DATA_DIR, "enstaller-4.5.0-1.egg")
ETS_EGG = os.path.join(DATA_DIR, "ets-4.3.0-3.egg")
Expand Down Expand Up @@ -477,6 +477,13 @@

PIP_SETUPTOOLS_EGG = os.path.join(DATA_DIR, "pip-7.0.3-py3.4.egg")

TRAITS_SETUPTOOLS_OSX_cp38_EGG = os.path.join(
DATA_DIR, "traits-6.3.0.dev1702-py3.8-macosx-10.14-x86_64.egg")
TRAITS_SETUPTOOLS_LINUX_cp38_EGG = os.path.join(
DATA_DIR, "traits-6.3.0.dev1702-py3.8-linux-x86_64.egg")
TRAITS_SETUPTOOLS_WIN_cp38_EGG = os.path.join(
DATA_DIR, "traits-6.3.0.dev1702-py3.8-win-amd64.egg")

FAKE_PYSIDE_1_1_0_EGG_PKG_INFO = u"""\
============
About PySide
Expand Down
248 changes: 174 additions & 74 deletions okonomiyaki/file_formats/tests/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,83 +10,83 @@

from okonomiyaki.platforms import EPDPlatform

from ..legacy import _guess_platform_abi

#: Known platforms that at some point have been uploaded into an EDS
#: server.
CONFIGURATIONS = {
('cp27', 'osx_x86'): 'darwin',
('cp27', 'osx_x86_64'): 'darwin',
('cp27', 'rh5_x86'): 'gnu',
('cp27', 'rh5_x86_64'): 'gnu',
('cp27', 'win_x86'): 'msvc2008',
('cp27', 'win_x86_64'): 'msvc2008',
('cp30', 'osx_x86'): 'darwin',
('cp30', 'osx_x86_64'): 'darwin',
('cp30', 'rh5_x86'): 'gnu',
('cp30', 'rh5_x86_64'): 'gnu',
('cp30', 'win_x86'): 'msvc2008',
('cp30', 'win_x86_64'): 'msvc2008',
('cp31', 'osx_x86'): 'darwin',
('cp31', 'osx_x86_64'): 'darwin',
('cp31', 'rh5_x86'): 'gnu',
('cp31', 'rh5_x86_64'): 'gnu',
('cp31', 'win_x86'): 'msvc2008',
('cp31', 'win_x86_64'): 'msvc2008',
('cp32', 'osx_x86'): 'darwin',
('cp32', 'osx_x86_64'): 'darwin',
('cp32', 'rh5_x86'): 'gnu',
('cp32', 'rh5_x86_64'): 'gnu',
('cp32', 'win_x86'): 'msvc2008',
('cp32', 'win_x86_64'): 'msvc2008',
('cp33', 'osx_x86'): 'darwin',
('cp33', 'osx_x86_64'): 'darwin',
('cp33', 'rh5_x86'): 'gnu',
('cp33', 'rh5_x86_64'): 'gnu',
('cp33', 'win_x86'): 'msvc2010',
('cp33', 'win_x86_64'): 'msvc2010',
('cp34', 'osx_x86'): 'darwin',
('cp34', 'osx_x86_64'): 'darwin',
('cp34', 'rh5_x86'): 'gnu',
('cp34', 'rh5_x86_64'): 'gnu',
('cp34', 'win_x86'): 'msvc2010',
('cp34', 'win_x86_64'): 'msvc2010',
('cp36', 'osx_x86'): 'darwin',
('cp36', 'osx_x86_64'): 'darwin',
('cp36', 'rh6_x86'): 'gnu',
('cp36', 'rh6_x86_64'): 'gnu',
('cp36', 'rh7_x86'): 'gnu',
('cp36', 'rh7_x86_64'): 'gnu',
('cp36', 'win_x86'): 'msvc2015',
('cp36', 'win_x86_64'): 'msvc2015',
('cp38', 'osx_x86'): 'darwin',
('cp38', 'osx_x86_64'): 'darwin',
('cp38', 'rh7_x86'): 'gnu',
('cp38', 'rh7_x86_64'): 'gnu',
('cp38', 'win_x86'): 'msvc2019',
('cp38', 'win_x86_64'): 'msvc2019',
('ip27', 'osx_x86'): 'darwin',
('ip27', 'osx_x86_64'): 'darwin',
('ip27', 'rh5_x86'): 'gnu',
('ip27', 'rh5_x86_64'): 'gnu',
('ip27', 'win_x86'): 'msvc2008',
('ip27', 'win_x86_64'): 'msvc2008',
('jy27', 'osx_x86'): 'darwin',
('jy27', 'osx_x86_64'): 'darwin',
('jy27', 'rh5_x86'): 'gnu',
('jy27', 'rh5_x86_64'): 'gnu',
('jy27', 'win_x86'): 'msvc2008',
('jy27', 'win_x86_64'): 'msvc2008',
('pp27', 'osx_x86'): 'darwin',
('pp27', 'osx_x86_64'): 'darwin',
('pp27', 'rh5_x86'): 'gnu',
('pp27', 'rh5_x86_64'): 'gnu',
('pp27', 'win_x86'): 'msvc2008',
('pp27', 'win_x86_64'): 'msvc2008'}
from ..legacy import _guess_platform_abi, _guess_abi_tag


class TestGuessPlatformABI(unittest.TestCase):

#: Known platforms that at some point have been uploaded into an EDS
#: server.
CONFIGURATIONS = {
('cp27', 'osx_x86'): 'darwin',
('cp27', 'osx_x86_64'): 'darwin',
('cp27', 'rh5_x86'): 'gnu',
('cp27', 'rh5_x86_64'): 'gnu',
('cp27', 'win_x86'): 'msvc2008',
('cp27', 'win_x86_64'): 'msvc2008',
('cp30', 'osx_x86'): 'darwin',
('cp30', 'osx_x86_64'): 'darwin',
('cp30', 'rh5_x86'): 'gnu',
('cp30', 'rh5_x86_64'): 'gnu',
('cp30', 'win_x86'): 'msvc2008',
('cp30', 'win_x86_64'): 'msvc2008',
('cp31', 'osx_x86'): 'darwin',
('cp31', 'osx_x86_64'): 'darwin',
('cp31', 'rh5_x86'): 'gnu',
('cp31', 'rh5_x86_64'): 'gnu',
('cp31', 'win_x86'): 'msvc2008',
('cp31', 'win_x86_64'): 'msvc2008',
('cp32', 'osx_x86'): 'darwin',
('cp32', 'osx_x86_64'): 'darwin',
('cp32', 'rh5_x86'): 'gnu',
('cp32', 'rh5_x86_64'): 'gnu',
('cp32', 'win_x86'): 'msvc2008',
('cp32', 'win_x86_64'): 'msvc2008',
('cp33', 'osx_x86'): 'darwin',
('cp33', 'osx_x86_64'): 'darwin',
('cp33', 'rh5_x86'): 'gnu',
('cp33', 'rh5_x86_64'): 'gnu',
('cp33', 'win_x86'): 'msvc2010',
('cp33', 'win_x86_64'): 'msvc2010',
('cp34', 'osx_x86'): 'darwin',
('cp34', 'osx_x86_64'): 'darwin',
('cp34', 'rh5_x86'): 'gnu',
('cp34', 'rh5_x86_64'): 'gnu',
('cp34', 'win_x86'): 'msvc2010',
('cp34', 'win_x86_64'): 'msvc2010',
('cp36', 'osx_x86'): 'darwin',
('cp36', 'osx_x86_64'): 'darwin',
('cp36', 'rh6_x86'): 'gnu',
('cp36', 'rh6_x86_64'): 'gnu',
('cp36', 'rh7_x86'): 'gnu',
('cp36', 'rh7_x86_64'): 'gnu',
('cp36', 'win_x86'): 'msvc2015',
('cp36', 'win_x86_64'): 'msvc2015',
('cp38', 'osx_x86'): 'darwin',
('cp38', 'osx_x86_64'): 'darwin',
('cp38', 'rh7_x86'): 'gnu',
('cp38', 'rh7_x86_64'): 'gnu',
('cp38', 'win_x86'): 'msvc2019',
('cp38', 'win_x86_64'): 'msvc2019',
('ip27', 'osx_x86'): 'darwin',
('ip27', 'osx_x86_64'): 'darwin',
('ip27', 'rh5_x86'): 'gnu',
('ip27', 'rh5_x86_64'): 'gnu',
('ip27', 'win_x86'): 'msvc2008',
('ip27', 'win_x86_64'): 'msvc2008',
('jy27', 'osx_x86'): 'darwin',
('jy27', 'osx_x86_64'): 'darwin',
('jy27', 'rh5_x86'): 'gnu',
('jy27', 'rh5_x86_64'): 'gnu',
('jy27', 'win_x86'): 'msvc2008',
('jy27', 'win_x86_64'): 'msvc2008',
('pp27', 'osx_x86'): 'darwin',
('pp27', 'osx_x86_64'): 'darwin',
('pp27', 'rh5_x86'): 'gnu',
('pp27', 'rh5_x86_64'): 'gnu',
('pp27', 'win_x86'): 'msvc2008',
('pp27', 'win_x86_64'): 'msvc2008'}

@given(sampled_from(sorted(CONFIGURATIONS)))
def test_known_cases(self, configuration):
# given
Expand All @@ -96,7 +96,7 @@ def test_known_cases(self, configuration):
result = _guess_platform_abi(epd_platform, configuration[0])

# then
expected = CONFIGURATIONS[configuration]
expected = self.CONFIGURATIONS[configuration]
self.assertEqual(
result, expected,
msg="{} gives {} instead of {}".format(
Expand Down Expand Up @@ -149,3 +149,103 @@ def test_no_python_implementation(self):

# Then
self.assertEqual(abi, "msvc2008")


class TestGuessABITag(unittest.TestCase):

#: Known platforms that at some point have been uploaded into an EDS
#: server. Note that only cpython and pypy implementations are
#: supported
CONFIGURATIONS = {
('cp27', 'osx_x86'): 'cp27m',
('cp27', 'osx_x86_64'): 'cp27m',
('cp27', 'rh5_x86'): 'cp27m',
('cp27', 'rh5_x86_64'): 'cp27m',
('cp27', 'win_x86'): 'cp27m',
('cp27', 'win_x86_64'): 'cp27m',
('cp30', 'osx_x86'): 'cp30m',
('cp30', 'osx_x86_64'): 'cp30m',
('cp30', 'rh5_x86'): 'cp30m',
('cp30', 'rh5_x86_64'): 'cp30m',
('cp30', 'win_x86'): 'cp30m',
('cp30', 'win_x86_64'): 'cp30m',
('cp31', 'osx_x86'): 'cp31m',
('cp31', 'osx_x86_64'): 'cp31m',
('cp31', 'rh5_x86'): 'cp31m',
('cp31', 'rh5_x86_64'): 'cp31m',
('cp31', 'win_x86'): 'cp31m',
('cp31', 'win_x86_64'): 'cp31m',
('cp32', 'osx_x86'): 'cp32m',
('cp32', 'osx_x86_64'): 'cp32m',
('cp32', 'rh5_x86'): 'cp32m',
('cp32', 'rh5_x86_64'): 'cp32m',
('cp32', 'win_x86'): 'cp32m',
('cp32', 'win_x86_64'): 'cp32m',
('cp33', 'osx_x86'): 'cp33m',
('cp33', 'osx_x86_64'): 'cp33m',
('cp33', 'rh5_x86'): 'cp33m',
('cp33', 'rh5_x86_64'): 'cp33m',
('cp33', 'win_x86'): 'cp33m',
('cp33', 'win_x86_64'): 'cp33m',
('cp34', 'osx_x86'): 'cp34m',
('cp34', 'osx_x86_64'): 'cp34m',
('cp34', 'rh5_x86'): 'cp34m',
('cp34', 'rh5_x86_64'): 'cp34m',
('cp34', 'win_x86'): 'cp34m',
('cp34', 'win_x86_64'): 'cp34m',
('cp36', 'osx_x86'): 'cp36m',
('cp36', 'osx_x86_64'): 'cp36m',
('cp36', 'rh6_x86'): 'cp36m',
('cp36', 'rh6_x86_64'): 'cp36m',
('cp36', 'rh7_x86'): 'cp36m',
('cp36', 'rh7_x86_64'): 'cp36m',
('cp36', 'win_x86'): 'cp36m',
('cp36', 'win_x86_64'): 'cp36m',
('cp38', 'osx_x86'): 'cp38',
('cp38', 'osx_x86_64'): 'cp38',
('cp38', 'rh7_x86'): 'cp38',
('cp38', 'rh7_x86_64'): 'cp38',
('cp38', 'win_x86'): 'cp38',
('cp38', 'win_x86_64'): 'cp38',
('pp27', 'osx_x86'): 'cp27m',
('pp27', 'osx_x86_64'): 'cp27m',
('pp27', 'rh5_x86'): 'cp27m',
('pp27', 'rh5_x86_64'): 'cp27m',
('pp27', 'win_x86'): 'cp27m',
('pp27', 'win_x86_64'): 'cp27m'}

@given(sampled_from(sorted(CONFIGURATIONS)))
def test_known_cases(self, configuration):
# given
epd_platform = EPDPlatform.from_string(configuration[1])

# when
result = _guess_abi_tag(epd_platform, configuration[0])

# then
expected = self.CONFIGURATIONS[configuration]
self.assertEqual(
result, expected,
msg="{} gives {} instead of {}".format(
configuration, result, expected))

@given(sampled_from(
['cp27', 'cp30', 'cp31', 'cp34', 'cp36', 'cp38']))
def test_no_platform(self, python_tag):
# When
abi = _guess_abi_tag(None, python_tag)

# Then
self.assertIsNone(abi)

@given(sampled_from(
['rh5-64', 'rh6-64', 'rh7-64', 'win-32', 'win-64', 'osx-64']))
def test_no_python_implementation(self, platform_tag):
# Given
platform = EPDPlatform.from_epd_string(platform_tag)

# When
abi = _guess_abi_tag(platform, None)

# Then
self.assertIsNone(abi)
Loading

0 comments on commit 1e844f5

Please sign in to comment.