File: python-site.py

package info (click to toggle)
gringo 5.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,128 kB
  • sloc: cpp: 210,867; ansic: 37,507; python: 11,271; yacc: 825; javascript: 627; sh: 368; xml: 364; makefile: 102
file content (63 lines) | stat: -rw-r--r-- 1,976 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
import sys
from argparse import ArgumentParser

if sys.version_info >= (3, 11):
    NEW_STYLE = True
    from sysconfig import (
        get_config_var,
        get_config_vars,
        get_path,
        get_preferred_scheme,
    )
else:
    NEW_STYLE = False
    from distutils.sysconfig import get_config_vars, get_python_lib
    from site import USER_SITE

parser = ArgumentParser()
if sys.version_info >= (3, 7):
    subparser = parser.add_subparsers(required=True, dest="action")
else:
    subparser = parser.add_subparsers(dest="action")

prefix_parser = subparser.add_parser("target")
prefix_group = prefix_parser.add_mutually_exclusive_group()
prefix_group.add_argument("--user", action="store_true", help="get user prefix")
prefix_group.add_argument("--prefix", type=str, help="prepend prefix")

prefix_parser = subparser.add_parser("suffix")

result = parser.parse_args()

if NEW_STYLE:
    if result.action == "target":
        if result.user:
            scheme = get_preferred_scheme("user")
        else:
            scheme = get_preferred_scheme("prefix")
        if result.prefix is not None:
            cvars = get_config_vars()
            cvars["base"] = result.prefix
            cvars["platbase"] = result.prefix
            platlib = get_path("platlib", scheme, cvars)
        else:
            platlib = get_path("platlib", scheme)
        print(platlib)
    elif result.action == "suffix":
        print(get_config_var("EXT_SUFFIX"))
else:
    # TODO: remove once python 3.10 is eol
    if result.action == "target":
        if result.user:
            print(USER_SITE)
        else:
            print(get_python_lib(True, False, result.prefix))
    elif result.action == "suffix":
        SO, SOABI, EXT_SUFFIX = get_config_vars("SO", "SOABI", "EXT_SUFFIX")
        if EXT_SUFFIX is not None:
            ext = EXT_SUFFIX
        elif SOABI is not None:
            ext = "".join(".", SOABI, SO)
        else:
            ext = SO
        print(ext)