Run hatch script from outside of project

127 Views Asked by At

Given a simple hatch project, what is a clean way of running it from outside of the project folder?

To be more concrete, say my project myproject has its root in /home/me/projects/myproject/, where the pyproject.toml and other files live. The pyproject.toml file contains a runnable script, as follows.

[project.scripts]
myrunnable = "myproject.main:main"

Say I am in my user folder, /home/me/ and want to run myrunnable. I can do cd "/home/me/projects/myproject/" then hatch run myrunnable. But I find inelegant that I have to explicitly switch to the project folder before running it. I would prefer, if possible, to type something like hatch --projectdir "/home/me/projects/myproject/" run myrunnable. I am aware that I can do pushd "/home/me/projects/myproject/"; hatch run myrunnable; popd (which I currently use) but is there some way more official and elegant?

I have tried hatch --config "/home/me/projects/myproject/pyproject.toml" run myrunnable but this fails because it tries to run myrunnable with a workdir of where I am currently (/home/me/) whereas myrunnable expects to be ran in the project root.

(This issue is possibly related.)

0

There are 0 best solutions below