-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_project.py
141 lines (117 loc) · 5.11 KB
/
start_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import re
import fileinput
import os
print(r'''
.______ __ ___ .__ __. __ ___
| _ \ | | / \ | \ | | | |/ /
| |_) | | | / ^ \ | \| | | ' /
| _ < | | / /_\ \ | . ` | | <
| |_) | | `----. / _____ \ | |\ | | . \
|______/ |_______|/__/ \__\ |__| \__| |__|\__\
.______ ____ ____ .___________. __ __ ______ .__ __.
| _ \ \ \ / / | || | | | / __ \ | \ | |
| |_) | \ \/ / `---| |----`| |__| | | | | | | \| |
| ___/ \_ _/ | | | __ | | | | | | . ` |
| | | | | | | | | | | `--' | | |\ |
| _| |__| |__| |__| |__| \______/ |__| \__|
.______ .______ ______ __ _______ ______ .___________.
| _ \ | _ \ / __ \ | | | ____| / || |
| |_) | | |_) | | | | | | | | |__ | ,----'`---| |----`
| ___/ | / | | | | .--. | | | __| | | | |
| | | |\ \----.| `--' | | `--' | | |____ | `----. | |
| _| | _| `._____| \______/ \______/ |_______| \______| |__|
by Jackson Burns
github.com/JacksonBurns/blank-python-project
''')
gh_uname = input("GitHub username: ")
while not re.search(r"^[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}$", gh_uname, re.IGNORECASE):
print('''
Username may only contain alphanumeric characters or hyphens,
cannot have multiple consecutive hyphens, and cannot begin or end with a hyphen.
Maximum length is 39 characters.
''')
gh_uname = input("GitHub username: ")
usr_name = input("Your name: ")
prj_name = input("Name of the project: ")
while not re.search(r"^[a-z\d](?:[a-z\d]|-|_(?=[a-z\d])){0,61}$", prj_name, re.IGNORECASE):
print('''
Project name may only contain alphanumeric characters or hyphens/underscores,
cannot have multiple consecutive hyphens, and cannot begin or end with a hyphen.
Maximum length is 62 characters.
''')
prj_name = input("Name of the project: ")
pypi_name = input("Name for the PyPI package: ")
while not re.search(r"^[a-z\d](?:[a-z\d]|-|_(?=[a-z\d])){0,61}$", pypi_name):
print('''
Package name may only contain lowercase alphanumeric characters or underscores and should be succinct.
''')
pypi_name = input("Name for the PyPI package: ")
slogan = input("Slogan for your project: ")
project_files = [
'pyproject.toml',
'README.md',
'test/test_blankpythonproject.py',
'blankpythonproject/__init__.py',
'blankpythonproject/blankpythonproject.py',
'.github/workflows/CI.yml',
'.github/workflows/gen_docs.yml',
'docs/conf.py',
'docs/index.rst',
'docs/modules.rst',
]
def replace_blanks():
changed = False
for filename in project_files:
with fileinput.FileInput(filename, inplace=True) as file:
for line in file:
if re.search("blankpythonproject", line):
print(line.replace('blankpythonproject', prj_name), end='')
changed = True
elif re.search("BlankPythonProject", line):
print(line.replace('BlankPythonProject', prj_name), end='')
changed = True
elif re.search("blank-python-project", line):
print(line.replace('blank-python-project', prj_name), end='')
changed = True
elif re.search("JacksonBurns", line):
print(line.replace('JacksonBurns', gh_uname), end='')
changed = True
elif re.search("Jackson Burns", line):
print(line.replace('Jackson Burns', usr_name), end='')
changed = True
elif re.search("blpyproj", line):
print(line.replace('blpyproj', pypi_name), end='')
changed = True
elif re.search("Catchy slogan.", line):
print(line.replace('Catchy slogan.', slogan), end='')
changed = True
else:
print(line, end='')
return changed
it_limit = 0
while it_limit < 10:
if not replace_blanks():
break
it_limit += 1
og_dir = os.getcwd()
os.rename('blankpythonproject_logo.png', prj_name + '_logo.png')
os.rename(
os.path.join(og_dir, 'test', 'test_blankpythonproject.py'),
os.path.join(og_dir, 'test', 'test_' + prj_name + '.py'),
)
os.rename(
os.path.join(og_dir, 'examples', 'blankpythonproject_example.ipynb'),
os.path.join(og_dir, 'examples', prj_name + '_example.ipynb'),
)
os.rename(
os.path.join(og_dir, 'blankpythonproject', 'blankpythonproject.py'),
os.path.join(og_dir, 'blankpythonproject', prj_name + '.py'),
)
os.rename('blankpythonproject', prj_name)
print(r'''
...updates complete - delete this file (start_project.py) and make your
first commit to get started.
If you wish to use a license other than MIT, delete the existing LICENSE
file and update pyproject.toml to reflect the new license.
Happy coding!
''')