refactor: migrate from pip-tools to uv for dependency management#1973
refactor: migrate from pip-tools to uv for dependency management#1973TeaDrinkingProgrammer wants to merge 7 commits intoFlexMeasures:mainfrom
Conversation
79a04bf to
87f9ea8
Compare
|
I see I broke Sphinx in some way, I'll see if I can fix that |
There was a problem hiding this comment.
Thanks!
Big change, but looking forward to the benefits in the CI pipeline and in development.
Also well done in cleaning files we don't need anymore and fixing smaller things like make commands everywhere!
- It seems the dependencies are not kept per Python version anymore (just for 3.12)? So if somebody runs FlexMeasures on 3.10 and runs into a bug, how would we reproduce his exact environment? (This is not a question about this PR per se, more about the new way of working, probably. Sorry)
- Now the dependencies all have a minimum version. Where did that come from?
- We have Dependabot scanning requirements already. Maybe we can observe how it picks up uv.lock. I'd expect it would do well.
- I have no inclination to stick with flake8, so if that is cleaner we can move to ruff. Any other thoughts on that @Flix6x ?
- Your comment about plugins might have to do with some legacy approach we should clean up. (A) Any plugin can be added by path, and dependencies installed in a separate step. That is the MVP. (B) We also think it would be nice if a plugin could be installed to the venv and be referenced by its package name only. The cookiecutter template is outdated and needs to be cleaned. I recently moved fm-entsoe to pyproject.toml at least. So all existing plugins can continue to at least use version (A), and FlexMEasures will then use
uvto install the plugin deoendencies if it finds them (or you are responsible to do that yourself actually). And we should later update the preferred way for plugins to do (B) (viauv). - I will take a look at poethepoet, I didn't know it yet. Not married to Makefiles, either!
| solver = SolverFactory(solver_name) | ||
|
|
||
| # Temporary fix for https://github.com/Pyomo/pyomo/issues/3841 | ||
| if solver_name == "cbc": |
There was a problem hiding this comment.
Cool.
We usually use HiGHs these days, any reason you used Cbc?
There was a problem hiding this comment.
Some tests failed when I didn't have CBC installed
There was a problem hiding this comment.
Ah, maybe you have a different OS (Fedora?) than our team (I believe we have PopOS and MacOS) and that might come across unique problems :)
There was a problem hiding this comment.
Yes that's right. For some reason Fedora chooses to name the binary 'Cbc' instead of 'cbc'. They're the only ones doing it as far as I know, so it's no wonder it flew under the radar.
Probably not, take a look at #1972 |
Ah, I see. I also added a fix. I'll revert it tomorrow and rebase |
|
Ruff over flake8 sounds good. This PR already touches a lot, though. Does it make sense to do even more in one PR? |
There was a problem hiding this comment.
Is there something of a migration table of what the make commands have been replaced with? Or, even more backwards compatible, would it make sense to keep the old commands, but just have them run the new commands (with a deprecation warning if we want).
f2cc19e to
87f9ea8
Compare
Replace the pip-tools based dependency management workflow with uv, consolidating all dependencies into pyproject.toml and a single uv.lock file. This simplifies and speeds up the development setup greatly. Changes: - Switch build backend from setuptools to hatchling - Move all dependencies from requirements/*.in to pyproject.toml - Remove setup.cfg in favour of .flake8 and pyproject.toml - Remove Makefile in favour of poethepoet tasks - Upgrade main python version (CI/CD, .python-version, etc.) to 1.12 - Use Ubuntu LTS latest for readthedocs.yaml - Refactor and update Dockerfile to use uv for installation - Upgrade the Debian version in the Dockerfile from bookworm to trixie - Add .python-version for consistent Python version management - Replace pip-tools with uv in all CI/CD workflows - Remove legacy build and update scripts (to_pypi.sh, ci/update-packages.sh, ci/run_mypy.sh) - Update documentation to reflect changes Signed-off-by: Stijn van Houwelingen <teadrinkingprogrammer@github.io>
Signed-off-by: Stijn van Houwelingen <teadrinkingprogrammer@github.io>
87f9ea8 to
7659bb7
Compare
Yes I agree, I'll open a new issue |
Signed-off-by: Stijn van Houwelingen <teadrinkingprogrammer@github.io>
Signed-off-by: Stijn van Houwelingen <teadrinkingprogrammer@github.io>
That's a good point, now the users workflow will break and they won't know what happened. I added a new Makefile that executes the equivalent command with a warning where it makes sense (like make install), otherwise it only displays a warning (like install-pip-tools) |
Thanks 😄
|
|
I want to test this, but have to find some time first.
I am okay with fixing a few leftovers while we go along. However, I want to release v0.31 before merging this PR, so that release process (documented in the TSC repo) will go smoothly. |
…nt variable Signed-off-by: Stijn van Houwelingen <teadrinkingprogrammer@github.io>
…pre-commit checking in CI. Remove pre-commit as dev dependency (docs already recommend using `uv tool install pre-commit`). Fix Flake8 scanning the .venv folder. Signed-off-by: Stijn van Houwelingen <teadrinkingprogrammer@github.io>
c8a0a82 to
427e983
Compare
|
Slightly improved the CI/CD: it was implicitly syncing some uv dependencies because of the invocation of the One bug that came out of that though, is that it now uses the flake8-blind-except plugin correctly where it did not before. How would you like to deal with that? |
Maybe you answered my other comment here. How is it guaranteed that my local dev environment and GH Actions will use the same lint tool versions?
Oh, interesting.
|
Signed-off-by: Stijn van Houwelingen <teadrinkingprogrammer@github.io>
I'll explain it a bit more thoroughly: Before: Pre-commit installs itself using PIP, makes its own venv, and uses the flake8 etc. in that venv. Every dependency is installed by cloning the git repo, then running https://pre-commit.com/#python Now: Because the pre-commit now just runs uv commands thanks to the Because this setup uses the same lock file, the version will always be the same as the versions you have installed locally. Using uv-pre-commit means that pre-commit will install itself using UV too, but that is just a nice performance bonus, it doesn't change the running behaviour. Another plus is that it doesn't have to clone the git repos any-more.
There were 42 blind except errors. One error I forgot to mention is a whitespace error. It is not a big error, but I' ll give it the same treatment. Good point, I've added a global ignore and an explanation for those errors for now |
|
Thanks for taking the time to explain more of this! As I said earlier, I'd love to move on this soon, but this week we had other priorities and next week I'll be off work. Not sure if someone else can take the time until I'm back. Busy times. I hope it's okay that this sits around a bit longer. Good to get v0.31 out first, also because there might be downstream effects. I can think of two. First, cloudinfra scripts might need an update. We use internally ansible and terraform, and we might need to update a few places in the code and test on staging, not sure. Second, plugins. You mentioned that you "install the requirements.txt in the VENV using the pip compat mode of uv". I still see only |
Replace the pip-tools based dependency management workflow with uv,
consolidating all dependencies into pyproject.toml and a single uv.lock file.
This simplifies and speeds up the development setup greatly.
Changes:
Description
Fixes #1643. See commit for details.
documentation/changelog.rstLook & Feel
N.A.
How to test
This is quite an extensive change, so these are the things I can think of:
Further Improvements
Migrate from Flake8 to Ruff?
pyproject.toml, so migration would consolidate all configuration inpyproject.tomlOptions:
Should we enable Dependabot for UV lockfile updates?
uv.lockfor security updatesOptions:
Migrate to using separate environments for plugins
Currently plugins use the same environment as the main application. This breaks the stability of the UV lock file.
I do not know enough about plugins to suggest how this can be done better.
6. Pre-commit Hook using UV
Use UV commands in the pre-commit hooks instead of separate pre-commit hook versions. See https://github.com/ElaadNL/openadr3-client/blob/main/.pre-commit-config.yaml
Current approach: keep pre-commit hook versions, only migrate to poethepoet task when a python script was used before.
Compile bytecode
See https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
Current approach: compile bytecode in the Docker file.
Move to ranges in the dependency versions
Previously, dependencies were listed in the .in file, and 'compiled' to a requirements.txt file. In UV, it is customary to set a range (e.g. <=x.x.x), so that a UV lock upgrade always stays within minor versions and you need to manually update the major version. For now, I have applied that way of working, but this could be reverted.
Misc
Related Items
Sign-off