Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / distribute-0.6.19-py2.7.egg / setuptools / command / develop.py @ 1a305335

History | View | Annotate | Download (5.24 KB)

1
from setuptools.command.easy_install import easy_install
2
from distutils.util import convert_path, subst_vars
3
from pkg_resources import Distribution, PathMetadata, normalize_path
4
from distutils import log
5
from distutils.errors import DistutilsError, DistutilsOptionError
6
import 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
    def finalize_options(self):
40
        ei = self.get_finalized_command("egg_info")
41
        if ei.broken_egg_info:
42
            raise DistutilsError(
43
            "Please rename %r to %r before using 'develop'"
44
            % (ei.egg_info, ei.broken_egg_info)
45
            )
46
        self.args = [ei.egg_name]
47

    
48

    
49

    
50

    
51
        easy_install.finalize_options(self)
52
        self.expand_basedirs()
53
        self.expand_dirs()
54
        # pick up setup-dir .egg files only: no .egg-info
55
        self.package_index.scan(glob.glob('*.egg'))
56

    
57
        self.egg_link = os.path.join(self.install_dir, ei.egg_name+'.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
        if normalize_path(os.path.join(self.install_dir, self.egg_path)) != target:
64
            raise DistutilsOptionError(
65
                "--egg-path must be a relative path from the install"
66
                " directory to "+target
67
        )
68

    
69
        # Make a distribution for the package's source
70
        self.dist = Distribution(
71
            target,
72
            PathMetadata(target, os.path.abspath(ei.egg_info)),
73
            project_name = ei.egg_name
74
        )
75

    
76
        p = self.egg_base.replace(os.sep,'/')
77
        if p!= os.curdir:
78
            p = '../' * (p.count('/')+1)
79
        self.setup_path = p
80
        p = normalize_path(os.path.join(self.install_dir, self.egg_path, p))
81
        if  p != normalize_path(os.curdir):
82
            raise DistutilsOptionError(
83
                "Can't get a consistent path to setup script from"
84
                " installation directory", p, normalize_path(os.curdir))
85

    
86
    def install_for_development(self):
87
        # Ensure metadata is up-to-date
88
        self.run_command('egg_info')
89
        # Build extensions in-place
90
        self.reinitialize_command('build_ext', inplace=1)
91
        self.run_command('build_ext')
92
        self.install_site_py()  # ensure that target dir is site-safe
93
        if setuptools.bootstrap_install_from:
94
            self.easy_install(setuptools.bootstrap_install_from)
95
            setuptools.bootstrap_install_from = None
96

    
97
        # create an .egg-link in the installation dir, pointing to our egg
98
        log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
99
        if not self.dry_run:
100
            f = open(self.egg_link,"w")
101
            f.write(self.egg_path + "\n" + self.setup_path)
102
            f.close()
103
        # postprocess the installed distro, fixing up .pth, installing scripts,
104
        # and handling requirements
105
        self.process_distribution(None, self.dist, not self.no_deps)
106

    
107

    
108
    def uninstall_link(self):
109
        if os.path.exists(self.egg_link):
110
            log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
111
            contents = [line.rstrip() for line in open(self.egg_link)]
112
            if contents not in ([self.egg_path], [self.egg_path, self.setup_path]):
113
                log.warn("Link points to %s: uninstall aborted", contents)
114
                return
115
            if not self.dry_run:
116
                os.unlink(self.egg_link)
117
        if not self.dry_run:
118
            self.update_pth(self.dist)  # remove any .pth link to us
119
        if self.distribution.scripts:
120
            # XXX should also check for entry point scripts!
121
            log.warn("Note: you must uninstall or replace scripts manually!")
122

    
123
    def install_egg_scripts(self, dist):
124
        if dist is not self.dist:
125
            # Installing a dependency, so fall back to normal behavior
126
            return easy_install.install_egg_scripts(self,dist)
127

    
128
        # create wrapper scripts in the script dir, pointing to dist.scripts
129

    
130
        # new-style...
131
        self.install_wrapper_scripts(dist)
132

    
133
        # ...and old-style
134
        for script_name in self.distribution.scripts or []:
135
            script_path = os.path.abspath(convert_path(script_name))
136
            script_name = os.path.basename(script_path)
137
            f = open(script_path,'rU')
138
            script_text = f.read()
139
            f.close()
140
            self.install_script(dist, script_name, script_text, script_path)
141