Skip to content
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

build: Add new build infrastructure #154

Merged
merged 22 commits into from
Sep 25, 2024
Merged

build: Add new build infrastructure #154

merged 22 commits into from
Sep 25, 2024

Conversation

adisbladis
Copy link
Member

@adisbladis adisbladis commented Sep 18, 2024

This fixes many problems existing in the Nixpkgs Python infrastructure:

  • No dependency propagation

No leaking of dependencies via PYTHONPATH

  • No runtime deps at build time

This causes much less rebuilds

  • Support for circular dependencies

  • No wrapping of Python bin's

No strange venv breaking shell wrapper

  • Proper virtualenvs only

Meaning that applications that spawns children using sys.executable works fine.

  • Hermetic bootstrap

Nixpkgs breaks if you override any bootstrap dependencies with wheels.

  • Manual cross splicing

Meaning you can override build-time and runtime deps separately, and also IMHO just in general a much better cross interface.


I've previously tried to tackle this in NixOS/nixpkgs#272178.
This is not having the same backwards compat concerns.

@adisbladis
Copy link
Member Author

adisbladis commented Sep 18, 2024

Example usage:

{ pyproject-nix, pkgs }:

let
  python = pkgs.python312;

  # Inject your own packages on top with overrideScope
  pythonSet = pkgs.callPackage pyproject-nix.build.packages {
    inherit python;
  };

in pythonSet.pythonPackagesHostHost.mkVirtualEnv "test-venv" {
  build = [ ];
}

@adisbladis adisbladis force-pushed the pyproject-build branch 7 times, most recently from f264e23 to 53c1e54 Compare September 24, 2024 02:18
@TyberiusPrime
Copy link
Contributor

This is great work, and I especially like the recent symlinks fixes.

One case where we still run into a collision in bin (=needs dependency ordering) is
"fastapi[standard]==0.114.0", which leads to

  > error: collision between `/nix/store/caq1nnyypsr16yrb4j6cpwxxyvcxd4rd-python3.12-fastapi-cli-0.0.5/bin/fastapi' and `/nix/store/722hdr0lwkzj3qdppr39r35vnrxvmjys-python3.12-fastapi-0.114.0/bin/fastapi'

@adisbladis
Copy link
Member Author

This is great work, and I especially like the recent symlinks fixes.

One case where we still run into a collision in bin (=needs dependency ordering) is "fastapi[standard]==0.114.0", which leads to

  > error: collision between `/nix/store/caq1nnyypsr16yrb4j6cpwxxyvcxd4rd-python3.12-fastapi-cli-0.0.5/bin/fastapi' and `/nix/store/722hdr0lwkzj3qdppr39r35vnrxvmjys-python3.12-fastapi-0.114.0/bin/fastapi'

Are you sure you're using the right builder? This error message looks to originate in buildEnv, which is not used to construct the virtualenv.

@TyberiusPrime
Copy link
Contributor

This is great work, and I especially like the recent symlinks fixes.
One case where we still run into a collision in bin (=needs dependency ordering) is "fastapi[standard]==0.114.0", which leads to

  > error: collision between `/nix/store/caq1nnyypsr16yrb4j6cpwxxyvcxd4rd-python3.12-fastapi-cli-0.0.5/bin/fastapi' and `/nix/store/722hdr0lwkzj3qdppr39r35vnrxvmjys-python3.12-fastapi-0.114.0/bin/fastapi'

Are you sure you're using the right builder? This error message looks to originate in buildEnv, which is not used to construct the virtualenv.

My bad, that was the old builder.

The current builder gives

      > Executing pyprojectMakeVenv
       > Traceback (most recent call last):
       >   File "/nix/store/k44y6ylpzvk62wrz1s72gq7ym6z0dx1r-make-venv.py", line 216, in <module>
       >     main()
       >   File "/nix/store/k44y6ylpzvk62wrz1s72gq7ym6z0dx1r-make-venv.py", line 212, in main
       >     link_dependency(dep_root, out_root)
       >   File "/nix/store/k44y6ylpzvk62wrz1s72gq7ym6z0dx1r-make-venv.py", line 136, in link_dependency
       >     _link(dep_root, out_root)
       >   File "/nix/store/k44y6ylpzvk62wrz1s72gq7ym6z0dx1r-make-venv.py", line 119, in _link
       >     write_bin_dir(path, out.joinpath("bin"))
       >   File "/nix/store/k44y6ylpzvk62wrz1s72gq7ym6z0dx1r-make-venv.py", line 42, in write_bin_dir
       >     with open(bin_file_out, "wb") as f_out:
       >          ^^^^^^^^^^^^^^^^^^^^^^^^
       > PermissionError: [Errno 13] Permission denied: '/nix/store/4kzghrgzklaajq792djhx8dv6cxja9ff-test-venv/bin/fastapi'

@adisbladis adisbladis force-pushed the pyproject-build branch 4 times, most recently from 2a67564 to 6ff6f59 Compare September 25, 2024 03:49
This fixes many problems existing in the Nixpkgs Python infrastructure:
- No dependency propagation
  No leaking of dependencies via PYTHONPATH

- No runtime deps at build time
  This causes much less rebuilds

- Support for circular dependencies

- No wrapping of Python bin's
  No strange venv breaking shell wrapper

- Proper virtualenvs only
  Meaning that applications that spawns children using sys.executable works fine.

- Hermetic bootstrap
  Nixpkgs breaks if you override any bootstrap dependencies with wheels.

- Manual cross splicing
  Meaning you can override build-time and runtime deps separately, and also IMHO just in general a much better cross interface.
It was removed from nixpkgs
This is shorter and less likely to be mixed up with python(2|3|)Packages from nixpkgs.
@adisbladis
Copy link
Member Author

Merging this now documented as an experimental feature.

@adisbladis adisbladis merged commit fa3eeab into master Sep 25, 2024
19 checks passed
@adisbladis adisbladis deleted the pyproject-build branch September 25, 2024 09:26
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.

2 participants