Phillip J. Eby | 069159b | 2006-04-18 04:05:34 +0000 | [diff] [blame] | 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 |
| 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 | ] |
| 16 | |
| 17 | boolean_options = easy_install.boolean_options + ['uninstall'] |
| 18 | |
| 19 | command_consumes_arguments = False # override base |
| 20 | |
| 21 | def run(self): |
| 22 | if self.uninstall: |
| 23 | self.multi_version = True |
| 24 | self.uninstall_link() |
| 25 | else: |
| 26 | self.install_for_development() |
| 27 | self.warn_deprecated_options() |
| 28 | |
| 29 | def initialize_options(self): |
| 30 | self.uninstall = None |
| 31 | easy_install.initialize_options(self) |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 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 | ) |
Tim Peters | 584b0e0 | 2006-04-18 17:32:12 +0000 | [diff] [blame^] | 49 | self.args = [ei.egg_name] |
Phillip J. Eby | 069159b | 2006-04-18 04:05:34 +0000 | [diff] [blame] | 50 | easy_install.finalize_options(self) |
| 51 | self.egg_link = os.path.join(self.install_dir, ei.egg_name+'.egg-link') |
| 52 | self.egg_base = ei.egg_base |
| 53 | self.egg_path = os.path.abspath(ei.egg_base) |
| 54 | |
| 55 | # Make a distribution for the package's source |
| 56 | self.dist = Distribution( |
| 57 | normalize_path(self.egg_path), |
| 58 | PathMetadata(self.egg_path, os.path.abspath(ei.egg_info)), |
| 59 | project_name = ei.egg_name |
| 60 | ) |
| 61 | |
| 62 | def install_for_development(self): |
| 63 | # Ensure metadata is up-to-date |
| 64 | self.run_command('egg_info') |
| 65 | |
| 66 | # Build extensions in-place |
| 67 | self.reinitialize_command('build_ext', inplace=1) |
| 68 | self.run_command('build_ext') |
| 69 | |
| 70 | self.install_site_py() # ensure that target dir is site-safe |
| 71 | |
| 72 | # create an .egg-link in the installation dir, pointing to our egg |
| 73 | log.info("Creating %s (link to %s)", self.egg_link, self.egg_base) |
| 74 | if not self.dry_run: |
| 75 | f = open(self.egg_link,"w") |
| 76 | f.write(self.egg_path) |
| 77 | f.close() |
| 78 | |
| 79 | # postprocess the installed distro, fixing up .pth, installing scripts, |
| 80 | # and handling requirements |
| 81 | self.process_distribution(None, self.dist) |
| 82 | |
| 83 | def uninstall_link(self): |
| 84 | if os.path.exists(self.egg_link): |
| 85 | log.info("Removing %s (link to %s)", self.egg_link, self.egg_base) |
| 86 | contents = [line.rstrip() for line in file(self.egg_link)] |
| 87 | if contents != [self.egg_path]: |
| 88 | log.warn("Link points to %s: uninstall aborted", contents) |
| 89 | return |
| 90 | if not self.dry_run: |
| 91 | os.unlink(self.egg_link) |
| 92 | if not self.dry_run: |
| 93 | self.update_pth(self.dist) # remove any .pth link to us |
| 94 | if self.distribution.scripts: |
| 95 | # XXX should also check for entry point scripts! |
| 96 | log.warn("Note: you must uninstall or replace scripts manually!") |
| 97 | |
| 98 | |
| 99 | def install_egg_scripts(self, dist): |
| 100 | if dist is not self.dist: |
| 101 | # Installing a dependency, so fall back to normal behavior |
| 102 | return easy_install.install_egg_scripts(self,dist) |
| 103 | |
| 104 | # create wrapper scripts in the script dir, pointing to dist.scripts |
| 105 | |
| 106 | # new-style... |
Tim Peters | 584b0e0 | 2006-04-18 17:32:12 +0000 | [diff] [blame^] | 107 | self.install_wrapper_scripts(dist) |
Phillip J. Eby | 069159b | 2006-04-18 04:05:34 +0000 | [diff] [blame] | 108 | |
| 109 | # ...and old-style |
| 110 | for script_name in self.distribution.scripts or []: |
| 111 | script_path = os.path.abspath(convert_path(script_name)) |
| 112 | script_name = os.path.basename(script_path) |
| 113 | f = open(script_path,'rU') |
| 114 | script_text = f.read() |
| 115 | f.close() |
| 116 | self.install_script(dist, script_name, script_text, script_path) |