-
Notifications
You must be signed in to change notification settings - Fork 0
/
.create_project.py
executable file
·122 lines (101 loc) · 3.29 KB
/
.create_project.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import sys
def create_project_structure(project_name):
# Create project directory
os.makedirs(project_name, exist_ok=True)
os.chdir(project_name)
# Create src directory
os.makedirs(f"src/{project_name}", exist_ok=True)
# Create main project file with example class
with open(f"src/{project_name}/{project_name}.py", "w") as f:
f.write(f"""
class ExampleClass:
def __init__(self, name):
self.name = name
def greet(self):
return f"Hello, {{self.name}}!"
def main():
example = ExampleClass("World")
print(example.greet())
if __name__ == "__main__":
main()
""")
# Create empty __init__.py
open(f"src/{project_name}/__init__.py", 'a').close()
# Create setup.py
with open("setup.py", "w") as f:
f.write(f"""
from setuptools import setup, find_packages
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setup(
name="{project_name}",
version="0.1.0",
author="Tom Sapletta",
author_email="[email protected]",
description="",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://python.dobyemail.com",
packages=find_packages(where="src"),
package_dir={{"": "src"}},
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
install_requires=[
# Add your project dependencies here
],
entry_points={{
'console_scripts': [
'{project_name}={project_name}.{project_name}:main',
],
}},
)
""")
# Create README.md
with open("README.md", "w") as f:
f.write(f"# {project_name.capitalize()}\n\nDescription of your project goes here.")
# Create requirements.txt
open("requirements.txt", 'a').close()
# Create tests directory with updated test file
os.makedirs("tests", exist_ok=True)
with open("tests/test_" + project_name + ".py", "w") as f:
f.write(f"""
import unittest
from {project_name}.{project_name} import ExampleClass
class Test{project_name.capitalize()}(unittest.TestCase):
def test_example_class(self):
example = ExampleClass("Test")
self.assertEqual(example.greet(), "Hello, Test!")
if __name__ == '__main__':
unittest.main()
""")
# Create config file
create_config_file(project_name)
print(f"Project structure for {project_name} has been created.")
def create_config_file(project_name):
config_content = f"""
[{project_name}]
debug = false
log_level = INFO
[database]
host = localhost
port = 5432
name = {project_name}_db
"""
with open(f"config.ini", "w") as f:
f.write(config_content)
if __name__ == "__main__":
project_name = input("Enter the name of your project: ").strip()
if not project_name:
print("Error: Project name cannot be empty.")
sys.exit(1)
create_project_structure(project_name)