Skip to content

migration from poetry to uv #8249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

king-11
Copy link
Contributor

@king-11 king-11 commented Apr 27, 2025

make use of standard keys for project and dependeny specification

  • provide sources to run uv build so that it can refer local packages
  • using hatchling for build as is stock build option
  • use optional-dependencies.dev for dev-dependencies
  • add hatch targets for packages and includes where unclear
  • update Makefiles to use uv when running commands that access python dependencies

#7665

Important

25.05 FREEZE MAY 12TH: Non-bugfix PRs not ready by this date will wait for 25.08.

RC1 is scheduled on May 23rd, RC2 on May 26th, ...

The final release is on MAY 29TH.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.

@king-11 king-11 requested a review from cdecker as a code owner April 27, 2025 05:49
@king-11 king-11 marked this pull request as draft April 27, 2025 05:49
@king-11 king-11 changed the title refactor: pyproject.toml poetry to uv + hatch migration from poetry to uv Apr 27, 2025
@king-11 king-11 force-pushed the king-11/migrate-uv branch from a75084e to d041488 Compare April 27, 2025 05:51
@king-11
Copy link
Contributor Author

king-11 commented Apr 27, 2025

pending changes:

  • ci.yaml
  • macos.yaml
  • setup.sh
  • reckless

@vincenzopalazzo
Copy link
Collaborator

What are the benefit of uv over poetry?

@cdecker
Copy link
Member

cdecker commented Apr 27, 2025

It's much faster (5-10 seconds compared to minutes using poetry). While that doesn't sound too different, it means that we don't create long lived venvs that may drift from the metadata, causing fewer "it worked on my machine" kind of errors. It can also be used as a shebang, automatically wrapping for example a plugin, downloading dependencies on first invocation, creating the venv and only then passing control to python. This means we can make plugins self-contained and single file if we wanted to.

The speed, which unlocks all of these use cases, is done via caching, and interesting speedup ideas, that are quite fun to read up on. And finally, you don't need a system-wide python installation, since uv can also download and manage python versions (prevents you from accidentally polluting the system python and potentially break your OS).

@cdecker
Copy link
Member

cdecker commented Apr 27, 2025

Great initiative @king-11 , I had a branch with some initial steps, but you are much further along, so I'd rather help you than double-tracking

@king-11
Copy link
Contributor Author

king-11 commented Apr 27, 2025

Thanks @cdecker i will get the last few things in, just raised a draft PR given I saw some interest around it and wanted to have a pre-ready change look available.

@king-11
Copy link
Contributor Author

king-11 commented May 2, 2025

@cdecker do you have any suggestions I am currently encountering an issue where running tests shows pyln path not found.

After these changes I am setting things up as

uv venv --python 3.12
source .venv/bin/activate
uv sync --all-extras
uv run pytest tests/test_renepay.py

I ran the debug command

uv pip list

it shows pyln-testing is installed the only hunch I have here is maybe I need to set that as editable 🤔

@cdecker
Copy link
Member

cdecker commented May 3, 2025

Yeah, workspace-related options take a bit of getting used to.

For packages that we'd like uv to pull in from the repo, rather than the PyPI repository, we need to tell uv about the dependency:

[project]
...
dependencies = [
  "pyln-testing",
  ...
]

Then we need to tell uv that there is a member gl-testing in the workspace:

[tool.uv.workspace]
members = [
  "pyln-testing",
  ...
]

And then finally we need to tell uv to prefer the local copy from the repo, rather than the PyPI repo:

[tool.uv.sources]
pyln-testing = { workspace = true }

At least these are the three steps that would work for me whenever I ran into this issue.

@king-11
Copy link
Contributor Author

king-11 commented May 3, 2025

Got it thanks

@king-11 king-11 force-pushed the king-11/migrate-uv branch 2 times, most recently from 6e9cab3 to 3679ba4 Compare May 7, 2025 04:10
@king-11
Copy link
Contributor Author

king-11 commented May 7, 2025

Thanks for the workspace tip @cdecker that helped but one more thing was needed that is __init__.py files with PATH override for namespace sharing of pyln took some help from our ai friends going to get working on ci now I think

@king-11 king-11 force-pushed the king-11/migrate-uv branch 4 times, most recently from d1167b9 to 3fd0f8b Compare May 8, 2025 03:07
@king-11 king-11 marked this pull request as ready for review May 8, 2025 03:35
@king-11 king-11 force-pushed the king-11/migrate-uv branch from 5c0d170 to 888ff00 Compare May 8, 2025 03:35
@king-11
Copy link
Contributor Author

king-11 commented May 8, 2025

The flake8 fails for auto generated files not sure why but I have ran locally and tests are working fine now. Can you use some guidance on how to resolve the flake9 issue

@king-11 king-11 marked this pull request as draft May 8, 2025 03:39
@king-11 king-11 force-pushed the king-11/migrate-uv branch 2 times, most recently from 698222f to debba20 Compare May 8, 2025 03:55
king-11 added 3 commits May 9, 2025 19:46
make use of standard keys for project and dependeny specification

- provide sources to run uv build so that it can refer local packages
- using hatchling for build as is stock build option
- use optional-dependencies.dev for dev-dependencies
- add hatch targets for packages and includes where unclear

Changelog-Update: use uv with hatchling instead of poetry
allows for namespace sharing in a virtual environment otherwise gets overriden by pyln-proto-grpc's pyln folder
Add pytest.ini with pythonpath = . configuration to ensure modules 
are properly discovered when running tests. Also add empty 
__init__.py file to make the tests directory a proper Python package.
@king-11 king-11 force-pushed the king-11/migrate-uv branch 2 times, most recently from b3e2479 to 5c7aff4 Compare May 10, 2025 02:38
@king-11 king-11 force-pushed the king-11/migrate-uv branch 3 times, most recently from dd3239d to 9d67e52 Compare May 10, 2025 04:43
king-11 added 4 commits May 10, 2025 12:12
Replace poetry with uv for managing Python dependencies and running
commands across CI workflow.

- Add astral-sh/setup-uv@v5 action to install uv
- Replace all poetry run commands with uv run
- Remove poetry-specific installation steps
- Update Python setup in multiple jobs
add openssl installation and flags to install grpcio-tools
Remove unnecessary global declarations across multiple test files. 
This change improves code quality by eliminating redundant global 
statements for variables that are already accessible in their 
respective scopes. Add proper type annotation for fees_from_status 
in test_closing.py and import the required typing modules. These 
changes maintain the same functionality while making the code cleaner 
and more compliant with Python best practices.
Extract package versions from pyproject.toml directly
instead of using poetry commands. Use `uv run` to execute flake8,
pytest and other Python tools consistently.
@king-11 king-11 force-pushed the king-11/migrate-uv branch from 9d67e52 to 2848ad4 Compare May 10, 2025 06:47
@king-11 king-11 marked this pull request as ready for review May 10, 2025 07:23
@king-11 king-11 force-pushed the king-11/migrate-uv branch from 5882aa0 to 13b3ac4 Compare May 14, 2025 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants