How to run a project script/cli without installing?
Hatch has the possibility to define a global, project-wide CLI script (https://hatch.pypa.io/latest/config/metadata/#cli), as well as a env-specific script (https://hatch.pypa.io/latest/config/environment/overview/#scripts).
For env-specific scripts, running them during development is clear:
hatch run test:run-coverage
However, for the "global" scripts defined in project.scripts, it is not clear to me how to run them without installing the pkg during development.
Is this possible? I'd propose either implementing this (if not possible already), or documenting running a CLI/script during development.
The project has to be installed in order to run those scripts as they are defined by project metadata. What is your use case for not wanting the project also?
As I currently understand it, I'd need to hatch build and install the wheel every time after changing something.
I had the issue that we were iterating around the project.scripts config, and wanted a fast way to run the defined "cli" in a "default env" (e.g. the one being created by hatch shell without args), being sure that the current dev-state is used. Building and Installing for every small iteration was not practical here.
We did not find an easy way of doing this, and workarounded it by using a script inside an env (which does only work for Dev?).
if you are using environments you just need to re-create the environment but yes metadata updates are not dynamic, there is no standard for that because nobody has been able to come up with a good idea yet
Can the scripts in project.scripts be defined in terms of environments, or have environments defined in terms of these scripts?
I'm working around this by defining an environment that "happens" to have the same content as the [project.scripts] main entry point, but that's far from ideal. E.g.
[project.scripts]
hatch-demo = "hatch_demo.main:run"
# Duplication of the main entry point, see the github issue mentioned
# above the [project.scripts] section.
[tool.hatch.envs.main]
hatch-demo = "python -m hatch_demo.main:run"
With that I can use hatch run main:hatch-demo
This would be cleaner if I could, say, define that env script as something like:
[tool.hatch.envs.main]
hatch-demo = "python -m {project.scripts.hatch-demo}"
(Maybe this is possible? I'm having trouble finding out what replacement strings are allowed in scripts other than {args: ...})
That, I think, leads to a potential for a generated environment that does this automatically for every entry point. (e.g. main or `` -- the latter in my imagination allowing for a shell command like hatch :hatch-demo to work, with no configuration beyond the [project.scripts] section.)