]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/setuptools/namespaces.py
2 from distutils
import log
6 flatten
= itertools
.chain
.from_iterable
11 nspkg_ext
= '-nspkg.pth'
13 def install_namespaces(self
):
14 nsp
= self
._get
_all
_ns
_packages
()
17 filename
, ext
= os
.path
.splitext(self
._get
_target
())
18 filename
+= self
.nspkg_ext
19 self
.outputs
.append(filename
)
20 log
.info("Installing %s", filename
)
21 lines
= map(self
._gen
_nspkg
_line
, nsp
)
24 # always generate the lines, even in dry run
28 with
open(filename
, 'wt') as f
:
31 def uninstall_namespaces(self
):
32 filename
, ext
= os
.path
.splitext(self
._get
_target
())
33 filename
+= self
.nspkg_ext
34 if not os
.path
.exists(filename
):
36 log
.info("Removing %s", filename
)
39 def _get_target(self
):
43 "import sys, types, os",
44 "has_mfs = sys.version_info > (3, 5)",
45 "p = os.path.join(%(root)s, *%(pth)r)",
46 "importlib = has_mfs and __import__('importlib.util')",
47 "has_mfs and __import__('importlib.machinery')",
50 "sys.modules.setdefault(%(pkg)r, "
51 "importlib.util.module_from_spec("
52 "importlib.machinery.PathFinder.find_spec(%(pkg)r, "
53 "[os.path.dirname(p)])))"
57 "sys.modules.setdefault(%(pkg)r, types.ModuleType(%(pkg)r))"
59 "mp = (m or []) and m.__dict__.setdefault('__path__',[])",
60 "(p not in mp) and mp.append(p)",
62 "lines for the namespace installer"
65 'm and setattr(sys.modules[%(parent)r], %(child)r, m)',
67 "additional line(s) when a parent package is indicated"
70 return "sys._getframe(1).f_locals['sitedir']"
72 def _gen_nspkg_line(self
, pkg
):
73 pth
= tuple(pkg
.split('.'))
74 root
= self
._get
_root
()
75 tmpl_lines
= self
._nspkg
_tmpl
76 parent
, sep
, child
= pkg
.rpartition('.')
78 tmpl_lines
+= self
._nspkg
_tmpl
_multi
79 return ';'.join(tmpl_lines
) % locals() + '\n'
81 def _get_all_ns_packages(self
):
82 """Return sorted list of all package namespaces"""
83 pkgs
= self
.distribution
.namespace_packages
or []
84 return sorted(flatten(map(self
._pkg
_names
, pkgs
)))
89 Given a namespace package, yield the components of that
92 >>> names = Installer._pkg_names('a.b.c')
93 >>> set(names) == set(['a', 'a.b', 'a.b.c'])
96 parts
= pkg
.split('.')
102 class DevelopInstaller(Installer
):
104 return repr(str(self
.egg_path
))
106 def _get_target(self
):