[kupfer] wscript: Automatically find all Python packages and subpackages



commit 75b889094a09f75af734d246c3e2e797c1dae20c
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Oct 27 20:00:55 2009 +0100

    wscript: Automatically find all Python packages and subpackages
    
    Since we may add any number of subpackages as subpackages in kupfer or
    as plugins, make the wscript find all inside ``kupfer/``
    automatically.

 wscript |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
---
diff --git a/wscript b/wscript
index cccd384..204e7b5 100644
--- a/wscript
+++ b/wscript
@@ -140,13 +140,23 @@ def configure(conf):
 	if "False" in pipe.read():
 		Utils.pprint("YELLOW", "Please add %(PYTHONDIR)s to your sys.path!" % conf.env)
 
-def new_module(bld, name, sources=None):
-	if not sources: sources = name
+def _new_package(bld, name):
+	"""Add module @name to sources to be installed,
+	where the name is the full (relative) path to the package
+	"""
 	obj = bld.new_task_gen("py")
-	obj.find_sources_in_dirs(sources)
+	obj.find_sources_in_dirs(name)
 	obj.install_path = "${PYTHONDIR}/%s" % name
 	return obj
 
+def _find_packages_in_directory(bld, name):
+	"""Go through directory @name and recursively add all
+	Python packages with contents to the sources to be installed
+	"""
+	for dirname, dirs, filenames in os.walk(name):
+		if "__init__.py" in filenames:
+			_new_package(bld, dirname)
+
 def build(bld):
 	# kupfer module version info file
 	version_subst_file = "kupfer/version_subst.py"
@@ -157,9 +167,8 @@ def build(bld):
 		dict = bld.env,
 		)
 
-	# modules
-	new_module(bld, "kupfer")
-	new_module(bld, "kupfer/plugin")
+	# Add all Python packages recursively
+	_find_packages_in_directory(bld, "kupfer")
 
 	# binary
 	# Subst in the python version



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]