Mercurial > repos > guerler > springsuite
comparison planemo/lib/python3.7/site-packages/virtualenv/create/debug.py @ 1:56ad4e20f292 draft
"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author | guerler |
---|---|
date | Fri, 31 Jul 2020 00:32:28 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:d30785e31577 | 1:56ad4e20f292 |
---|---|
1 """Inspect a target Python interpreter virtual environment wise""" | |
2 import sys # built-in | |
3 | |
4 PYPY2_WIN = hasattr(sys, "pypy_version_info") and sys.platform != "win32" and sys.version_info[0] == 2 | |
5 | |
6 | |
7 def encode_path(value): | |
8 if value is None: | |
9 return None | |
10 if not isinstance(value, (str, bytes)): | |
11 if isinstance(value, type): | |
12 value = repr(value) | |
13 else: | |
14 value = repr(type(value)) | |
15 if isinstance(value, bytes) and not PYPY2_WIN: | |
16 value = value.decode(sys.getfilesystemencoding()) | |
17 return value | |
18 | |
19 | |
20 def encode_list_path(value): | |
21 return [encode_path(i) for i in value] | |
22 | |
23 | |
24 def run(): | |
25 """print debug data about the virtual environment""" | |
26 try: | |
27 from collections import OrderedDict | |
28 except ImportError: # pragma: no cover | |
29 # this is possible if the standard library cannot be accessed | |
30 # noinspection PyPep8Naming | |
31 OrderedDict = dict # pragma: no cover | |
32 result = OrderedDict([("sys", OrderedDict())]) | |
33 path_keys = ( | |
34 "executable", | |
35 "_base_executable", | |
36 "prefix", | |
37 "base_prefix", | |
38 "real_prefix", | |
39 "exec_prefix", | |
40 "base_exec_prefix", | |
41 "path", | |
42 "meta_path", | |
43 ) | |
44 for key in path_keys: | |
45 value = getattr(sys, key, None) | |
46 if isinstance(value, list): | |
47 value = encode_list_path(value) | |
48 else: | |
49 value = encode_path(value) | |
50 result["sys"][key] = value | |
51 result["sys"]["fs_encoding"] = sys.getfilesystemencoding() | |
52 result["sys"]["io_encoding"] = getattr(sys.stdout, "encoding", None) | |
53 result["version"] = sys.version | |
54 | |
55 try: | |
56 import sysconfig | |
57 | |
58 # https://bugs.python.org/issue22199 | |
59 makefile = getattr(sysconfig, "get_makefile_filename", getattr(sysconfig, "_get_makefile_filename", None)) | |
60 result["makefile_filename"] = encode_path(makefile()) | |
61 except ImportError: | |
62 pass | |
63 | |
64 import os # landmark | |
65 | |
66 result["os"] = repr(os) | |
67 | |
68 try: | |
69 # noinspection PyUnresolvedReferences | |
70 import site # site | |
71 | |
72 result["site"] = repr(site) | |
73 except ImportError as exception: # pragma: no cover | |
74 result["site"] = repr(exception) # pragma: no cover | |
75 | |
76 try: | |
77 # noinspection PyUnresolvedReferences | |
78 import datetime # site | |
79 | |
80 result["datetime"] = repr(datetime) | |
81 except ImportError as exception: # pragma: no cover | |
82 result["datetime"] = repr(exception) # pragma: no cover | |
83 | |
84 try: | |
85 # noinspection PyUnresolvedReferences | |
86 import math # site | |
87 | |
88 result["math"] = repr(math) | |
89 except ImportError as exception: # pragma: no cover | |
90 result["math"] = repr(exception) # pragma: no cover | |
91 | |
92 # try to print out, this will validate if other core modules are available (json in this case) | |
93 try: | |
94 import json | |
95 | |
96 result["json"] = repr(json) | |
97 except ImportError as exception: | |
98 result["json"] = repr(exception) | |
99 else: | |
100 try: | |
101 content = json.dumps(result, indent=2) | |
102 sys.stdout.write(content) | |
103 except (ValueError, TypeError) as exception: # pragma: no cover | |
104 sys.stderr.write(repr(exception)) | |
105 sys.stdout.write(repr(result)) # pragma: no cover | |
106 raise SystemExit(1) # pragma: no cover | |
107 | |
108 | |
109 if __name__ == "__main__": | |
110 run() |