Refactor experimental demo into final state for developing the game
[base2-runner.git] / engine / __init__.py
diff --git a/engine/__init__.py b/engine/__init__.py
new file mode 100644 (file)
index 0000000..b0fef8a
--- /dev/null
@@ -0,0 +1,48 @@
+#!/usr/bin/python3
+# (c) Copyright 2013 TJ <hacker@iam.tj>
+# Licensed on the terms of the GNU General Public License version 3 (see COPYING)
+
+__all__ = ["Game", "Channel", "SeamlessBackground", "logging"]
+
+"""
+ this code allows us to use the Java packaging convention of one file per class and
+ still have each class exist in the package namespace, rather than in a sub-module
+ namespace.
+
+ E.g: given the following directory structure:
+
+ package/
+         module1.py
+            Class mod1Class
+         module2.py
+            Class mod2Class
+         module3.py
+            Class mod3Class
+
+If our code did:
+
+ import engine
+
+The classes would be accessed using these namespaces:
+ package.module1.mod1Class
+ package.module2.mod2Class
+ package.module3.mod3Class
+
+But we'd prefer to acccess them as:
+ package.mod1Class
+ package.mod2Class
+ package.mod3Class
+
+Therefore, when this package is loaded it reads the __all__ attribute which contains
+a list of the module names to be included in the package namespace. An import statement
+is created dynamically and then executed of the form "from .module_name import *".
+
+The leading "." is required to ensure that the current (package) directory is searched for
+the module file.
+
+This is needed because a static statement "from module_name import *" will not evaluate 
+"module_name" as a variable; instead it'll treat it as the literal module of that name.
+"""
+for module_name in __all__:
+ cmd = "from .%s import *" % module_name
+ exec(cmd)