comparison venv/lib/python2.7/site-packages/setuptools/command/develop.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
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
7 from pkg_resources import Distribution, PathMetadata, normalize_path
8 from setuptools.command.easy_install import easy_install
9 from setuptools.compat import PY3
10 import setuptools
11
12
13 class develop(easy_install):
14 """Set up package for development"""
15
16 description = "install package in 'development mode'"
17
18 user_options = easy_install.user_options + [
19 ("uninstall", "u", "Uninstall this source package"),
20 ("egg-path=", None, "Set the path to be used in the .egg-link file"),
21 ]
22
23 boolean_options = easy_install.boolean_options + ['uninstall']
24
25 command_consumes_arguments = False # override base
26
27 def run(self):
28 if self.uninstall:
29 self.multi_version = True
30 self.uninstall_link()
31 else:
32 self.install_for_development()
33 self.warn_deprecated_options()
34
35 def initialize_options(self):
36 self.uninstall = None
37 self.egg_path = None
38 easy_install.initialize_options(self)
39 self.setup_path = None
40 self.always_copy_from = '.' # always copy eggs installed in curdir
41
42 def finalize_options(self):
43 ei = self.get_finalized_command("egg_info")
44 if ei.broken_egg_info:
45 template = "Please rename %r to %r before using 'develop'"
46 args = ei.egg_info, ei.broken_egg_info
47 raise DistutilsError(template % args)
48 self.args = [ei.egg_name]
49
50 easy_install.finalize_options(self)
51 self.expand_basedirs()
52 self.expand_dirs()
53 # pick up setup-dir .egg files only: no .egg-info
54 self.package_index.scan(glob.glob('*.egg'))
55
56 self.egg_link = os.path.join(self.install_dir, ei.egg_name +
57 '.egg-link')
58 self.egg_base = ei.egg_base
59 if self.egg_path is None:
60 self.egg_path = os.path.abspath(ei.egg_base)
61
62 target = normalize_path(self.egg_base)
63 egg_path = normalize_path(os.path.join(self.install_dir,
64 self.egg_path))
65 if egg_path != target:
66 raise DistutilsOptionError(
67 "--egg-path must be a relative path from the install"
68 " directory to " + target
69 )
70
71 # Make a distribution for the package's source
72 self.dist = Distribution(
73 target,
74 PathMetadata(target, os.path.abspath(ei.egg_info)),
75 project_name=ei.egg_name
76 )
77
78 p = self.egg_base.replace(os.sep, '/')
79 if p != os.curdir:
80 p = '../' * (p.count('/') + 1)
81 self.setup_path = p
82 p = normalize_path(os.path.join(self.install_dir, self.egg_path, p))
83 if p != normalize_path(os.curdir):
84 raise DistutilsOptionError(
85 "Can't get a consistent path to setup script from"
86 " installation directory", p, normalize_path(os.curdir))
87
88 def install_for_development(self):
89 if PY3 and getattr(self.distribution, 'use_2to3', False):
90 # If we run 2to3 we can not do this inplace:
91
92 # Ensure metadata is up-to-date
93 self.reinitialize_command('build_py', inplace=0)
94 self.run_command('build_py')
95 bpy_cmd = self.get_finalized_command("build_py")
96 build_path = normalize_path(bpy_cmd.build_lib)
97
98 # Build extensions
99 self.reinitialize_command('egg_info', egg_base=build_path)
100 self.run_command('egg_info')
101
102 self.reinitialize_command('build_ext', inplace=0)
103 self.run_command('build_ext')
104
105 # Fixup egg-link and easy-install.pth
106 ei_cmd = self.get_finalized_command("egg_info")
107 self.egg_path = build_path
108 self.dist.location = build_path
109 # XXX
110 self.dist._provider = PathMetadata(build_path, ei_cmd.egg_info)
111 else:
112 # Without 2to3 inplace works fine:
113 self.run_command('egg_info')
114
115 # Build extensions in-place
116 self.reinitialize_command('build_ext', inplace=1)
117 self.run_command('build_ext')
118
119 self.install_site_py() # ensure that target dir is site-safe
120 if setuptools.bootstrap_install_from:
121 self.easy_install(setuptools.bootstrap_install_from)
122 setuptools.bootstrap_install_from = None
123
124 # create an .egg-link in the installation dir, pointing to our egg
125 log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
126 if not self.dry_run:
127 f = open(self.egg_link, "w")
128 f.write(self.egg_path + "\n" + self.setup_path)
129 f.close()
130 # postprocess the installed distro, fixing up .pth, installing scripts,
131 # and handling requirements
132 self.process_distribution(None, self.dist, not self.no_deps)
133
134 def uninstall_link(self):
135 if os.path.exists(self.egg_link):
136 log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
137 egg_link_file = open(self.egg_link)
138 contents = [line.rstrip() for line in egg_link_file]
139 egg_link_file.close()
140 if contents not in ([self.egg_path],
141 [self.egg_path, self.setup_path]):
142 log.warn("Link points to %s: uninstall aborted", contents)
143 return
144 if not self.dry_run:
145 os.unlink(self.egg_link)
146 if not self.dry_run:
147 self.update_pth(self.dist) # remove any .pth link to us
148 if self.distribution.scripts:
149 # XXX should also check for entry point scripts!
150 log.warn("Note: you must uninstall or replace scripts manually!")
151
152 def install_egg_scripts(self, dist):
153 if dist is not self.dist:
154 # Installing a dependency, so fall back to normal behavior
155 return easy_install.install_egg_scripts(self, dist)
156
157 # create wrapper scripts in the script dir, pointing to dist.scripts
158
159 # new-style...
160 self.install_wrapper_scripts(dist)
161
162 # ...and old-style
163 for script_name in self.distribution.scripts or []:
164 script_path = os.path.abspath(convert_path(script_name))
165 script_name = os.path.basename(script_path)
166 f = open(script_path, 'rU')
167 script_text = f.read()
168 f.close()
169 self.install_script(dist, script_name, script_text, script_path)