Skip to content

Conversation

@thebrandonlucas
Copy link
Collaborator

@thebrandonlucas thebrandonlucas commented Sep 15, 2025

Pull Request Checklist

Please confirm the following before requesting review:

This continues the work done in by @nothingmuch in #997. When we first started creating nix devShells in #864, @nothingmuch pointed out that we lose many of the reproducibility benefits of Nix by using pip without a lockfile. pip can create lockfiles but the process is very manual and verbose, aside from the many other benefits uv brings us, such as:

  • Much faster due to built in Rust
  • Auto-manages both lockfiles and virtual environments (currently users manually must create and enter venv)
  • A simpler and easier to use API
  • All in one backward compatibility for managing poetry, pip, and other pythonic goodies

Also noted by @nothingmuch here.

By making this change we will also be able to use uv2nix in a subsequent PR to have Nix auto-generate a devShell or perform the tests with a simple nix flake check command.

Note that this PR does not yet modify anything with the Nix devShells yet, just replaces pip with uv. When we do combine this with nix, we will have complete dependency management for users who have nix installed.

I did run into one hiccup with the dependencies in generate_bindings.sh. There are "debianisms" see commit which make this impossible to run on many Linux systems. Basically it installs two dependencies required for building: build-essential and python3-dev. I removed those install lines and instead them as a comment in the README to ensure the user had these before running the script. In one way this makes it less robust for users who don't already have those, but it decouples the script from the Linux distro and also paves the way for us to add these dependencies in our nix flake later.

You should just be able to follow the updated instructions in the README and generating the bindings, building, and the tests should work.

To create a shell environment with the necessary dependencies installed for testing this PR, I used the below shell.nix with the required dependencies:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
  buildInputs = [
    pkgs.gcc
    pkgs.rustc
    pkgs.cargo
    pkgs.rustup
  ];
}

@coveralls
Copy link
Collaborator

coveralls commented Sep 25, 2025

Pull Request Test Coverage Report for Build 18009273643

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.525%

Totals Coverage Status
Change from base Build 17984185097: 0.0%
Covered Lines: 8581
Relevant Lines: 10152

💛 - Coveralls

`uv` has significant speed, dependency management, and
virtual environment advantages compared to `pip`, in
addition to being backward compatible with `pip`.

This commit replaces `pip` with `uv` everywhere it is used in our
python FFI bindings and updates the README with the simplified uv-
specific instructions.
enable-cache: true

- name: "uv sync"
run: uv sync --all-extras
Copy link
Collaborator Author

@thebrandonlucas thebrandonlucas Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command includes all "optional" (i.e. dev) dependencies and is the replacement for pip install but also updates the .venv and lockfile

- name: Install a specific version of uv
uses: astral-sh/setup-uv@v6
with:
version: "0.8.2"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is simply the current version of uv, I figured we shouldn't just arbitrarily pull latest?


- name: "Build wheel"
run: python -m build --wheel
run: uv build --wheel
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running just uv build would have built both the source and binary (wheel) distribution, which is redundant so we only build the binary here.

*.whl
build/
venv
.venv
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uv's virtualenv lives in .venv

Comment on lines -19 to -20
git clone https://github.com/payjoin/rust-payjoin.git
cd rust-payjoin/payjoin-ffi/python
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed redundant

Comment on lines +21 to +22
# Ensure you have uv installed:
# https://docs.astral.sh/uv/getting-started/installation/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are, of course, other deps required (gcc compiler, for ex.) but these will be abstracted away in uv2nix in the next PR

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a separate followup PR it'd make sense to add python and these toolchain bits to the devshell

not sure it should be gcc though, since rustc uses llvm clang might be the more appropriate option

@thebrandonlucas thebrandonlucas marked this pull request as ready for review September 25, 2025 13:38
Copy link
Collaborator

@nothingmuch nothingmuch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK, afaict this is basically the same as what we came up with before

this should be reviewed by someone else too since i co-authored these changes

@thebrandonlucas
Copy link
Collaborator Author

thebrandonlucas commented Sep 30, 2025

this should be reviewed by someone else too since i co-authored these changes

@benalleng perhaps?

@DanGould DanGould requested a review from benalleng September 30, 2025 17:09
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 3bbb35c, tested the new "generate python bindings and run tests" on macOS with no issues after installing uv.

Sidenote, it would be nice to move the "build and reinstall wheel" steps into the generate_bindings.sh script if at all possible to reduce the number of commands to run.

@spacebear21 spacebear21 merged commit cf2d82f into payjoin:master Sep 30, 2025
14 checks passed
@nothingmuch
Copy link
Collaborator

Sidenote, it would be nice to move the "build and reinstall wheel" steps into the generate_bindings.sh script if at all possible to reduce the number of commands to run.

I think that should be done in a separate script (a test.sh?) or just a flake check (in which case it'd be nix flake check .#python to do the whole procedure including binding generation in the sandbox), although the installation is into the venv it still feels a bit weird to me that generate bindings does more than generate bindings IMO

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.

4 participants