-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_creator.py
48 lines (37 loc) · 1.4 KB
/
env_creator.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
def create_environment(project_name:str, requirements:list)->None:
# create file setup.py
with open("setup.py", "w") as f:
f.write("from setuptools import setup, find_packages\n")
f.write("setup(name='"+project_name+"', version='1.0', packages=find_packages())")
# create project folder
os.mkdir(project_name)
# create __init__.py in project folder
with open(project_name+"/__init__.py", "w") as f:
f.write("")
# create requirements.txt
with open("requirements.txt", "w") as f:
for req in requirements:
f.write(req+"\n")
# create README.md
with open("README.md", "w") as f:
f.write(f"# {project_name}\n")
# create virtual environment
os.system("python -m venv venv")
# create activate.bat
with open("activate.bat", "w") as f:
f.write("venv\\Scripts\\activate.bat\n")
f.close()
# create deactivate.bat
with open("deactivate.bat", "w") as f:
f.write("venv\\Scripts\\deactivate.bat\n")
f.close()
# run activate.bat
os.system('''
activate.bat & pip install -r requirements.txt & pip install -e .
''')
# create gitignore file and add venv folder
with open(".gitignore", "w") as f:
f.write("\\venv\n")
if __name__ == '__main__':
create_environment('python_learn', ['numpy', 'pandas'])