From 6b58bddb8e7aae49f5cb2e68fe08c6d9e1fd5aa5 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Fri, 11 Oct 2024 18:08:19 +0200
Subject: [PATCH] Add --find-imports option

---
 apa | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/apa b/apa
index c1932a9..c162fef 100755
--- a/apa
+++ b/apa
@@ -151,6 +151,9 @@ if __name__ == '__main__':
     optParser.add_option('--filter-imports',
                          action='store_true',
                          help='Filter out files that are not imported')
+    optParser.add_option('--find-imports',
+                         action='store_true',
+                         help='Add files below CWD imported from MAIN')
     (options, args) = optParser.parse_args(sys.argv[1:])
 
     if options.documentation:
@@ -171,6 +174,13 @@ if __name__ == '__main__':
         args = [ keep[0] ] + sorted(keep[1:])
         pass
 
+    if options.find_imports:
+        visitor = ImportVisitor(args[0])
+        imported = [ os.path.normpath(f) for f in visitor.find_all_imports() ]
+        given = [ os.path.normpath(f) for f in args ]
+        args = [ given[0] ] + list(sorted(set(imported) | set(given[1:])))
+        pass
+
     # Read all python files
     code = []
     processed = set()
-- 
GitLab