pypa / hatch

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

hatch run from directory outside of project tree? #1615

Open peakschris opened 3 months ago

peakschris commented 3 months ago

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!

ofek commented 3 months ago

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

peakschris commented 3 months ago

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?

ofek commented 3 months ago

can you show me exactly what you want to do?

peakschris commented 3 months ago

I can try.

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
ofek commented 3 months ago

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%