hatch icon indicating copy to clipboard operation
hatch copied to clipboard

feature request: add custom templates for new projects

Open bhajneet opened this issue 1 year ago • 7 comments

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 avatar Jul 04 '24 00:07 bhajneet

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"

bhajneet avatar Jul 04 '24 00:07 bhajneet

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

ofek avatar Jul 04 '24 01:07 ofek

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 avatar Jul 04 '24 04:07 bhajneet

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!")

bhajneet avatar Jul 04 '24 04:07 bhajneet

show the full script

ofek avatar Jul 04 '24 04:07 ofek

image

bhajneet avatar Jul 04 '24 04:07 bhajneet

I'm also interested in the custom templates. My use case is this: All projects need to use our local hosted artifactory for installing the dependencies. Currently the process looks like this:

  1. create a new hatch project
  2. add the following line to the pyproject.toml:
[tool.hatch.envs.default.env-vars]
PIP_EXTRA_INDEX_URL = "https://our-artifactory.com/..."
PIP_INDEX_URL = "https://our-artifactory.com/..."
  1. then continue to manage my project.

It would be nice if one could decalare stuff like the env-vars in the config.toml (maybe in the templates section) so that all new projects use those settings.

fhennig42 avatar Jul 22 '24 09:07 fhennig42