| title | Migration Guide | ||
|---|---|---|---|
| description | Migrate existing Python projects to use this template | ||
| audience |
|
||
| tags |
|
Bring your existing Python project into the pyproject-template.
Automated Option: Use
migrate_existing_project.pyto copy template files automatically:python tools/pyproject_template/migrate_existing_project.py --target /path/to/your/projectSee Tools Reference for details.
Use this checklist for a manual migration. The flow assumes hatch-vcs for versioning, commitizen for tagging/changelog, uv for deps, and doit for tasks.
- Note current package import name, supported Python versions, dependencies (runtime/dev/extras), scripts/entry points, CI/release setup.
- Ensure current tests pass before migrating.
- Backup: Rename your existing
README.md,LICENSE, andpyproject.toml(e.g., to*.old) so you don't lose content. - Copy Files: Copy template files into your repo:
- Config:
pyproject.toml,dodo.py,.envrc,.pre-commit-config.yaml,.python-version,mkdocs.yml. - Docs & Guides:
AGENTS.md,AI_SETUP.md,docs/*,examples/*,CHANGELOG.md. - Hidden Configs:
.github/workflows/*,.vscode/,.devcontainer/,.claude/,.codex/,.gemini/,tmp/.gitkeep.
- Config:
- Keep your code: You’ll move it in step 4.
- From the template root:
python tools/pyproject_template/manage.py. - Select [2] Configure project to run the configurator.
- Provide project name, package name (import), PyPI name, author, GitHub user, description.
- What it does: Rewrites placeholders (badges/links/docs/workflows), renames
src/package_name → src/<your_package>.
See Template Management for full documentation on the management script.
- Move your existing package source into the newly renamed
src/<your_package>/. - Cleanup: Delete the template's default
core.pyif not needed. - Type Hinting: Ensure
py.typedexists insrc/<your_package>/to mark your package as typed. - Versioning: Leave
_version.pyas the stub; hatch-vcs generates it at build time from git tags.
- Merge, don't overwrite: Copy your dependencies and metadata into the new
pyproject.toml. Preserve the[tool]sections (hatch, ruff, mypy, doit) provided by the template. - Update
[project.dependencies]. - Add dev tools to
[project.optional-dependencies](keep the template's defaults likeruff,pytestif possible). - Define entry points under
[project.scripts]if you have a CLI.
- Move your tests to
tests/. - If moving from a flat layout to
src/, you may need to adjust imports in your tests. - Ensure
dodo.pyand workflows point coverage to the correct package (handled byconfigure.py, but worth double-checking).
- Run
uv lockto refreshuv.lockwith your merged dependencies.
- Local tasks:
doit checkruns format (ruff), lint, mypy, tests. - Workflows:
ci.ymlruns checks;release.ymltriggers on stablev*tags;testpypi.ymltriggers on prereleasev*-<pre>tags.
- Check
README.md: Restore your project description, but keep the new badges (links were updated byconfigure.py). - Update docs (
docs/installation.md,docs/usage.md,docs/api.md) with your specific details.
- Install environment:
uv sync --all-extras --dev - Install hooks:
doit pre_commit_install - Run checks:
doit check - Run tests:
doit test
- All releases go through a PR.
doit release [--prerelease=alpha|beta|rc]opens a release PR with the version bump and changelog updates. - Tag after merge. Once the release PR is merged, run
doit release_tagto tagmainand trigger the publish workflow (testpypi.ymlfor pre-releases,release.ymlfor production tags). - Important: No manual edits to
pyproject.tomlversion or_version.py; the git tag is the source of truth.
- Remove old CI configs/Makefiles you no longer need.
direnv allowto load.envrc.- Commit and push. Monitor CI actions to ensure the migration was successful.
After migration, use Keeping Up to Date to stay in sync with template improvements.