File tree 1 file changed +26
-0
lines changed 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
1
+ # import_modules.py
2
+ import os
3
+
4
+ def dynamic_import_modules ():
5
+ app_dir = os .path .join (os .path .dirname (__file__ ), 'app' )
6
+ import_modules_path = os .path .join (os .path .dirname (__file__ ), 'dynamic_import_modules.py' )
7
+
8
+ try :
9
+ with open (import_modules_path , 'w' ) as f :
10
+ f .write ("# This file is auto-generated by dynamic_import_modules.py\n " )
11
+ f .write ("import sys\n " )
12
+ f .write ("sys.path.append(os.path.join(os.path.dirname(__file__), 'app'))\n \n " )
13
+
14
+ for root , dirs , files in os .walk (app_dir ):
15
+ for file in files :
16
+ if file .startswith ('sys_' ) and file .endswith ('.py' ):
17
+ module_name = file [:- 3 ] # Remove .py extension
18
+ f .write (f"from { module_name } import *\n " )
19
+
20
+ print (f"Generated imports in { import_modules_path } " )
21
+ except Exception as e :
22
+ print (f"An error occurred while generating imports: { e } " )
23
+
24
+ if __name__ == "__main__" :
25
+ dynamic_import_modules ()
26
+
You can’t perform that action at this time.
0 commit comments