77
88
99def git_init () -> None :
10- subprocess .run (
11- [
12- "git" ,
13- "init" ,
14- ]
15- )
16-
17- subprocess .run (
18- [
19- "git" ,
20- "add" ,
21- "." ,
22- ]
23- )
10+ subprocess .run (["git" , "init" ])
11+ subprocess .run (["git" , "add" , "." ])
2412
2513
2614def uv_init () -> None :
27- subprocess .run (
28- [
29- "uv" ,
30- "lock" ,
31- ]
32- )
15+ subprocess .run (["uv" , "lock" ])
3316
3417
3518def lint () -> None :
36- subprocess .run (
37- [
38- "make" ,
39- "lint" ,
40- ]
41- )
19+ subprocess .run (["make" , "lint" ])
4220
4321
4422def make_env () -> None :
45- subprocess .run (
46- [
47- "cp" ,
48- ".env.example" ,
49- ".env" ,
50- ]
51- )
23+ subprocess .run (["cp" , ".env.example" , ".env" ])
5224
5325
5426def _get_delete_flagged () -> tuple [list [str ], list [str ]]:
@@ -80,6 +52,37 @@ def _get_delete_flagged() -> tuple[list[str], list[str]]:
8052 return files , folders
8153
8254
55+ def delete_empty_init_folders (root_dir : str = "src" ) -> None :
56+ """Delete folders that only contain empty __init__.py files."""
57+ for dirpath , dirnames , filenames in os .walk (root_dir , topdown = False ):
58+ # Skip the root directory itself
59+ if dirpath == root_dir :
60+ continue
61+
62+ if set (filenames ) == {"__init__.py" } and not dirnames :
63+ init_file = os .path .join (dirpath , "__init__.py" )
64+
65+ try :
66+ with open (init_file , "r" ) as f :
67+ content = f .read ()
68+ has_code = any (
69+ line .strip () and not line .strip ().startswith ("#" )
70+ for line in content .splitlines ()
71+ )
72+ if "__all__ = []" in content :
73+ print (45747457745 )
74+ else :
75+ print (123123123 )
76+ if not has_code :
77+ os .remove (init_file )
78+ os .rmdir (dirpath )
79+ logger .info (f"Deleted empty package: { dirpath } " )
80+ else :
81+ logger .info (f"Keeping package with code: { dirpath } " )
82+ except OSError as exc :
83+ logger .info (f"Error processing package { dirpath } : { exc } " )
84+
85+
8386def cleanup ():
8487 files , folders = _get_delete_flagged ()
8588
@@ -97,6 +100,8 @@ def cleanup():
97100 except OSError as exc :
98101 logger .info (f"Error deleting folder { folder_path } : { exc } " )
99102
103+ delete_empty_init_folders ()
104+
100105
101106if __name__ == "__main__" :
102107 cleanup ()
0 commit comments