summaryrefslogtreecommitdiff
path: root/distutils2/command/build_py.py
diff options
context:
space:
mode:
Diffstat (limited to 'distutils2/command/build_py.py')
-rw-r--r--distutils2/command/build_py.py51
1 files changed, 12 insertions, 39 deletions
diff --git a/distutils2/command/build_py.py b/distutils2/command/build_py.py
index c24a13b..0b6b247 100644
--- a/distutils2/command/build_py.py
+++ b/distutils2/command/build_py.py
@@ -8,7 +8,6 @@ import sys
import logging
from glob import glob
-import distutils2
from distutils2.command.cmd import Command
from distutils2.errors import DistutilsOptionError, DistutilsFileError
from distutils2.util import convert_path
@@ -66,10 +65,9 @@ class build_py(Command, Mixin2to3):
self.packages = self.distribution.packages
self.py_modules = self.distribution.py_modules
self.package_data = self.distribution.package_data
- self.package_dir = {}
- if self.distribution.package_dir:
- for name, path in self.distribution.package_dir.items():
- self.package_dir[name] = convert_path(path)
+ self.package_dir = None
+ if self.distribution.package_dir is not None:
+ self.package_dir = convert_path(self.distribution.package_dir)
self.data_files = self.get_data_files()
# Ick, copied straight from install_lib.py (fancy_getopt needs a
@@ -164,11 +162,13 @@ class build_py(Command, Mixin2to3):
Helper function for `run()`.
"""
+ # FIXME add tests for this method
for package, src_dir, build_dir, filenames in self.data_files:
for filename in filenames:
target = os.path.join(build_dir, filename)
+ srcfile = os.path.join(src_dir, filename)
self.mkpath(os.path.dirname(target))
- outf, copied = self.copy_file(os.path.join(src_dir, filename),
+ outf, copied = self.copy_file(srcfile,
target, preserve_mode=False)
if copied and srcfile in self.distribution.convert_2to3.doctests:
self._doctests_2to3.append(outf)
@@ -179,41 +179,14 @@ class build_py(Command, Mixin2to3):
"""Return the directory, relative to the top of the source
distribution, where package 'package' should be found
(at least according to the 'package_dir' option, if any)."""
-
path = package.split('.')
+ if self.package_dir is not None:
+ path.insert(0, self.package_dir)
- if not self.package_dir:
- if path:
- return os.path.join(*path)
- else:
- return ''
- else:
- tail = []
- while path:
- try:
- pdir = self.package_dir['.'.join(path)]
- except KeyError:
- tail.insert(0, path[-1])
- del path[-1]
- else:
- tail.insert(0, pdir)
- return os.path.join(*tail)
- else:
- # Oops, got all the way through 'path' without finding a
- # match in package_dir. If package_dir defines a directory
- # for the root (nameless) package, then fallback on it;
- # otherwise, we might as well have not consulted
- # package_dir at all, as we just use the directory implied
- # by 'tail' (which should be the same as the original value
- # of 'path' at this point).
- pdir = self.package_dir.get('')
- if pdir is not None:
- tail.insert(0, pdir)
-
- if tail:
- return os.path.join(*tail)
- else:
- return ''
+ if len(path) > 0:
+ return os.path.join(*path)
+
+ return ''
def check_package(self, package, package_dir):
"""Helper function for `find_package_modules()` and `find_modules()'.