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 self.multi_version = True
27 self.install_for_development()
28 self.warn_deprecated_options()
30 def initialize_options(self):
33 easy_install.initialize_options(self)
34 self.setup_path = None
35 self.always_copy_from = '.' # always copy eggs installed in curdir
42 def finalize_options(self):
43 ei = self.get_finalized_command("egg_info")
44 if ei.broken_egg_info:
46 "Please rename %r to %r before using 'develop'"
47 % (ei.egg_info, ei.broken_egg_info)
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'))
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)
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
66 # Make a distribution for the package's source
67 self.dist = Distribution(
69 PathMetadata(target, os.path.abspath(ei.egg_info)),
70 project_name = ei.egg_name
73 p = self.egg_base.replace(os.sep,'/')
75 p = '../' * (p.count('/')+1)
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))
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
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)
97 f = open(self.egg_link,"w")
98 f.write(self.egg_path + "\n" + self.setup_path)
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)
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)
113 os.unlink(self.egg_link)
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!")
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)
129 # create wrapper scripts in the script dir, pointing to dist.scripts
132 self.install_wrapper_scripts(dist)
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()
141 self.install_script(dist, script_name, script_text, script_path)