Browse files

Merge pull request #67 from reinout/reinout-33-cornercase

Fix for #64: __pycache__ dir inside distutils scripts metadata directory
  • Loading branch information...
2 parents a31ae81 + 7c397c5 commit 3bf9b96ce6550b46c7504d799bf2c3ca0f26c529 Jim Fulton committed Feb 14, 2013
Showing with 24 additions and 0 deletions.
  1. +7 −0 CHANGES.rst
  2. +3 −0 src/zc/buildout/easy_install.py
  3. +14 −0 src/zc/buildout/easy_install.txt
View
7 CHANGES.rst
@@ -1,6 +1,13 @@
Change History
**************
+Next version
+============
+
+- Fix for distutils scripts installation on Python 3, related to
+ ``__pycache__`` directories.
+
+
2.0.0 (2013-02-10)
==================
View
3 src/zc/buildout/easy_install.py
@@ -915,6 +915,9 @@ def scripts(reqs, working_set, executable, dest=None,
# /EGG-INFO/scripts/.
if dist.metadata_isdir('scripts'):
for name in dist.metadata_listdir('scripts'):
+ if dist.metadata_isdir('scripts/' + name):
+ # Probably Python 3 __pycache__ directory.
+ continue
contents = dist.get_metadata('scripts/' + name)
distutils_scripts.append((name, contents))
else:
View
14 src/zc/buildout/easy_install.txt
@@ -957,6 +957,20 @@ contain a source encoding hint; buildout retains it.
Due to the nature of distutils scripts, buildout cannot pass arguments as
there's no specific method to pass them to.
+In some cases, a python 3 ``__pycache__`` directory can end up in an internal
+``EGG-INFO`` metadata directory, next to the script information we're looking
+for. Buildout doesn't crash on that:
+
+ >>> eggname = [name for name in os.listdir(distdir2)
+ ... if name.endswith('egg')][0]
+ >>> scripts_metadata_dir = os.path.join(
+ ... distdir2, eggname, 'EGG-INFO', 'scripts')
+ >>> os.mkdir(os.path.join(scripts_metadata_dir, '__dummy__'))
+ >>> scripts = zc.buildout.easy_install.scripts(
+ ... ['du_zipped'], ws, sys.executable, distbin2)
+ >>> ls(distbin2)
+ - distutilsscript
+
Handling custom build options for extensions provided in source distributions
-----------------------------------------------------------------------------

4 comments on commit 3bf9b96

@regebro

Wouldn't it be better to simply just skip __pycache__ instead of skipping all directories, because they "probably" are the __pycache__ directory?

@reinout

Scripts cannot be directories. So omitting directories safeguards us against any possible future weirdness.

@regebro

That makes sense. The comment ought to be specific about that, though.

@mgedmin
buildout member

dist.get_metadata('scripts/' + name) will raise an error when 'scripts/' + name points to a directory, even when that directory is not __pycache__.

Please sign in to comment.