FlorianWilhelm / the-hatchlor

🌹 Cookiecutter template featuring the modern and extensible Python project manager hatch
MIT License
66 stars 5 forks source link

How to sync / apply script updates in `pyproject.toml` ? #2

Open floschne opened 7 months ago

floschne commented 7 months ago

Hi @FlorianWilhelm and first of all thanks for this amazing project template!

Maybe I missed it in the docs but I'm facing issues when I update script entries in pyproject.toml E.g. let's say I have the following entry and a fresh hatch project (i.e., never ran hatch run ... or hatch env create)

[project.scripts]
fibonacci = "autorag.fibonacci:app"

When I run hatch env create && hatch run fibonacci 10 it correctly executes the script.

Now I want to change ,e.g., the name of the script:

[project.scripts]
print_fibonacci = "autorag.fibonacci:app"

When I run hatch env create && hatch run print_fibonacci 10 it prints /bin/sh: print_fibonacci: command not found. Also, when I look into the venv bin dir, I can see the old fibonacci but not the new print_fibonacci.

The only way I found to update and sync the env is to completely remove my venv dir and create the env from scratch.

Is this behaviour on purpose or did I miss something here?

FlorianWilhelm commented 6 months ago

Hi @floschne, thanks for reporting this and nice to hear that you like my template 😊

I can confirm that this behaviour exists and bothers me too. Every update in the project‘s metadata will only be reflected after a new installation within the environment and this is not noticed by Hatch. On the other hand, if every change would trigger a reinstallation, the dynamic versioning would cause this after each commit, but then again it‘s quite fast to do a development installation.

What does @ofek, the author of hatch, think about this? Would this be a nice optional feature for hatch? So that changes within the project‘s metadata trigger a reinstallation of the project within the environments?

floschne commented 6 months ago

I actually also asked this in the official hatch repo and he answered that this is indeed the correct behavior of hatch :)

https://github.com/pypa/hatch/issues/1301#issuecomment-1983540246

I'm not too deep in the tech behind hatch but from my understanding it should generally be possible to only re-build/re-generate the scripts w/o the need of re-building the whole venv.

Anyways, I think for now there is nothing to do about it :)

ofek commented 6 months ago

I will fix it but it's not high priority for me at the moment.