From 6b98bfa7af575cf3d37ae7dbb02ba0bc4e80dca6 Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Fri, 11 Oct 2024 18:07:02 +0200 Subject: [PATCH] Fix bug in import handling --- apa | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/apa b/apa index e450791..c1932a9 100755 --- a/apa +++ b/apa @@ -111,25 +111,13 @@ class ImportVisitor(ast.NodeVisitor): def visit_Import(self, node): for name in [ n.name for n in node.names ]: self.add_import(name, '.'.join(name.split('.')[0:-1])) - continue - print("X",name) - sub_path = name.replace('.', '/') - full_path = os.path.join(self.root_dir, sub_path) - if os.path.isdir(full_path): - # We need to look for __init__.py for module - self.add_file(os.path.join(full_path, '__init__.py'), - module=name) - pass - else: - self.add_file(full_path + '.py', module=self.module) - pass pass ast.NodeVisitor.generic_visit(self, node) pass def visit_ImportFrom(self, node): for name in [ n.name for n in node.names ]: - module = node.module if node.module else self.module + module = '.'.join([ s for s in [self.module, node.module] if s]) module = module.split('.') if module else [] if node.level > 1: module = module[0:-node.level+1] @@ -144,7 +132,7 @@ class ImportVisitor(ast.NodeVisitor): if __name__ == '__main__': - usage = "%prog [options] <main module> <additional modules>*" + usage = "%prog [options] MAIN <additional modules>*" optParser = optparse.OptionParser(usage=usage) optParser.add_option('-d','--documentation', action='store_true', @@ -162,7 +150,7 @@ if __name__ == '__main__': help='Strip this part from filenames') optParser.add_option('--filter-imports', action='store_true', - help='Filter out fies that are not imported') + help='Filter out files that are not imported') (options, args) = optParser.parse_args(sys.argv[1:]) if options.documentation: @@ -170,6 +158,10 @@ if __name__ == '__main__': sys.exit(0) pass + if args == []: + raise Exception('No MAIN module specified') + sys.exit(1) + if options.filter_imports: # Only add imported modules to archive visitor = ImportVisitor(args[0]) -- GitLab