-
Notifications
You must be signed in to change notification settings - Fork 2
/
monorepo_setup.py
48 lines (39 loc) · 1.62 KB
/
monorepo_setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import subprocess
ROOT_DIRECTORY = os.path.dirname(os.path.abspath(__file__))
# function to run poetry init command in the current directory
def run_poetry_init():
try:
print("Running poetry init...")
subprocess.run(["poetry", "init", "--no-interaction"],
check=True,
text=True,
input="\n")
print("Poetry initialized successfully.")
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
def run_poetry_install():
try:
print("Running poetry install...")
subprocess.run(["poetry", "install"], check=True, text=True, input="\n")
print("Poetry dependencies installed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
def process_directories(root_dir: str, command: str):
"""Iterate through subdirectories recursively"""
for directory in os.listdir(root_dir):
if directory[0] != '.' and os.path.isdir(directory):
print(directory)
os.chdir(directory)
if command == 'init':
print(f"\nInitializing poetry in directory: {directory}")
run_poetry_init()
elif command == 'install':
print(f"\nRunning poetry install in directory: {directory}")
run_poetry_install()
os.chdir(root_dir)
if __name__ == "__main__":
process_directories(root_dir=ROOT_DIRECTORY, command='init')
# for directory in os.listdir(ROOT_DIRECTORY):
# if directory[0] != '.' and os.path.isdir(directory):
# print(directory)