Commits

Ronny Pfannschmidt committed b2dda2e

add support for toplevel modules

  • Participants
  • Parent commits bbce811

Comments (0)

Files changed (2)

File genscript/pkgpacker.py

         lib = base/name
         if lib.check(dir=1):
             return lib
+        mod = lib + '.py'
+        if mod.check(file=1):
+            return mod
     raise LookupError(name)
 
 def pkgname(toplevel, rootpath, path):
 
 def pkg_to_mapping(name):
     toplevel = find_toplevel(name)
+    if toplevel.check(file=1):
+        return {name: toplevel.read()}
+
     name2src = {}
     for pyfile in toplevel.visit('*.py'):
         pkg = pkgname(name, toplevel, pyfile)

File testing/test_walkpkg.py

     }
     assert mapping == expected
 
+def test_pkg_to_mapping_for_module(tmpdir, monkeypatch):
+    monkeypatch.setattr(pkgpacker, 'find_toplevel', lambda x:test)
+    test = tmpdir.join('test.py')
+    test.write('#test\n')
+
+    mapping = pkg_to_mapping('test')
+    assert mapping == { 'test': '#test\n' }
+
+