pypa / hatch

Modern, extensible Python project management
https://hatch.pypa.io/latest/
MIT License
5.68k stars 277 forks source link

feature request: add custom templates for new projects #1597

Open bhajneet opened 3 days ago

bhajneet commented 3 days ago

Hello, I do a lot of one-off python projects, what I'm looking for in these situations is a very easy way to create a virtual environment and dependency management, often for a single main.py file. It would be nice to use hatch for these situations even if I'm not planning to build or package the project. Correct me if wrong, but it would be nice to run something like:

hatch new --bare

and get something simple like pyproject.toml and main.py created inside it

pyproject.toml could contain just the bare necessity:

[project]
name = "asdf"
version = "0"
requires-python = ">=3.8"
dependencies = []

[tool.hatch.envs.default.scripts]
main = "python main.py"

This would make it much easier to use hatch for new (super-simple) projects. It would also be nice to somehow remove the requirement for name / version (again this is more important when sharing a project, but not necessarily for locally managed ones)

bhajneet commented 3 days ago

Another idea, off the top of my head, would be to allow for multiple templates (or project default templates) when creating new hatch. Like this https://hatch.pypa.io/latest/config/project-templates/ is not actually what I'm asking for in this issue, since I do still create projects that need tests, or projects that need tests and will be published/distributed later, etc.

But it could be nice to have something like:

hatch new
hatch new --template "bare"
hatch new --template "package"
ofek commented 3 days ago

Have you seen this? https://hatch.pypa.io/latest/how-to/run/python-scripts/

bhajneet commented 3 days ago

That is quite nice too, thank you! I can start using that today for the simple scripts

I still think it would be worth having multiple templates to choose between for new projects, so going to leave this issue open and rename the title

bhajneet commented 3 days ago

Also for some reason getting these errors:

hatch run main.py
/bin/sh: main.py: command not found

hatch run ./main.py
/bin/sh: ./main.py: Permission denied

the script simply does this:

print("hello, world!")
ofek commented 3 days ago

show the full script

bhajneet commented 3 days ago
image