[Python-checkins] python/nondist/sandbox/setuptools/setuptools/command develop.py, NONE, 1.1 __init__.py, 1.3, 1.4 easy_install.py, 1.1, 1.2 test.py, 1.2, 1.3

pje@users.sourceforge.net pje at users.sourceforge.net
Wed Jul 6 05:46:19 CEST 2005


Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13765/setuptools/command

Modified Files:
	__init__.py easy_install.py test.py 
Added Files:
	develop.py 
Log Message:
Added ``develop`` command to ``setuptools``-based packages.  This command
installs an ``.egg-link`` pointing to the package's source directory, and
script wrappers that ``execfile()`` the source versions of the package's
scripts.  This lets you put your development checkout(s) on sys.path 
without having to actually install them.  (To uninstall the link, use
use ``setup.py develop --uninstall``.)


--- NEW FILE: develop.py ---
from setuptools.command.easy_install import easy_install
from distutils.util import convert_path
from pkg_resources import Distribution, PathMetadata
from distutils import log
import sys, os




































class develop(easy_install):
    """Set up package for development"""

    description = "install package in 'development mode'"

    user_options = [
        ("install-dir=", "d", "link package from DIR"),
        ("script-dir=", "s", "create script wrappers in DIR"),
        ("multi-version", "m", "make apps have to require() a version"),
        ("exclude-scripts", "x", "Don't install scripts"),
        ("always-copy", "a", "Copy all needed dependencies to install dir"),
        ("uninstall", "u", "Uninstall this source package"),
    ]

    boolean_options = [
        'multi-version', 'exclude-scripts', 'always-copy', 'uninstall'
    ]

    command_consumes_arguments = False  # override base

    def initialize_options(self):
        self.uninstall = None
        easy_install.initialize_options(self)

    def finalize_options(self):
        ei = self.get_finalized_command("egg_info")
        self.args = [ei.egg_name]
        easy_install.finalize_options(self)
        self.egg_link = os.path.join(self.install_dir, ei.egg_name+'.egg-link')
        self.egg_base = ei.egg_base
        self.egg_path = os.path.abspath(ei.egg_base)

        # Make a distribution for the package's source
        self.dist = Distribution(
            self.egg_path,
            PathMetadata(self.egg_path, os.path.abspath(ei.egg_info)),
            name = ei.egg_name
        )



    def run(self):
        if self.uninstall:
            self.multi_version = True
            self.uninstall_link()
        else:
            self.install_for_development()

    def install_for_development(self):
        # Ensure metadata is up-to-date
        self.run_command('egg_info')
        ei = self.get_finalized_command("egg_info")

        # Build extensions in-place
        self.reinitialize_command('build_ext', inplace=1)
        self.run_command('build_ext')


        # create an .egg-link in the installation dir, pointing to our egg
        log.info("Creating %s (link to %s)", self.egg_link, self.egg_base)
        if not self.dry_run:
            f = open(self.egg_link,"w")
            f.write(self.egg_path)
            f.close()

        # postprocess the installed distro, fixing up .pth, installing scripts,
        # and handling requirements
        self.process_distribution(None, self.dist)

    def uninstall_link(self):
        if os.path.exists(self.egg_link):
            log.info("Removing %s (link to %s)", self.egg_link, self.egg_base)
            contents = [line.rstrip() for line in file(self.egg_link)]
            if contents != [self.egg_path]:
                log.warn("Link points to %s: uninstall aborted", contents)
                return
            if not self.dry_run:
                os.unlink(self.egg_link)
        self.update_pth(self.dist)  # remove any .pth link to us
        if self.distribution.scripts:
            log.warn("Note: you must uninstall or replace scripts manually!")

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

        # create wrapper scripts in the script dir, pointing to dist.scripts
        for script_name in self.distribution.scripts or []:
            script_path = os.path.abspath(convert_path(script_name))
            script_name = os.path.basename(script_path)
            f = open(script_path,'rU')
            script_text = f.read()
            f.close()
            self.install_script(dist, script_name, script_text, script_path)





























Index: __init__.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/__init__.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- __init__.py	21 Mar 2005 19:50:46 -0000	1.3
+++ __init__.py	6 Jul 2005 03:46:16 -0000	1.4
@@ -1,6 +1,6 @@
 import distutils.command
 
-__all__ = ['test', 'depends', 'bdist_egg']
+__all__ = ['test', 'develop', 'bdist_egg']
 
 
 # Make our commands available as though they were part of the distutils

Index: easy_install.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/easy_install.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- easy_install.py	6 Jul 2005 02:10:48 -0000	1.1
+++ easy_install.py	6 Jul 2005 03:46:16 -0000	1.2
@@ -126,7 +126,7 @@
         for path_item in self.install_dir, self.script_dir:
             if path_item not in self.shadow_path:
                 self.shadow_path.insert(0, self.install_dir)
-        
+
         if self.package_index is None:
             self.package_index = self.create_index(
                 self.index_url, search_path = self.shadow_path
@@ -207,12 +207,12 @@
         tmpdir = self.alloc_tmp()
         download = None
 
-        try:           
+        try:
             if not isinstance(spec,Requirement):
                 if URL_SCHEME(spec):
                     # It's a url, download it to tmpdir and process
                     download = self.package_index.download(spec, tmpdir)
-                    return self.install_item(None, download, tmpdir, True)                   
+                    return self.install_item(None, download, tmpdir, True)
 
                 elif os.path.exists(spec):
                     # Existing file or directory, just process it directly
@@ -290,40 +290,81 @@
         if self.exclude_scripts or not metadata.metadata_isdir('scripts'):
             return
 
-        from distutils.command.build_scripts import first_line_re
-
         for script_name in metadata.metadata_listdir('scripts'):
-            target = os.path.join(self.script_dir, script_name)
+            self.install_script(
+                dist, script_name,
+                metadata.get_metadata('scripts/'+script_name).replace('\r','\n')
+            )
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 
-            log.info("Installing %s script to %s", script_name,self.script_dir)
 
-            script_text = metadata.get_metadata('scripts/'+script_name)
-            script_text = script_text.replace('\r','\n')
-            first, rest = script_text.split('\n',1)
 
-            match = first_line_re.match(first)
-            options = ''
-            if match:
-                options = match.group(1) or ''
-                if options:
-                    options = ' '+options
 
-            spec = '%s==%s' % (dist.name,dist.version)
 
-            script_text = '\n'.join([
-                "#!%s%s" % (os.path.normpath(sys.executable),options),
-                "# EASY-INSTALL-SCRIPT: %r,%r" % (spec, script_name),
-                "import pkg_resources",
-                "pkg_resources.run_main(%r, %r)" % (spec, script_name)
-            ])
-            if not self.dry_run:
-                f = open(target,"w")
-                f.write(script_text)
-                f.close()
-                try:
-                    os.chmod(target,0755)
-                except (AttributeError, os.error):
-                    pass
+
+
+
+    def install_script(self, dist, script_name, script_text, dev_path=None):
+        log.info("Installing %s script to %s", script_name,self.script_dir)
+        target = os.path.join(self.script_dir, script_name)
+        first, rest = script_text.split('\n',1)
+        from distutils.command.build_scripts import first_line_re
+        match = first_line_re.match(first)
+        options = ''
+        if match:
+            options = match.group(1) or ''
+            if options:
+                options = ' '+options
+        spec = '%s==%s' % (dist.name,dist.version)
+        executable = os.path.normpath(sys.executable)
+
+        if dev_path:
+            script_text = (
+                "#!%(executable)s%(options)s\n"
+                "# EASY-INSTALL-DEV-SCRIPT: %(spec)r,%(script_name)r\n"
+                "from pkg_resources import require; require(%(spec)r)\n"
+                "del require\n"
+                "__file__ = %(dev_path)r\n"
+                "execfile(__file__)\n"
+            ) % locals()
+        else:
+            script_text = (
+                "#!%(executable)s%(options)s\n"
+                "# EASY-INSTALL-SCRIPT: %(spec)r,%(script_name)r\n"
+                "import pkg_resources\n"
+                "pkg_resources.run_main(%(spec)r, %(script_name)r)\n"
+            ) % locals()
+
+        if not self.dry_run:
+            f = open(target,"w")
+            f.write(script_text)
+            f.close()
+            try:
+                os.chmod(target,0755)
+            except (AttributeError, os.error):
+                pass
 
 
     def install_eggs(self, dist_filename, zip_ok, tmpdir):
@@ -373,7 +414,7 @@
         else:
             metadata = EggMetadata(zipimport.zipimporter(egg_path))
         return Distribution.from_filename(egg_path,metadata=metadata)
-        
+
     def install_egg(self, egg_path, zip_ok, tmpdir):
         destination = os.path.join(self.install_dir,os.path.basename(egg_path))
         destination = os.path.abspath(destination)
@@ -443,7 +484,7 @@
             verbose=self.verbose, dry_run=self.dry_run
         )
 
