From f06a9f3e793dac05f4331f8fa23a2736aa303c57 Mon Sep 17 00:00:00 2001 From: Benjamin Sparks Date: Thu, 26 Feb 2026 15:51:23 +0100 Subject: [PATCH] python3Packages.ty: init at 0.0.20 Similar to `python3Packages.ruff` and `python3Packages.uv`, the Python module for ty allows for the ty binary to be searched for, e.g. for subprocess CLI invocations. This derivation uses the same tricks to speedup its build by referencing the nixpkgs ty binary instead of rebuilding from scratch. --- .../development/python-modules/ty/default.nix | 46 +++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 48 insertions(+) create mode 100644 pkgs/development/python-modules/ty/default.nix diff --git a/pkgs/development/python-modules/ty/default.nix b/pkgs/development/python-modules/ty/default.nix new file mode 100644 index 000000000000..799eb31759e8 --- /dev/null +++ b/pkgs/development/python-modules/ty/default.nix @@ -0,0 +1,46 @@ +{ + buildPythonPackage, + hatchling, + lib, + ty, +}: + +buildPythonPackage { + inherit (ty) + pname + version + src + meta + ; + pyproject = true; + + build-system = [ hatchling ]; + + postPatch = + # Add the path to the ty binary as a fallback after other path search methods have been exhausted + '' + substituteInPlace python/ty/_find_ty.py \ + --replace-fail \ + 'sysconfig.get_path("scripts", scheme=_user_scheme()),' \ + 'sysconfig.get_path("scripts", scheme=_user_scheme()), "${baseNameOf (lib.getExe ty)}",' + '' + # Sidestep the maturin build system in favour of reusing the binary already built by nixpkgs, + # to avoid rebuilding the ty binary for every active python package set. + + '' + substituteInPlace pyproject.toml \ + --replace-fail 'requires = ["maturin>=1.0,<2.0"]' 'requires = ["hatchling"]' \ + --replace-fail 'build-backend = "maturin"' 'build-backend = "hatchling.build"' + + cat >> pyproject.toml <