[Checkins] SVN: martian/trunk/src/martian/scan. Move the
exclude_filter argument to the __init__ of ModuleInfo class.
Jan-Wijbrand Kolman
janwijbrand at gmail.com
Tue Oct 2 04:51:05 EDT 2007
Log message for revision 80468:
Move the exclude_filter argument to the __init__ of ModuleInfo class.
Changed:
U martian/trunk/src/martian/scan.py
U martian/trunk/src/martian/scan.txt
-=-
Modified: martian/trunk/src/martian/scan.py
===================================================================
--- martian/trunk/src/martian/scan.py 2007-10-02 08:39:01 UTC (rev 80467)
+++ martian/trunk/src/martian/scan.py 2007-10-02 08:51:04 UTC (rev 80468)
@@ -31,13 +31,14 @@
class ModuleInfo(object):
implements(IModuleInfo)
-
- def __init__(self, path, dotted_name):
+
+ def __init__(self, path, dotted_name, exclude_filter=lambda name:False):
# Normalize .pyc files to .py
if path.endswith('c'):
path = path[:-1]
self.path = path
self.dotted_name = dotted_name
+ self.exclude_filter = exclude_filter
name_parts = dotted_name.split('.')
self.name = name_parts[-1]
@@ -60,7 +61,7 @@
"""
return os.path.join(os.path.dirname(self.path), name)
- def getSubModuleInfos(self, exclude_filter=lambda x:False):
+ def getSubModuleInfos(self):
if not self.isPackage():
return []
directory = os.path.dirname(self.path)
@@ -70,7 +71,7 @@
entry_path = os.path.join(directory, entry)
name, ext = os.path.splitext(entry)
dotted_name = self.dotted_name + '.' + name
- if exclude_filter(name):
+ if self.exclude_filter(name):
continue
# Case one: modules
if (os.path.isfile(entry_path) and ext in ['.py', '.pyc']):
@@ -100,8 +101,8 @@
'%s.%s' % (self.package_dotted_name, name))
else:
return None
-
+
def getAnnotation(self, key, default):
key = key.replace('.', '_')
key = '__%s__' % key
@@ -120,12 +121,12 @@
return "<ModuleInfo object for '%s'>" % self.dotted_name
-def module_info_from_dotted_name(dotted_name):
+def module_info_from_dotted_name(dotted_name, exclude_filter=lambda name:False):
module = resolve(dotted_name)
- return ModuleInfo(module.__file__, dotted_name)
+ return ModuleInfo(module.__file__, dotted_name, exclude_filter)
-def module_info_from_module(module):
- return ModuleInfo(module.__file__, module.__name__)
+def module_info_from_module(module, exclude_filter=lambda name:False):
+ return ModuleInfo(module.__file__, module.__name__, exclude_filter)
# taken from zope.dottedname.resolve
Modified: martian/trunk/src/martian/scan.txt
===================================================================
--- martian/trunk/src/martian/scan.txt 2007-10-02 08:39:01 UTC (rev 80467)
+++ martian/trunk/src/martian/scan.txt 2007-10-02 08:51:04 UTC (rev 80468)
@@ -7,7 +7,7 @@
process.
>>> from martian.scan import module_info_from_dotted_name
-
+
We have provided a special test fixture package called stoneage that we are
going to scan, in ``martian.tests.stoneage``.
@@ -19,12 +19,12 @@
``cave`` module in the stone-age package::
>>> module_info = module_info_from_dotted_name('martian.tests.stoneage.cave')
-
+
We get a ``ModuleInfo`` object representing the ``cave module::
>>> module_info
<ModuleInfo object for 'martian.tests.stoneage.cave'>
-
+
``cave`` is a module, not a package.
>>> module_info.isPackage()
@@ -188,11 +188,12 @@
nor 'ftests' we could do::
>>> from martian.scan import ModuleInfo, module_info_from_dotted_name
+ >>> no_tests_filter = lambda x: x in ['tests', 'ftests']
>>> module_info = module_info_from_dotted_name(
- ... 'martian.tests.withtestsmodules')
+ ... 'martian.tests.withtestsmodules', exclude_filter=no_tests_filter)
>>> module_info
<ModuleInfo object for 'martian.tests.withtestsmodules'>
>>> no_tests_filter = lambda x: x in ['tests', 'ftests']
- >>> print module_info.getSubModuleInfos(exclude_filter=no_tests_filter)
+ >>> print module_info.getSubModuleInfos()
[<ModuleInfo object for 'martian.tests.withtestsmodules.subpackage'>]
More information about the Checkins
mailing list