juftin / hatch-pip-compile

hatch plugin to use pip-compile (or uv) to manage project dependencies and lockfiles
http://juftin.com/hatch-pip-compile/
MIT License
74 stars 3 forks source link

How can one update hatch-pip-compile itself ? #77

Closed Tobi-De closed 6 months ago

Tobi-De commented 6 months ago

Hi, I'm trying to test out uv. For some reason, it worked the first time I tried, but now this is what I get:


│    74 │   │   │   │   f"Invalid pip-tools install method: {install_method} - "                   │
│    75 │   │   │   │   "must be 'pip' or 'pip-sync'"                                              │
│    76 │   │   │   )                                                                              │
│ ❱  77 │   │   │   raise HatchPipCompileError(msg)                                                │
│    78 │                                                                                          │
│    79 │   @staticmethod                                                                          │
│    80 │   def get_option_types() -> Dict[str, Any]:                                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
HatchPipCompileError: Invalid pip-tools install method: uv - must be 'pip' or 'pip-sync'

It seems that the version of hatch-pip-compile I have is too old for this work. That's weird because I'm pretty sure I made it work once. I tried uninstalling and reinstalling Hatch (with different methods: pip and binary) itself, but encountered the same issue. Now, I realize that I have no clue how I'm supposed to update hatch-pip-compile itself. 🤔 Is it supposed to work automatically? If yes, when does it happen? Does the Hatch installation method matter?

juftin commented 6 months ago

How do you have hatch installed @Tobi-De?

If you have it installed with something like pipx the following works (see https://juftin.com/hatch-pip-compile/notes/#manual-installation) (This is why I like pipx best for hatch):

pipx runpip hatch install --upgrade hatch-pip-compile

If you have hatch installed with pip then you'd have to just do a vanilla pip install --upgrade hatch-pip-compile.

If you have hatch installed via the binary I believe you get less control over something like this and you'd have to add this to your hatch pyproject.toml (you could change this back to "hatch" after it has run once probably)

[tool.hatch.env]
requires = [
    "hatch-pip-compile>=1.11.1"
]
juftin commented 6 months ago

Err, it seems that I started this without fully understanding your original comment. Some points to clarify:

hatch-pip-compile runs inside the Python interpreter that is also running hatch. It accesses the virtual environments it creates but hatch-pip-compile is not installed into those virtualenvs (pip-tools / uv is installed into the virtualenvs though).

I tried uninstalling and reinstalling Hatch (with different methods: pip and binary) itself, but encountered the same issue

This one seems weird to me - maybe somehow the virtual environment that hatch lives in is getting persisted between these installs. hatch basically just runs a vanilla pip install hatch-pip-compile when it sees the tool.hatch.env table so maybe the virtualenv is never destroyed and thus never updated 🤷

Is it supposed to work automatically?

I think you're asking about whether hatch-pip-compile gets updated automatically. It doesn't 😞 - I can create an issue for this upstream in hatch. Ideally you should be able to run something like:

hatch self run-pip --upgrade hatch-pip-compile

If yes, when does it happen?

I believe the [tool.hatch.env] section only gets installed once, the first time it's called. I'm not 100% on this. I'll try to learn more

Tobi-De commented 6 months ago

If you have hatch installed via the binary I believe you get less control over something like this and you'd have to add this to your hatch pyproject.toml (you could change this back to "hatch" after it has run once probably)

[tool.hatch.env]
requires = [
    "hatch-pip-compile>=1.11.1"
]

This worked, currently I have hatch installed via binary, I guessed the solution you suggested for pip will also work. Thanks

I think you're asking about whether hatch-pip-compile gets updated automatically. It doesn't 😞 - I can create an issue for > this upstream in hatch. Ideally you should be able to run something like:

I don't know if it is possible, or maybe it will slow things down, but ideally the user won't have to think about it, but trying to update everything [tool.hatch.env] everytime is probably not a good idea

juftin commented 6 months ago

Nice 🙌 I'm glad you got that worked out. I raised https://github.com/pypa/hatch/issues/1293 re: this issue.

Let me know how you like the new uv functionality, I've really enjoyed it so far - it's been a huge performance improvement.

Tobi-De commented 6 months ago

Nice 🙌 I'm glad you got that worked out. I raised https://github.com/pypa/hatch/issues/1293 re: this issue.

Let me know how you like the new uv functionality, I've really enjoyed it so far - it's been a huge performance emportement.

I was skeptical at first, but damn, it does make a difference, especially when you are using the same sets of dependencies in most of your projects. I was looking for support for it within Hatch directly and saw there was a pending issue on that. Luckily, today I was looking for something in the hatch-pip-compile docs and discovered you added support for it weeks ago. Frankly, bravo, thanks so much for your work.