Fixed a couple of long-hidden bugs (amazing what you find when you
attempt to verify the bold assertions in the documentation): * entries for the "root package" in 'package_dir' didn't work -- fixed by improving the fall-through code in 'get_package_dir()' * __init__.py files weren't installed when modules-in-packages were listed individually (ie. in 'py_modules' in the setup script); fixed by making 'check_package()' return the name of the __init__ file if it exists, and making 'find_modules()' add an entry to the module list for __init__ if applicable
This commit is contained in:
parent
8415edb433
commit
8bbba17d38
|
@ -117,8 +117,17 @@ class build_py (Command):
|
||||||
tail.insert (0, pdir)
|
tail.insert (0, pdir)
|
||||||
return apply (os.path.join, tail)
|
return apply (os.path.join, tail)
|
||||||
else:
|
else:
|
||||||
# arg! everything failed, we might as well have not even
|
# Oops, got all the way through 'path' without finding a
|
||||||
# looked in package_dir -- oh well
|
# 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:
|
if tail:
|
||||||
return apply (os.path.join, tail)
|
return apply (os.path.join, tail)
|
||||||
else:
|
else:
|
||||||
|
@ -145,9 +154,16 @@ class build_py (Command):
|
||||||
# Require __init__.py for all but the "root package"
|
# Require __init__.py for all but the "root package"
|
||||||
if package:
|
if package:
|
||||||
init_py = os.path.join (package_dir, "__init__.py")
|
init_py = os.path.join (package_dir, "__init__.py")
|
||||||
if not os.path.isfile (init_py):
|
if os.path.isfile (init_py):
|
||||||
|
return init_py
|
||||||
|
else:
|
||||||
self.warn (("package init file '%s' not found " +
|
self.warn (("package init file '%s' not found " +
|
||||||
"(or not a regular file)") % init_py)
|
"(or not a regular file)") % init_py)
|
||||||
|
|
||||||
|
# Either not in a package at all (__init__.py not expected), or
|
||||||
|
# __init__.py doesn't exist -- so don't return the filename.
|
||||||
|
return
|
||||||
|
|
||||||
# check_package ()
|
# check_package ()
|
||||||
|
|
||||||
|
|
||||||
|
@ -177,6 +193,15 @@ class build_py (Command):
|
||||||
|
|
||||||
|
|
||||||
def find_modules (self):
|
def find_modules (self):
|
||||||
|
"""Finds individually-specified Python modules, ie. those listed by
|
||||||
|
module name in 'self.modules'. Returns a list of tuples (package,
|
||||||
|
module_base, filename): 'package' is a tuple of the path through
|
||||||
|
package-space to the module; 'module_base' is the bare (no
|
||||||
|
packages, no dots) module name, and 'filename' is the path to the
|
||||||
|
".py" file (relative to the distribution root) that implements the
|
||||||
|
module.
|
||||||
|
"""
|
||||||
|
|
||||||
# Map package names to tuples of useful info about the package:
|
# Map package names to tuples of useful info about the package:
|
||||||
# (package_dir, checked)
|
# (package_dir, checked)
|
||||||
# package_dir - the directory where we'll find source files for
|
# package_dir - the directory where we'll find source files for
|
||||||
|
@ -185,7 +210,7 @@ class build_py (Command):
|
||||||
# is valid (exists, contains __init__.py, ... ?)
|
# is valid (exists, contains __init__.py, ... ?)
|
||||||
packages = {}
|
packages = {}
|
||||||
|
|
||||||
# List of (module, package, filename) tuples to return
|
# List of (package, module, filename) tuples to return
|
||||||
modules = []
|
modules = []
|
||||||
|
|
||||||
# We treat modules-in-packages almost the same as toplevel modules,
|
# We treat modules-in-packages almost the same as toplevel modules,
|
||||||
|
@ -205,8 +230,10 @@ class build_py (Command):
|
||||||
checked = 0
|
checked = 0
|
||||||
|
|
||||||
if not checked:
|
if not checked:
|
||||||
self.check_package (package, package_dir)
|
init_py = self.check_package (package, package_dir)
|
||||||
packages[package] = (package_dir, 1)
|
packages[package] = (package_dir, 1)
|
||||||
|
if init_py:
|
||||||
|
modules.append((package, "__init__", init_py))
|
||||||
|
|
||||||
# XXX perhaps we should also check for just .pyc files
|
# XXX perhaps we should also check for just .pyc files
|
||||||
# (so greedy closed-source bastards can distribute Python
|
# (so greedy closed-source bastards can distribute Python
|
||||||
|
@ -215,7 +242,7 @@ class build_py (Command):
|
||||||
if not self.check_module (module, module_file):
|
if not self.check_module (module, module_file):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
modules.append ((package, module, module_file))
|
modules.append ((package, module_base, module_file))
|
||||||
|
|
||||||
return modules
|
return modules
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue