File: pythondetector

package info (click to toggle)
gst-python1.0 1.14.4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,804 kB
  • sloc: sh: 4,822; python: 1,460; perl: 1,431; ansic: 835; makefile: 205
file content (84 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python3
import os
import platform
import subprocess
import sys

from distutils import sysconfig


try:
    sys.path.remove(os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                                 '..')))
except ValueError:
    pass

def get_python_abiflags():
    return sysconfig.get_config_var("ABIFLAGS")

def get_python_libloc():
    # OSX is a pain. Python as shipped by apple installs libpython in /usr/lib
    # so we hardcode that. Other systems can use --with-libpython-dir to
    # override this.
    if platform.system().lower() == 'darwin':
        return '/usr/lib'

    pylib_loc = sysconfig.get_config_var("LIBPL")
    pylib_ldlibrary = sysconfig.get_config_var("LDLIBRARY")

    py_sharedlib = os.path.join(pylib_loc, pylib_ldlibrary)
    if os.path.exists(py_sharedlib):
        return pylib_loc

    # Workaround for Fedora
    pylib_loc = sysconfig.get_config_var("LIBDIR")
    pylib_ldlibrary = sysconfig.get_config_var("LDLIBRARY")

    py_sharedlib = os.path.join(pylib_loc, pylib_ldlibrary)
    if os.path.exists(py_sharedlib):
        return pylib_loc

    return "None"


if __name__ == "__main__":
    if len(sys.argv) > 3:
        print("At most 2 arguments accepted")
        exit(1)

    if sys.argv[1] == '--abiflags':
        print(get_python_abiflags())
    elif sys.argv[1] == '--sosuffix':
        get = sysconfig.get_config_var
        suffix = get("EXT_SUFFIX") or get("SO") or ".so"
        print(suffix[1:])
    elif sys.argv[1] == '--pygi-overridedir':
        prefix = sys.argv[2]
        version = sys.version_info

        # If we are installing in the same prefix as PyGobject
        # make sure to install in the right place.
        import gi.overrides

        try:
            gi.overrides.__path__.remove(os.path.abspath(os.path.join(
                os.path.dirname(os.path.realpath(__file__)), '..', 'gi')))
        except ValueError:
            pass
        overrides_path = gi.overrides.__path__[0]
        if os.path.commonprefix([overrides_path, prefix]) == prefix:
            print(overrides_path)
            exit(0)

        # Otherwise follow python's way of install site packages inside
        # the provided prefix
        if os.name == 'posix':
            print(os.path.join(
                prefix, 'lib', 'python%d.%d' % (version.major, version.minor),
                'site-packages', 'gi', 'overrides'))
        else:
            print(os.path.join(
                prefix, 'Lib', 'Python%d%d' % (version.major, version.minor),
                'site-packages', 'gi', 'overrides'))
    elif sys.argv[1] == '--libloc':
        print(get_python_libloc())