diff --git a/README.md b/README.md index 66988e3..df8b20d 100755 --- a/README.md +++ b/README.md @@ -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 ` ```bash PROJECT_NAME=your-awesome-project code diff --git a/scripts/rename-template.py b/scripts/rename-template.py new file mode 100644 index 0000000..9e3f66f --- /dev/null +++ b/scripts/rename-template.py @@ -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)