Skip to content

Commit cf7469d

Browse files
nicolasfrippNicolas Fripp
andauthored
Rename project script (#68)
* script added * template fixed * remove comments * readme modified * more changes in readme * more changes in readme --------- Co-authored-by: Nicolas Fripp <[email protected]>
1 parent fbe50d5 commit cf7469d

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ For making code changes, installing `pre-commit` is necessary (see section [Code
3030

3131
### Customization
3232

33-
The project's name (`python-template`) can be edited following next steps:
34-
35-
1. Edit project's name in the [pyproject.toml](pyproject.toml) file
36-
2. Set `PROJECT_NAME` env variable to be exactly the same as project's name in pyproject.toml. Ensure VSCode has this
37-
variable loaded, otherwise the dev container might fail or not work as expected. You can open VScode with from cmd with:
33+
To rename the project `python-template`, you need to run `uv run python scripts/rename-template.py <new-project-name>`
3834

3935
```bash
4036
PROJECT_NAME=your-awesome-project code <path/to/repo>

scripts/rename-template.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
import argparse
3+
import glob
4+
import os
5+
6+
paths_to_replace = [
7+
"src/**/*.py",
8+
"tests/**/*.py",
9+
"Dockerfile",
10+
".env.example",
11+
".devcontainer/**/*",
12+
"uv.lock",
13+
"pyproject.toml",
14+
".github/workflows/python-app.yml",
15+
"scripts/**/*",
16+
"scripts/**/*",
17+
".env"
18+
]
19+
20+
def rename_template(new_project_name: str):
21+
for path in paths_to_replace:
22+
files = glob.glob(path, recursive=True)
23+
for file in files:
24+
if not os.path.isfile(file) or file.__contains__("rename-template.py"):
25+
continue
26+
with open(file, "r") as f:
27+
content = f.read()
28+
content = content.replace("python-template", new_project_name)
29+
content = content.replace("python_template", new_project_name.replace("-", "_"))
30+
with open(file, "w") as f:
31+
f.write(content)
32+
33+
if __name__ == "__main__":
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("new_project_name", type=str)
36+
args = parser.parse_args()
37+
rename_template(args.new_project_name)

0 commit comments

Comments
 (0)