Commit f06a9f3e authored by Benjamin Sparks's avatar Benjamin Sparks
Browse files

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.
parent 6bbbaab0
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
{
  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 <<EOF
      [tool.hatch.build]
      packages = ['python/ty']

      EOF
    '';

  postInstall = ''
    mkdir -p $out/bin && ln -s ${lib.getExe ty} $out/bin/ty
  '';

  pythonImportsCheck = [ "ty" ];
}
+2 −0
Original line number Diff line number Diff line
@@ -19685,6 +19685,8 @@ self: super: with self; {
  txzmq = callPackage ../development/python-modules/txzmq { };
  ty = callPackage ../development/python-modules/ty { inherit (pkgs) ty; };
  type-infer = callPackage ../development/python-modules/type-infer { };
  typechecks = callPackage ../development/python-modules/typechecks { };