-
Notifications
You must be signed in to change notification settings - Fork 2
/
distutils_extensions.py
58 lines (47 loc) · 2.25 KB
/
distutils_extensions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#------------------------------------------------------------------------
#
# PyGUI - Distutils hackery
#
#------------------------------------------------------------------------
import os, sys
from glob import glob
from distutils.dist import Distribution
if sys.version_info >= (3, 0):
try:
from distutils.command.build_py import build_py_2to3 as build_py
except ImportError:
raise ImportError("build_py_2to3 not found in distutils - it is required for Python 3.x")
else:
from distutils.command.build_py import build_py
#------------------------------------------------------------------------
class pygui_build_py(build_py):
"""
An extension of the distutils build_py command that supports
gathering .py files for a package from multiple source directories.
It provides a new option 'package_subdirs' that is a mapping from
a package name to a list of directory paths:
package_subdirs = {'package_name': ['source_dir', ...], ...}
The directory paths are interpreted relative to the primary source
directory for the package. In addition to .py files from the primary
source directory, any .py files from the specified directories will be
copied into the package during installation.
"""
Distribution.package_subdirs = {}
def initialize_options(self):
build_py.initialize_options(self)
self.package_subdirs = {}
def finalize_options(self):
build_py.finalize_options(self)
self.package_subdirs = self.distribution.package_subdirs
def find_package_modules(self, package, package_dir):
#print "distutils_extensions: Searching subdirectories of package", repr(package) ###
modules = build_py.find_package_modules(self, package, package_dir)
subdirs = self.package_subdirs.get(package, ())
for subdir in subdirs:
#print "Looking in subdir", repr(subdir), "of", repr(package_dir) ###
module_files = glob(os.path.join(package_dir, subdir, "*.py"))
for f in module_files:
module = os.path.splitext(os.path.basename(f))[0]
#print "Found module", repr(module), "in", repr(f) ###
modules.append((package, module, f))
return modules