-        # install the .egg        
+        # install the .egg
         return self.install_egg(egg_path, self.zip_ok, tmpdir)
 
 
@@ -474,7 +515,7 @@
 
         # extract, tracking .pyd/.dll->native_libs and .py -> to_compile
         unpack_archive(dist_filename, egg_tmp, process)
-       
+
         for res in native_libs:
             if res.lower().endswith('.pyd'):    # create stubs for .pyd's
                 parts = res.split('/')
@@ -482,9 +523,9 @@
                 pyfile = os.path.join(egg_tmp, *parts)
                 to_compile.append(pyfile)
                 bdist_egg.write_stub(resource, pyfile)
-        
+
         self.byte_compile(to_compile)   # compile .py's
-        
+
         if native_libs:     # write EGG-INFO/native_libs.txt
             nl_txt = os.path.join(egg_tmp, 'EGG-INFO', 'native_libs.txt')
             ensure_directory(nl_txt)
@@ -599,6 +640,7 @@
 
         if dist.name=='setuptools':
             # Ensure that setuptools itself never becomes unavailable!
+            # XXX should this check for latest version?
             f = open(os.path.join(self.install_dir,'setuptools.pth'), 'w')
             f.write(dist.path+'\n')
             f.close()
@@ -612,7 +654,6 @@
 
 
 
-
     def unpack_and_compile(self, egg_path, destination):
         to_compile = []
 
@@ -632,7 +673,7 @@
             # try to make the byte compile messages quieter
             log.set_verbosity(self.verbose - 1)
 
-            byte_compile(to_compile, optimize=0, force=1, dry_run=self.dry_run) 
+            byte_compile(to_compile, optimize=0, force=1, dry_run=self.dry_run)
             if self.optimize:
                 byte_compile(
                     to_compile, optimize=self.optimize, force=1,
@@ -667,7 +708,7 @@
 
         prepended = (endrec[9] - endrec[5]) - endrec[6]
         if prepended < 12:  # no wininst data here
-            return None               
+            return None
         f.seek(prepended-12)
 
         import struct, StringIO, ConfigParser
@@ -683,7 +724,7 @@
             return None
         if not cfg.has_section('metadata') or not cfg.has_section('Setup'):
             return None
-        return cfg              
+        return cfg
 
     finally:
         f.close()

Index: test.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/test.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test.py	6 Jul 2005 01:54:07 -0000	1.2
+++ test.py	6 Jul 2005 03:46:16 -0000	1.3
@@ -4,9 +4,9 @@
 
 class test(Command):
 
-    """Command to run unit tests after installation"""
+    """Command to run unit tests after in-place build"""
 
-    description = "run unit tests after installation"
+    description = "run unit tests after in-place build"
 
     user_options = [
         ('test-module=','m', "Run 'test_suite' in specified module"),



More information about the Python-checkins mailing list