rye
rye copied to clipboard
Invoke scripts from the project root
Fixes #930
I have some use cases that require rye run to preserve the current working directory, maybe this could be configurable in that case?
@bluss I see three approaches:
- Add a
cwd
option proposed in #930, but it should support some special variabes to support your use cases, for examplepwd = { cmd = "pwd", cwd: "${CWD}" }
- Defaults invoking scripts from current working directory (current behavior, not recommended). If the
cwd
option is set, invoking from that instead. - We take
npm
approach, which setsINIT_CWD
env to the current working directory when invoking scripts. Then in your scriptpwd = { cmd = "bash -c 'echo $INIT_CWD'"}
I'm not sure what's wrong with the current behaviour. Here's an argument in favour of keeping it.
These two should be equivalent:
cmd
(with virtualenv active - it's a binary in .venv/bin) and rye run cmd
(virtualenv doesn't matter)
They will only be the same if they both behave the same w.r.t cwd.
Current behavior makes relative file path in the cmd does not work, see #930
Since scripts
are defined in pyproject.toml
, it is natural to think that relative path are resloved by the directory containing pyproject.toml
. This is the default behavior of pipenv/pdm and npm.
Note that this function also handles rye run python, rye run cmd where cmd is an executable in the venv too (take for example cmd = pytest). Maybe it makes sense for tool.rye.scripts by itself, yes!
I feel like making it run from root is a reasonable default as many scripts will be taking relative file arguments. However I do think that if we change that, then an option should be added to override it like PDM does now. Also I do like what npm does with INIT_CWD
, maybe we can add support for this.