pypa / hatch

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

How to run a project script/cli without installing? #1632

Open margau opened 1 month ago

margau commented 1 month ago

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.

ofek commented 1 month ago

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?

margau commented 1 month ago

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?).

ofek commented 1 month ago

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