~ubuntu-branches/debian/jessie/python-pip/jessie

« back to all changes in this revision

Viewing changes to pip/pep425tags.py

  • Committer: Package Import Robot
  • Author(s): Barry Warsaw
  • Date: 2013-08-19 18:33:23 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20130819183323-8xyoldb2798iil6e
Tags: 1.4.1-1
* Team upload.
* New upstream release.
  - d/control: Update Standards-Version to 3.9.4 with no additional
    changes required.
  - d/patches/no-python-specific-scripts.patch: Refreshed.
  - d/patches/format_egg_string.patch: Refreshed.
  - d/patches/system-ca-certificates.patch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""Generate and work with PEP 425 Compatibility Tags."""
 
2
 
 
3
import sys
 
4
import warnings
 
5
 
 
6
try:
 
7
    import sysconfig
 
8
except ImportError:  # pragma nocover
 
9
    # Python < 2.7
 
10
    import distutils.sysconfig as sysconfig
 
11
import distutils.util
 
12
 
 
13
 
 
14
def get_abbr_impl():
 
15
    """Return abbreviated implementation name."""
 
16
    if hasattr(sys, 'pypy_version_info'):
 
17
        pyimpl = 'pp'
 
18
    elif sys.platform.startswith('java'):
 
19
        pyimpl = 'jy'
 
20
    elif sys.platform == 'cli':
 
21
        pyimpl = 'ip'
 
22
    else:
 
23
        pyimpl = 'cp'
 
24
    return pyimpl
 
25
 
 
26
 
 
27
def get_impl_ver():
 
28
    """Return implementation version."""
 
29
    return ''.join(map(str, sys.version_info[:2]))
 
30
 
 
31
 
 
32
def get_platform():
 
33
    """Return our platform name 'win32', 'linux_x86_64'"""
 
34
    # XXX remove distutils dependency
 
35
    return distutils.util.get_platform().replace('.', '_').replace('-', '_')
 
36
 
 
37
 
 
38
def get_supported(versions=None, noarch=False):
 
39
    """Return a list of supported tags for each version specified in
 
40
    `versions`.
 
41
 
 
42
    :param versions: a list of string versions, of the form ["33", "32"],
 
43
        or None. The first version will be assumed to support our ABI.
 
44
    """
 
45
    supported = []
 
46
 
 
47
    # Versions must be given with respect to the preference
 
48
    if versions is None:
 
49
        versions = []
 
50
        major = sys.version_info[0]
 
51
        # Support all previous minor Python versions.
 
52
        for minor in range(sys.version_info[1], -1, -1):
 
53
            versions.append(''.join(map(str, (major, minor))))
 
54
 
 
55
    impl = get_abbr_impl()
 
56
 
 
57
    abis = []
 
58
 
 
59
    try:
 
60
        soabi = sysconfig.get_config_var('SOABI')
 
61
    except IOError as e: # Issue #1074
 
62
        warnings.warn("{0}".format(e), RuntimeWarning)
 
63
        soabi = None
 
64
 
 
65
    if soabi and soabi.startswith('cpython-'):
 
66
        abis[0:0] = ['cp' + soabi.split('-', 1)[-1]]
 
67
 
 
68
    abi3s = set()
 
69
    import imp
 
70
    for suffix in imp.get_suffixes():
 
71
        if suffix[0].startswith('.abi'):
 
72
            abi3s.add(suffix[0].split('.', 2)[1])
 
73
 
 
74
    abis.extend(sorted(list(abi3s)))
 
75
 
 
76
    abis.append('none')
 
77
 
 
78
    if not noarch:
 
79
        arch = get_platform()
 
80
 
 
81
        # Current version, current API (built specifically for our Python):
 
82
        for abi in abis:
 
83
            supported.append(('%s%s' % (impl, versions[0]), abi, arch))
 
84
 
 
85
    # No abi / arch, but requires our implementation:
 
86
    for i, version in enumerate(versions):
 
87
        supported.append(('%s%s' % (impl, version), 'none', 'any'))
 
88
        if i == 0:
 
89
            # Tagged specifically as being cross-version compatible
 
90
            # (with just the major version specified)
 
91
            supported.append(('%s%s' % (impl, versions[0][0]), 'none', 'any'))
 
92
 
 
93
    # No abi / arch, generic Python
 
94
    for i, version in enumerate(versions):
 
95
        supported.append(('py%s' % (version,), 'none', 'any'))
 
96
        if i == 0:
 
97
            supported.append(('py%s' % (version[0]), 'none', 'any'))
 
98
 
 
99
    return supported
 
100
 
 
101
supported_tags = get_supported()
 
102
supported_tags_noarch = get_supported(noarch=True)