hatch
hatch copied to clipboard
hatch run from directory outside of project tree?
Hi there, we have a need to run a script managed by hatch from a working directory outside the hatch project tree. Is this possible?
I've tried hatch shell and then cd to required directory, this has some odd issues.
I've searched docs/issues and can't find this answer. Thanks!
that is possible if I understand what you're saying https://hatch.pypa.io/latest/config/hatch/#mode
I think I'm going the one that uses that feature lol let me know if it works for your use case
That's part of the use-case.
But it seems to change the cwd of the script to the project root. I need cwd to remain the directory that I'm invoking the command from. Is that possible?
can you show me exactly what you want to do?
I can try.
- d:\myhatchproject contains pyproject.toml, src\checkdata.py, checkdata is registered as script
- d:\data contains data for analysis
- checkdata is a script that checks datafiles in current directory
- normally, checkdata is packaged as binary and used
- but during development, we need to run it from source
Normal usage:
cd d:\data
checkdata --mode=detailed
During Dev, Either:
cd d:\data
hatch --project=d:\myhatchproject run checkdata -- --mode=detailed
Or:
<add myhatchproject to config.yaml>
cd d:\data
hatch --project=myhatchproject run checkdata -- --mode=detailed
hatch run ensures that the current directory is somewhere within the project, if not then it will be changed to the project root. You can either work within hatch shell and invoke your command directly or continue using hatch run but pass the current directory as an argument e.g. %PWD%