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
8 class develop(easy_install):
9 """Set up package for development"""
11 description = "install package in 'development mode'"
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"),
18 boolean_options = easy_install.boolean_options + ['uninstall']
20 command_consumes_arguments = False # override base
24 if sys.platform == "win32":
25 from setuptools.command.scriptsetup import do_scriptsetup
30 self.multi_version = True
33 self.install_for_development()
34 self.warn_deprecated_options()
36 def initialize_options(self):
39 easy_install.initialize_options(self)
40 self.setup_path = None
41 self.always_copy_from = '.' # always copy eggs installed in curdir
43 def finalize_options(self):
44 ei = self.get_finalized_command("egg_info")
45 if ei.broken_egg_info:
47 "Please rename %r to %r before using 'develop'"
48 % (ei.egg_info, ei.broken_egg_info)
50 self.args = [ei.egg_name]
51 easy_install.finalize_options(self)
52 # pick up setup-dir .egg files only: no .egg-info
53 self.package_index.scan(glob.glob('*.egg'))
55 self.egg_link = os.path.join(self.install_dir, ei.egg_name+'.egg-link')
56 self.egg_base = ei.egg_base
57 if self.egg_path is None:
58 self.egg_path = os.path.abspath(ei.egg_base)
60 target = normalize_path(self.egg_base)
61 if normalize_path(os.path.join(self.install_dir, self.egg_path)) != target:
62 raise DistutilsOptionError(
63 "--egg-path must be a relative path from the install"
64 " directory to "+target
67 # Make a distribution for the package's source
68 self.dist = Distribution(
70 PathMetadata(target, os.path.abspath(ei.egg_info)),
71 project_name = ei.egg_name
74 p = self.egg_base.replace(os.sep,'/')
76 p = '../' * (p.count('/')+1)
78 p = normalize_path(os.path.join(self.install_dir, self.egg_path, p))
79 if p != normalize_path(os.curdir):
80 raise DistutilsOptionError(
81 "Can't get a consistent path to setup script from"
82 " installation directory", p, normalize_path(os.curdir))
84 def install_for_development(self):
85 # Ensure metadata is up-to-date
86 self.run_command('egg_info')
87 # Build extensions in-place
88 self.reinitialize_command('build_ext', inplace=1)
89 self.run_command('build_ext')
90 self.install_site_py() # ensure that target dir is site-safe
91 if setuptools.bootstrap_install_from:
92 self.easy_install(setuptools.bootstrap_install_from)
93 setuptools.bootstrap_install_from = None
95 # create an .egg-link in the installation dir, pointing to our egg
96 log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
98 f = open(self.egg_link,"w")
99 f.write(self.egg_path + "\n" + self.setup_path)
101 # postprocess the installed distro, fixing up .pth, installing scripts,
102 # and handling requirements
103 self.process_distribution(None, self.dist, not self.no_deps)
106 def uninstall_link(self):
107 if os.path.exists(self.egg_link):
108 log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
109 contents = [line.rstrip() for line in file(self.egg_link)]
110 if contents not in ([self.egg_path], [self.egg_path, self.setup_path]):
111 log.warn("Link points to %s: uninstall aborted", contents)
114 os.unlink(self.egg_link)
116 self.update_pth(self.dist) # remove any .pth link to us
117 if self.distribution.scripts:
118 # XXX should also check for entry point scripts!
119 log.warn("Note: you must uninstall or replace scripts manually!")
125 def install_egg_scripts(self, dist):
126 if dist is not self.dist:
127 # Installing a dependency, so fall back to normal behavior
128 return easy_install.install_egg_scripts(self,dist)
130 # create wrapper scripts in the script dir, pointing to dist.scripts
133 self.install_wrapper_scripts(dist)
136 for script_name in self.distribution.scripts or []:
137 script_path = os.path.abspath(convert_path(script_name))
138 script_name = os.path.basename(script_path)
139 f = open(script_path,'rU')
140 script_text = f.read()
142 self.install_script(dist, script_name, script_text, script_path)