Mercurial > repos > shellac > sam_consensus_v3
comparison env/lib/python3.9/site-packages/setuptools/command/develop.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 distutils.util import convert_path | |
2 from distutils import log | |
3 from distutils.errors import DistutilsError, DistutilsOptionError | |
4 import os | |
5 import glob | |
6 import io | |
7 | |
8 import pkg_resources | |
9 from setuptools.command.easy_install import easy_install | |
10 from setuptools import namespaces | |
11 import setuptools | |
12 | |
13 | |
14 class develop(namespaces.DevelopInstaller, easy_install): | |
15 """Set up package for development""" | |
16 | |
17 description = "install package in 'development mode'" | |
18 | |
19 user_options = easy_install.user_options + [ | |
20 ("uninstall", "u", "Uninstall this source package"), | |
21 ("egg-path=", None, "Set the path to be used in the .egg-link file"), | |
22 ] | |
23 | |
24 boolean_options = easy_install.boolean_options + ['uninstall'] | |
25 | |
26 command_consumes_arguments = False # override base | |
27 | |
28 def run(self): | |
29 if self.uninstall: | |
30 self.multi_version = True | |
31 self.uninstall_link() | |
32 self.uninstall_namespaces() | |
33 else: | |
34 self.install_for_development() | |
35 self.warn_deprecated_options() | |
36 | |
37 def initialize_options(self): | |
38 self.uninstall = None | |
39 self.egg_path = None | |
40 easy_install.initialize_options(self) | |
41 self.setup_path = None | |
42 self.always_copy_from = '.' # always copy eggs installed in curdir | |
43 | |
44 def finalize_options(self): | |
45 ei = self.get_finalized_command("egg_info") | |
46 if ei.broken_egg_info: | |
47 template = "Please rename %r to %r before using 'develop'" | |
48 args = ei.egg_info, ei.broken_egg_info | |
49 raise DistutilsError(template % args) | |
50 self.args = [ei.egg_name] | |
51 | |
52 easy_install.finalize_options(self) | |
53 self.expand_basedirs() | |
54 self.expand_dirs() | |
55 # pick up setup-dir .egg files only: no .egg-info | |
56 self.package_index.scan(glob.glob('*.egg')) | |
57 | |
58 egg_link_fn = ei.egg_name + '.egg-link' | |
59 self.egg_link = os.path.join(self.install_dir, egg_link_fn) | |
60 self.egg_base = ei.egg_base | |
61 if self.egg_path is None: | |
62 self.egg_path = os.path.abspath(ei.egg_base) | |
63 | |
64 target = pkg_resources.normalize_path(self.egg_base) | |
65 egg_path = pkg_resources.normalize_path( | |
66 os.path.join(self.install_dir, self.egg_path)) | |
67 if egg_path != target: | |
68 raise DistutilsOptionError( | |
69 "--egg-path must be a relative path from the install" | |
70 " directory to " + target | |
71 ) | |
72 | |
73 # Make a distribution for the package's source | |
74 self.dist = pkg_resources.Distribution( | |
75 target, | |
76 pkg_resources.PathMetadata(target, os.path.abspath(ei.egg_info)), | |
77 project_name=ei.egg_name | |
78 ) | |
79 | |
80 self.setup_path = self._resolve_setup_path( | |
81 self.egg_base, | |
82 self.install_dir, | |
83 self.egg_path, | |
84 ) | |
85 | |
86 @staticmethod | |
87 def _resolve_setup_path(egg_base, install_dir, egg_path): | |
88 """ | |
89 Generate a path from egg_base back to '.' where the | |
90 setup script resides and ensure that path points to the | |
91 setup path from $install_dir/$egg_path. | |
92 """ | |
93 path_to_setup = egg_base.replace(os.sep, '/').rstrip('/') | |
94 if path_to_setup != os.curdir: | |
95 path_to_setup = '../' * (path_to_setup.count('/') + 1) | |
96 resolved = pkg_resources.normalize_path( | |
97 os.path.join(install_dir, egg_path, path_to_setup) | |
98 ) | |
99 if resolved != pkg_resources.normalize_path(os.curdir): | |
100 raise DistutilsOptionError( | |
101 "Can't get a consistent path to setup script from" | |
102 " installation directory", resolved, | |
103 pkg_resources.normalize_path(os.curdir)) | |
104 return path_to_setup | |
105 | |
106 def install_for_development(self): | |
107 if getattr(self.distribution, 'use_2to3', False): | |
108 # If we run 2to3 we can not do this inplace: | |
109 | |
110 # Ensure metadata is up-to-date | |
111 self.reinitialize_command('build_py', inplace=0) | |
112 self.run_command('build_py') | |
113 bpy_cmd = self.get_finalized_command("build_py") | |
114 build_path = pkg_resources.normalize_path(bpy_cmd.build_lib) | |
115 | |
116 # Build extensions | |
117 self.reinitialize_command('egg_info', egg_base=build_path) | |
118 self.run_command('egg_info') | |
119 | |
120 self.reinitialize_command('build_ext', inplace=0) | |
121 self.run_command('build_ext') | |
122 | |
123 # Fixup egg-link and easy-install.pth | |
124 ei_cmd = self.get_finalized_command("egg_info") | |
125 self.egg_path = build_path | |
126 self.dist.location = build_path | |
127 # XXX | |
128 self.dist._provider = pkg_resources.PathMetadata( | |
129 build_path, ei_cmd.egg_info) | |
130 else: | |
131 # Without 2to3 inplace works fine: | |
132 self.run_command('egg_info') | |
133 | |
134 # Build extensions in-place | |
135 self.reinitialize_command('build_ext', inplace=1) | |
136 self.run_command('build_ext') | |
137 | |
138 if setuptools.bootstrap_install_from: | |
139 self.easy_install(setuptools.bootstrap_install_from) | |
140 setuptools.bootstrap_install_from = None | |
141 | |
142 self.install_namespaces() | |
143 | |
144 # create an .egg-link in the installation dir, pointing to our egg | |
145 log.info("Creating %s (link to %s)", self.egg_link, self.egg_base) | |
146 if not self.dry_run: | |
147 with open(self.egg_link, "w") as f: | |
148 f.write(self.egg_path + "\n" + self.setup_path) | |
149 # postprocess the installed distro, fixing up .pth, installing scripts, | |
150 # and handling requirements | |
151 self.process_distribution(None, self.dist, not self.no_deps) | |
152 | |
153 def uninstall_link(self): | |
154 if os.path.exists(self.egg_link): | |
155 log.info("Removing %s (link to %s)", self.egg_link, self.egg_base) | |
156 egg_link_file = open(self.egg_link) | |
157 contents = [line.rstrip() for line in egg_link_file] | |
158 egg_link_file.close() | |
159 if contents not in ([self.egg_path], | |
160 [self.egg_path, self.setup_path]): | |
161 log.warn("Link points to %s: uninstall aborted", contents) | |
162 return | |
163 if not self.dry_run: | |
164 os.unlink(self.egg_link) | |
165 if not self.dry_run: | |
166 self.update_pth(self.dist) # remove any .pth link to us | |
167 if self.distribution.scripts: | |
168 # XXX should also check for entry point scripts! | |
169 log.warn("Note: you must uninstall or replace scripts manually!") | |
170 | |
171 def install_egg_scripts(self, dist): | |
172 if dist is not self.dist: | |
173 # Installing a dependency, so fall back to normal behavior | |
174 return easy_install.install_egg_scripts(self, dist) | |
175 | |
176 # create wrapper scripts in the script dir, pointing to dist.scripts | |
177 | |
178 # new-style... | |
179 self.install_wrapper_scripts(dist) | |
180 | |
181 # ...and old-style | |
182 for script_name in self.distribution.scripts or []: | |
183 script_path = os.path.abspath(convert_path(script_name)) | |
184 script_name = os.path.basename(script_path) | |
185 with io.open(script_path) as strm: | |
186 script_text = strm.read() | |
187 self.install_script(dist, script_name, script_text, script_path) | |
188 | |
189 def install_wrapper_scripts(self, dist): | |
190 dist = VersionlessRequirement(dist) | |
191 return easy_install.install_wrapper_scripts(self, dist) | |
192 | |
193 | |
194 class VersionlessRequirement: | |
195 """ | |
196 Adapt a pkg_resources.Distribution to simply return the project | |
197 name as the 'requirement' so that scripts will work across | |
198 multiple versions. | |
199 | |
200 >>> from pkg_resources import Distribution | |
201 >>> dist = Distribution(project_name='foo', version='1.0') | |
202 >>> str(dist.as_requirement()) | |
203 'foo==1.0' | |
204 >>> adapted_dist = VersionlessRequirement(dist) | |
205 >>> str(adapted_dist.as_requirement()) | |
206 'foo' | |
207 """ | |
208 | |
209 def __init__(self, dist): | |
210 self.__dist = dist | |
211 | |
212 def __getattr__(self, name): | |
213 return getattr(self.__dist, name) | |
214 | |
215 def as_requirement(self): | |
216 return self.project_name |