hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Unable to add script with `exec` keyword

Open awerchniak opened this issue 3 months ago • 1 comments

I attempted to include a hatch run clean command in my pyproject.toml to clean up the __pycache__ directories as follows:

[tool.hatch.envs.default.scripts]
clean = [ "find . -type d -name '__pycache__' -exec rm -rf {} +" ]

Unfortunately, this command would consistently fail with the following error: tuple index out of range. I was able to get the command to run by changing it to the following:

[tool.hatch.envs.default.scripts]
clean = [ "find . -type d -name '__pycache__' | xargs rm -rf" ]

While this solution works, I don't see any specific documentation notating issues with including an exec keyword in user-defined scripts, so I suspect this is a bug.

Thank you!

awerchniak avatar Sep 08 '25 14:09 awerchniak

Because of context formatting, your script should look like this instead, note the double curly braces.

[tool.hatch.envs.default.scripts]
clean = [ "find . -type d -name '__pycache__' -exec rm -rf {{}} +" ]

cjames23 avatar Sep 27 '25 22:09 cjames23