hatch icon indicating copy to clipboard operation
hatch copied to clipboard

hatch run from directory outside of project tree?

Open peakschris opened this issue 1 year ago • 5 comments

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!

peakschris avatar Jul 13 '24 16:07 peakschris

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

ofek avatar Jul 13 '24 16:07 ofek

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?

peakschris avatar Jul 13 '24 18:07 peakschris

can you show me exactly what you want to do?

ofek avatar Jul 13 '24 19:07 ofek

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

peakschris avatar Jul 13 '24 19:07 peakschris

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%

ofek avatar Jul 13 '24 19:07 ofek