comparison env/lib/python3.9/site-packages/virtualenv/create/describe.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 from __future__ import absolute_import, print_function, unicode_literals
2
3 from abc import ABCMeta
4 from collections import OrderedDict
5
6 from six import add_metaclass
7
8 from virtualenv.info import IS_WIN
9 from virtualenv.util.path import Path
10 from virtualenv.util.six import ensure_text
11
12
13 @add_metaclass(ABCMeta)
14 class Describe(object):
15 """Given a host interpreter tell us information about what the created interpreter might look like"""
16
17 suffix = ".exe" if IS_WIN else ""
18
19 def __init__(self, dest, interpreter):
20 self.interpreter = interpreter
21 self.dest = dest
22 self._stdlib = None
23 self._stdlib_platform = None
24 self._system_stdlib = None
25 self._conf_vars = None
26
27 @property
28 def bin_dir(self):
29 return self.script_dir
30
31 @property
32 def script_dir(self):
33 return self.dest / Path(self.interpreter.distutils_install["scripts"])
34
35 @property
36 def purelib(self):
37 return self.dest / self.interpreter.distutils_install["purelib"]
38
39 @property
40 def platlib(self):
41 return self.dest / self.interpreter.distutils_install["platlib"]
42
43 @property
44 def libs(self):
45 return list(OrderedDict(((self.platlib, None), (self.purelib, None))).keys())
46
47 @property
48 def stdlib(self):
49 if self._stdlib is None:
50 self._stdlib = Path(self.interpreter.sysconfig_path("stdlib", config_var=self._config_vars))
51 return self._stdlib
52
53 @property
54 def stdlib_platform(self):
55 if self._stdlib_platform is None:
56 self._stdlib_platform = Path(self.interpreter.sysconfig_path("platstdlib", config_var=self._config_vars))
57 return self._stdlib_platform
58
59 @property
60 def _config_vars(self):
61 if self._conf_vars is None:
62 self._conf_vars = self._calc_config_vars(ensure_text(str(self.dest)))
63 return self._conf_vars
64
65 def _calc_config_vars(self, to):
66 return {
67 k: (to if v.startswith(self.interpreter.prefix) else v) for k, v in self.interpreter.sysconfig_vars.items()
68 }
69
70 @classmethod
71 def can_describe(cls, interpreter):
72 """Knows means it knows how the output will look"""
73 return True
74
75 @property
76 def env_name(self):
77 return ensure_text(self.dest.parts[-1])
78
79 @property
80 def exe(self):
81 return self.bin_dir / "{}{}".format(self.exe_stem(), self.suffix)
82
83 @classmethod
84 def exe_stem(cls):
85 """executable name without suffix - there seems to be no standard way to get this without creating it"""
86 raise NotImplementedError
87
88 def script(self, name):
89 return self.script_dir / "{}{}".format(name, self.suffix)
90
91
92 @add_metaclass(ABCMeta)
93 class Python2Supports(Describe):
94 @classmethod
95 def can_describe(cls, interpreter):
96 return interpreter.version_info.major == 2 and super(Python2Supports, cls).can_describe(interpreter)
97
98
99 @add_metaclass(ABCMeta)
100 class Python3Supports(Describe):
101 @classmethod
102 def can_describe(cls, interpreter):
103 return interpreter.version_info.major == 3 and super(Python3Supports, cls).can_describe(interpreter)
104
105
106 @add_metaclass(ABCMeta)
107 class PosixSupports(Describe):
108 @classmethod
109 def can_describe(cls, interpreter):
110 return interpreter.os == "posix" and super(PosixSupports, cls).can_describe(interpreter)
111
112
113 @add_metaclass(ABCMeta)
114 class WindowsSupports(Describe):
115 @classmethod
116 def can_describe(cls, interpreter):
117 return interpreter.os == "nt" and super(WindowsSupports, cls).can_describe(interpreter)