Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyproject.toml template manager #12256

Open
sarpuser opened this issue Mar 18, 2025 · 0 comments
Open

pyproject.toml template manager #12256

sarpuser opened this issue Mar 18, 2025 · 0 comments
Labels
enhancement New feature or improvement to existing functionality

Comments

@sarpuser
Copy link

sarpuser commented Mar 18, 2025

Summary

Would it be possible to add some sort of template manager for pyproject.toml? I find myself copying and pasting my tools settings for things like ruff, mypy, etc a lot. It would be really nice if we could have a template manager of sorts that we could pass into uv init.

Example

Here is how I think this should work.

  • There should be a default uv templates folder. I am thinking ~/.config/uv/templates would be a good default.
  • The templates would have all the sections besides the things that uv init controls. For example, it might have the ruff config, the mypy config etc. The filename of these templates would be the template name.
  • When running uv init, we could pass in a template by doing something like uv init --template <template_name>. Instead of passing in a template name, we could also pass in a filepath to a template.
  • It would also be nice to pass in multiple templates so we can selectively add config options.
  • When running init, uv would take the information from the templates, and add it to the generated pyproject.toml. Any options such as build-system, project, and dependencies should be ignored if present within the template.

Example:

# ~/.config/uv/templates/pytest.toml
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "test_*.py"
addopts = "-rA --tb=line"
# ~/example/ruff.toml
[tool.ruff]
# Target version
target-version = "py311"

extend-exclude = ["__init__.py"]

# Line length
line-length = 88

Then, running uv init example-project --template pytest --template ~/example/ruff.toml would generate the following pyproject.toml (not sure what the best approach is for multiple templates):

[project]
name = "example-project"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = []

[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = "test_*.py"
addopts = "-rA --tb=line"

[tool.ruff]
# Target version
target-version = "py311"

extend-exclude = ["__init__.py"]

# Line length
line-length = 88

I think this would be a massive quality of life increase. Thank you for your consideration and all your effort into this amazing project.

@sarpuser sarpuser added the enhancement New feature or improvement to existing functionality label Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant