Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
26d4fcd
redo PR and force push
aixtools Nov 29, 2019
730016e
modify import to work better with monkeypatch in tests
aixtools Nov 29, 2019
ce9e721
Add extra monkeypatch setting
aixtools Nov 29, 2019
89a7b23
More changes to get past Windows CI tests...
aixtools Nov 29, 2019
e3ce54e
CI module `black` says double quotes `"` needed
aixtools Nov 29, 2019
b46efe0
Changes made in accordance of peer review of CPyhton PR #17303
aixtools Dec 8, 2019
ac25b81
Specify `#pragma no cover` for Windows - that does not have os.uname()
aixtools Dec 8, 2019
9c999bb
Remove "too many spaces" in pragma (comment)
aixtools Dec 8, 2019
f06f81a
Non-posix systems (i.e., no `os.uname()`) fail coverage tests, use co…
aixtools Dec 8, 2019
c8d5d79
Sync code with CPython 3.9: `Lib/_aix_support.py`
aixtools Dec 17, 2019
8677561
typo corrections to pass lint
aixtools Dec 17, 2019
1dc7248
Merge branch 'master' into AIX-platform-tag
di Jan 2, 2020
5c9166b
Merge branch 'master' into AIX-platform-tag
aixtools Feb 3, 2020
2f9fc76
Merge branch 'master' into AIX-platform-tag
aixtools Mar 17, 2020
f9019b2
rename _AIX_platform to _aix_support - same as in CPython
aixtools Apr 3, 2020
5572136
Merge branch 'master' into AIX-platform-tag
aixtools Apr 3, 2020
91412e8
Sync _aix_support.py with CPython `Lib/_aix_support.py`
aixtools Apr 3, 2020
81ebe3c
Fix file to pass flake8 tests
aixtools Apr 3, 2020
27ebbb1
import subprocess no longer needed to support monkeypatch
aixtools Apr 3, 2020
cf52688
Shorten variable names to pass flake8 line-length tests
aixtools Apr 20, 2020
68e9c80
Add a NewType for normalized names (#292)
pradyunsg Apr 8, 2020
880edc3
Merge branch 'master' into AIX-platform-tag
aixtools Apr 20, 2020
48dab36
typo
aixtools Apr 20, 2020
5088c8c
Merge branch 'master' into AIX-platform-tag by removing the conflicts
aixtools Nov 1, 2020
ae6ee5f
Restored the lines removed - in order to restart work.
aixtools Nov 1, 2020
56aee30
Fix paste error; add a new-line
aixtools Nov 3, 2020
c9544b6
Fix blank line with spaces
aixtools Nov 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
redo PR and force push
  • Loading branch information
aixtools committed Nov 29, 2019
commit 26d4fcd526c33eda99303cfeae3f00463382f74a
96 changes: 96 additions & 0 deletions packaging/_AIX_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""Shared AIX support functions."""

import sys
from sysconfig import get_config_var

# subprocess is not available early in the build process, test this
try:
from subprocess import check_output

_subprocess_rdy = True
except ImportError: # pragma: no cover
_subprocess_rdy = False

from ._typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING: # pragma: no cover
from typing import List, Tuple


# if var("AIX_BUILDDATE") is unknown, provide a substitute,
# impossible builddate to specify 'unknown'
_tmp = str(get_config_var("AIX_BUILDDATE"))
_bd = 9898 if (_tmp == "None") else int(_tmp)
_bgt = get_config_var("BUILD_GNU_TYPE")
_sz = 32 if sys.maxsize == 2147483647 else 64


def _aix_tag(v, bd):
# type: (List[int], int) -> str
# v is used as variable name so line below passes pep8 length test
# v[version, release, technology_level]
return "AIX-{:1x}{:1d}{:02d}-{:04d}-{}".format(v[0], v[1], v[2], bd, _sz)


# extract version, release and technology level from a VRMF string
def _aix_vrtl(vrmf):
# type: (str) -> List[int]
v, r, tl = vrmf.split(".")[:3]
return [int(v[-1]), int(r), int(tl)]


def _aix_bosmp64():
# type: () -> Tuple[str, int]
"""
Return a Tuple[str, int] e.g., ['7.1.4.34', 1806]
The fileset bos.mp64 is the AIX kernel. It's VRMF and builddate
reflect the current ABI levels of the runtime environment.
"""
if _subprocess_rdy:
out = check_output(["/usr/bin/lslpp", "-Lqc", "bos.mp64"])
out = out.decode("utf-8").strip().split(":") # type: ignore
# Use str() and int() to help mypy see types
return str(out[2]), int(out[-1])
else:
from os import uname

osname, host, release, version, machine = uname()
return "{}.{}.0.0".format(version, release), 9898


def aix_platform():
# type: () -> str
"""
AIX filesets are identified by four decimal values: V.R.M.F.
V (version) and R (release) can be retreived using ``uname``
Since 2007, starting with AIX 5.3 TL7, the M value has been
included with the fileset bos.mp64 and represents the Technology
Level (TL) of AIX. The F (Fix) value also increases, but is not
relevant for comparing releases and binary compatibility.
For binary compatibility the so-called builddate is needed.
Again, the builddate of an AIX release is associated with bos.mp64.
AIX ABI compatibility is described as guaranteed at: https://www.ibm.com/\
support/knowledgecenter/en/ssw_aix_72/install/binary_compatability.html

For pep425 purposes the AIX platform tag becomes:
"AIX-{:1x}{:1d}{:02d}-{:04d}-{}".format(v, r, tl, builddate, bitsize)
e.g., "AIX-6107-1415-32" for AIX 6.1 TL7 bd 1415, 32-bit
and, "AIX-6107-1415-64" for AIX 6.1 TL7 bd 1415, 64-bit
"""
vrmf, bd = _aix_bosmp64()
return _aix_tag(_aix_vrtl(vrmf), bd)


# extract vrtl from the BUILD_GNU_TYPE as an int
def _aix_bgt():
# type: () -> List[int]
assert _bgt
return _aix_vrtl(vrmf=_bgt)


def aix_buildtag():
# type: () -> str
"""
Return the platform_tag of the system Python was built on.
"""
return _aix_tag(_aix_bgt(), _bd)
12 changes: 12 additions & 0 deletions packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import warnings

from ._typing import MYPY_CHECK_RUNNING, cast
from ._AIX_platform import aix_platform

if MYPY_CHECK_RUNNING: # pragma: no cover
from typing import (
Expand Down Expand Up @@ -526,6 +527,15 @@ def _linux_platforms(is_32bit=_32_BIT_INTERPRETER):
yield linux


def _aix_platforms():
# type: () -> Iterator[str]
# Call support module if CPython returns old tag
platform = distutils.util.get_platform()
if platform[:3] == "aix":
platform = aix_platform()
yield platform


def _generic_platforms():
# type: () -> Iterator[str]
yield _normalize_string(distutils.util.get_platform())
Expand All @@ -540,6 +550,8 @@ def _platform_tags():
return mac_platforms()
elif platform.system() == "Linux":
return _linux_platforms()
elif platform.system() == "AIX":
return _aix_platforms()
else:
return _generic_platforms()

Expand Down
91 changes: 90 additions & 1 deletion tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import platform
import re
import subprocess
import sys
import sysconfig
import types
Expand All @@ -24,7 +25,7 @@
import pretend
import pytest

from packaging import tags
from packaging import tags, _AIX_platform


@pytest.fixture
Expand Down Expand Up @@ -839,3 +840,91 @@ def test_generic(self, monkeypatch):
result = list(tags.sys_tags())
expected = tags.Tag("py{}0".format(sys.version_info[0]), "none", "any")
assert result[-1] == expected


def test_aix_platform_notpep425_ready(monkeypatch):
if platform.system() != "AIX":
monkeypatch.setattr(
subprocess,
"check_output",
lambda *a: b"bos.mp64:bos.mp64:5.3.7.0:::C::BOS 64-bit:::::::1:0:/:0747\n",
)
monkeypatch.setattr(distutils.util, "get_platform", lambda: "aix_5_3")
monkeypatch.setattr(_AIX_platform, "_sz", 64)
result0 = list(tags._aix_platforms())
result1 = [_AIX_platform.aix_platform()]
assert result0 == result1
assert result0[0].startswith("AIX")
assert result0[0].endswith("64")


def test_aix_platform_no_subprocess(monkeypatch):
monkeypatch.setattr(_AIX_platform, "_subprocess_rdy", False)
vrmf, bd = _AIX_platform._aix_bosmp64()
assert vrmf
assert bd == 9898


def test_aix_platform_pep425_ready(monkeypatch):
monkeypatch.setattr(
subprocess,
"check_output",
lambda *a: b"bos.mp64:bos.mp64:5.3.7.0:::C::BOS 64-bit:::::::1:0:/:0747\n",
)
monkeypatch.setattr(distutils.util, "get_platform", lambda: "AIX-5307-0747-32")
monkeypatch.setattr(_AIX_platform, "_sz", 32)
result0 = list(tags._aix_platforms())
result1 = [_AIX_platform.aix_platform()]
assert result0[0][:4] == result1[0][:4]
assert result0[0].startswith("AIX")
assert result0[0].endswith("32")


def test_sys_tags_aix64_cpython(mock_interpreter_name, monkeypatch):
if mock_interpreter_name("CPython"):
monkeypatch.setattr(tags, "_cpython_abis", lambda *a: ["cp36m"])
if platform.system() != "xAIX":
monkeypatch.setattr(platform, "system", lambda: "AIX")
monkeypatch.setattr(tags, "_aix_platforms", lambda: ["AIX_5307_0747_64"])
abis = tags._cpython_abis(sys.version_info[:2])
platforms = tags._aix_platforms()
result = list(tags.sys_tags())
expected_interpreter = "cp{major}{minor}".format(
major=sys.version_info[0], minor=sys.version_info[1]
)
assert len(abis) == 1
assert result[0] == tags.Tag(expected_interpreter, abis[0], platforms[0])
expected = tags.Tag("py{}0".format(sys.version_info[0]), "none", "any")
assert result[-1] == expected


def test_sys_tags_aix32_cpython(mock_interpreter_name, monkeypatch):
if mock_interpreter_name("CPython"):
monkeypatch.setattr(tags, "_cpython_abis", lambda *a: ["cp36m"])
if platform.system() != "AIX":
monkeypatch.setattr(platform, "system", lambda: "AIX")
monkeypatch.setattr(tags, "_aix_platforms", lambda: ["AIX_5307_0747_32"])
abis = tags._cpython_abis(sys.version_info[:2])
platforms = tags._aix_platforms()
result = list(tags.sys_tags())
expected_interpreter = "cp{major}{minor}".format(
major=sys.version_info[0], minor=sys.version_info[1]
)
assert len(abis) == 1
assert result[0] == tags.Tag(expected_interpreter, abis[0], platforms[0])
expected = tags.Tag("py{}0".format(sys.version_info[0]), "none", "any")
assert result[-1] == expected


def test_aix_buildtag(monkeypatch):
monkeypatch.setattr(_AIX_platform, "_bgt", "powerpc-ibm-aix5.3.7.0")
assert _AIX_platform._bd == 9898
monkeypatch.setattr(_AIX_platform, "_bd", 9797)
monkeypatch.setattr(_AIX_platform, "_sz", 64)
assert _AIX_platform._bd == 9797
result = _AIX_platform.aix_buildtag()
assert result == "AIX-5307-9797-64"
monkeypatch.setattr(_AIX_platform, "_bd", 747)
monkeypatch.setattr(_AIX_platform, "_sz", 32)
result = _AIX_platform.aix_buildtag()
assert result == "AIX-5307-0747-32"