Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,52 @@
"payjoin-directory" = "";
};

# Python-specific configuration
pythonVersion = pkgs.python3;
pythonEnv = pythonVersion.withPackages (ps: with ps; [
virtualenv
pip
]);

# Determine platform for generate script
supportedPlatforms = {
"x86_64-linux" = "linux";
"aarch64-linux" = "linux";
"x86_64-darwin" = "macos";
"aarch64-darwin" = "macos";
};
platform = supportedPlatforms.${system} or (throw "Unsupported platform: ${system}. Supported platforms: ${builtins.concatStringsSep ", " (builtins.attrNames supportedPlatforms)}");

# Python devShell
pythonDevShell = pkgs.mkShell {
name = "python-dev";
buildInputs = with pkgs; [
pythonEnv
bash
];

# Environment variables and shell hook
shellHook = ''
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [pkgs.openssl]}:$LD_LIBRARY_PATH
cd payjoin-ffi/python
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies, allowing PyPI fetches for version mismatches
pip install --requirement requirements.txt --requirement requirements-dev.txt
# Generate bindings, setting PYBIN to the venv's python binary
export PYBIN=./venv/bin/python
bash ./scripts/generate_${platform}.sh
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't using ${system} potentially be more future proof? they can still be a single file using symlinks but if there are any platform specific quirks down the line i suspect the net result would be adding another layer on top of this, instead of going the more direct route

# Set CARGO_TOML_PATH for setup.py
export CARGO_TOML_PATH=${./.}/Cargo.toml
# Build the wheel
python setup.py bdist_wheel --verbose

# Install payjoin
pip install ./dist/payjoin-*.whl
Comment on lines +122 to +138
Copy link
Collaborator

Choose a reason for hiding this comment

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

any chance we can use uv and uv2nix instead of pip?

requirements.txt is not reproducible, and poetry2nix is kinda dead these days

doing this in a shell hook also means we can't really use this in a flake check in a clean way, so while this is convenient it seems like it would be pretty brittle in the long term and if people run into problems we would have a hard time debugging without a lot of manual intervention

especially because venv is likely to survive long term and accumulate cruft unless the user deliberately cleans and reruns the shell hook (ideally the built artifacts should end up in the nix store)

'';
};

devShells = builtins.mapAttrs (_name: craneLib:
craneLib.devShell {
packages = with pkgs; [
Expand All @@ -115,7 +161,10 @@
// args);
in {
packages = packages;
devShells = devShells // {default = devShells.nightly;};
devShells = devShells // {
default = devShells.nightly;
python = pythonDevShell;
};
formatter = pkgs.alejandra;
checks =
packages
Expand Down
49 changes: 28 additions & 21 deletions payjoin-ffi/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,59 @@ Welcome to the Python language bindings for the [Payjoin Dev Kit](https://payjoi

## Install from PyPI

Grab the latest release with a simple:
To grab the latest release:

```shell
```sh
pip install payjoin
```

## Running Tests
## Building the Package

If you have [nix](https://nixos.org/download/) installed, you can simply run:

Follow these steps to clone the repository and run the tests.
```sh
nix develop .#python
```

This will get you up and running with a shell containing the dependencies you need.

Otherwise, follow these steps to clone the repository and build the package:

```shell
```sh
git clone https://github.com/payjoin/rust-payjoin.git
cd rust-payjoin/payjoin-ffi/python

# Setup a python virtual environment
python -m venv venv
source venv/bin/activate

# Generate the bindings (use the script appropriate for your platform)
# Install dependencies
# NOTE: requirements-dev.txt only needed when running tests
pip install --requirement requirements.txt --requirement requirements-dev.txt

# Generate the bindings (use the script appropriate for your platform (linux or macos))
PYBIN="./venv/bin/" bash ./scripts/generate_<platform>.sh

# Build the wheel
python setup.py bdist_wheel --verbose

# Force reinstall payjoin
pip install ./dist/payjoin-<version>.whl --force-reinstall
```

If all goes well, you should be able to run the Python interpreter and import `payjoin`:

```sh
python
import payjoin
```

## Running Tests

```sh
# Run all tests
python -m unittest --verbose
```

Note that you'll need Docker to run the integration tests. If you get a "Failed to start container" error, ensure the Docker engine is running on your machine.
You can [filter which tests](https://docs.python.org/3/library/unittest.html#command-line-interface) to run by passing a file or test name as argument.

## Building the Package

```shell
# Setup a python virtual environment
python -m venv venv
source venv/bin/activate

# Generate the bindings (use the script appropriate for your platform)
PYBIN="./venv/bin/" bash ./scripts/generate_<platform>.sh

# Build the wheel
python setup.py --verbose bdist_wheel

```
Loading