[Checkins] SVN: zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py Got distutils script to be detected in unzipped eggs.

Reinout van Rees reinout at vanrees.org
Fri Sep 4 07:01:13 EDT 2009


Log message for revision 103528:
  Got distutils script to be detected in unzipped eggs.
  Contents still needs to be copied over.
  Zipped eggs might not work.
  Anyway, I got *something* working.

Changed:
  U   zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py

-=-
Modified: zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py
===================================================================
--- zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py	2009-09-04 08:11:15 UTC (rev 103527)
+++ zc.buildout/branches/reinout-scripts/src/zc/buildout/easy_install.py	2009-09-04 11:01:13 UTC (rev 103528)
@@ -932,12 +932,21 @@
         if isinstance(req, str):
             req = pkg_resources.Requirement.parse(req)
             dist = working_set.find(req)
+            # entry points
             for name in pkg_resources.get_entry_map(dist, 'console_scripts'):
                 entry_point = dist.get_entry_info('console_scripts', name)
                 entry_points.append(
                     (name, entry_point.module_name,
                      '.'.join(entry_point.attrs))
                     )
+            # distutils scripts
+            if os.path.isdir(dist.location):
+                # TODO: what about zipped eggs?
+                scripts_dir = os.path.join(dist.location, 'EGG-INFO', 'scripts')
+                if os.path.exists(scripts_dir):
+                    for name in os.listdir(scripts_dir):
+                        distutils_scripts.append(
+                            (name, os.path.join(scripts_dir, name)))
         else:
             entry_points.append(req)
 
@@ -957,6 +966,23 @@
                     initialization, rpsetup)
             )
 
+    # TODO: integrate distutils_scripts
+    for name, full_script_path in distutils_scripts:
+        if scripts is not None:
+            sname = scripts.get(name)
+            if sname is None:
+                continue
+        else:
+            sname = name
+
+        sname = os.path.join(dest, sname)
+        spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths)
+
+        generated.extend(
+            _distutils_script(spath, sname, full_script_path,
+                              executable, initialization, rpsetup)
+            )
+
     if interpreter:
         sname = os.path.join(dest, interpreter)
         spath, rpsetup = _relative_path_and_setup(sname, path, relative_paths)
@@ -1027,10 +1053,6 @@
 
 def _script(module_name, attrs, path, dest, executable, arguments,
             initialization, rsetup):
-    generated = []
-    script = dest
-    if is_win32:
-        dest += '-script.py'
 
     contents = script_template % dict(
         python = _safe_arg(executable),
@@ -1041,6 +1063,28 @@
         initialization = initialization,
         relative_paths_setup = rsetup,
         )
+    return _create_script(contents, dest)
+
+
+def _distutils_script(path, dest, original_file, executable, initialization, rsetup):
+
+    original_content = "TODO, strip first line from original_file"
+    contents = distutils_script_template % dict(
+        python = _safe_arg(executable),
+        path = path,
+        initialization = initialization,
+        relative_paths_setup = rsetup,
+        original_content = original_content
+        )
+    return _create_script(contents, dest)
+
+
+def _create_script(contents, dest):
+    generated = []
+    script = dest
+    if is_win32:
+        dest += '-script.py'
+
     changed = not (os.path.exists(dest) and open(dest).read() == contents)
 
     if is_win32:
@@ -1064,6 +1108,7 @@
     generated.append(dest)
     return generated
 
+
 if is_jython and jython_os_name == 'linux':
     script_header = '#!/usr/bin/env %(python)s'
 else:
@@ -1084,7 +1129,19 @@
     %(module_name)s.%(attrs)s(%(arguments)s)
 '''
 
+distutils_script_template = script_header + '''\
 
+%(relative_paths_setup)s
+import sys
+sys.path[0:0] = [
+  %(path)s,
+  ]
+%(initialization)s
+
+%(original_content)s
+'''
+
+
 def _pyscript(path, dest, executable, rsetup):
     generated = []
     script = dest



More information about the checkins mailing list