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