Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ For making code changes, installing `pre-commit` is necessary (see section [Code

### Customization

The project's name (`python-template`) can be edited following next steps:

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

```bash
PROJECT_NAME=your-awesome-project code <path/to/repo>
Expand Down
37 changes: 37 additions & 0 deletions scripts/rename-template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

import argparse
import glob
import os

paths_to_replace = [
"src/**/*.py",
"tests/**/*.py",
"Dockerfile",
".env.example",
".devcontainer/**/*",
"uv.lock",
"pyproject.toml",
".github/workflows/python-app.yml",
"scripts/**/*",
"scripts/**/*",
".env"
]

def rename_template(new_project_name: str):
for path in paths_to_replace:
files = glob.glob(path, recursive=True)
for file in files:
if not os.path.isfile(file) or file.__contains__("rename-template.py"):
continue
with open(file, "r") as f:
content = f.read()
content = content.replace("python-template", new_project_name)
content = content.replace("python_template", new_project_name.replace("-", "_"))
with open(file, "w") as f:
f.write(content)

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("new_project_name", type=str)
args = parser.parse_args()
rename_template(args.new_project_name)