From 97ac39aaa41d5bd1142949fea0176897efaae874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sat, 29 Nov 2025 21:02:10 -0800 Subject: [PATCH] python3Packages.typer: use mkPythonMetaPackage This fixes a collision between typer and typer-slim when building python3.withPackages (ps: [ ps.spacy ]) --- .../python-modules/typer-slim/default.nix | 90 +++++++++++++++ .../python-modules/typer/default.nix | 103 +++--------------- pkgs/top-level/python-packages.nix | 2 +- 3 files changed, 104 insertions(+), 91 deletions(-) create mode 100644 pkgs/development/python-modules/typer-slim/default.nix diff --git a/pkgs/development/python-modules/typer-slim/default.nix b/pkgs/development/python-modules/typer-slim/default.nix new file mode 100644 index 000000000000..55c736320c78 --- /dev/null +++ b/pkgs/development/python-modules/typer-slim/default.nix @@ -0,0 +1,90 @@ +{ + lib, + stdenv, + buildPythonPackage, + fetchFromGitHub, + + # build-system + pdm-backend, + + # dependencies + click, + typing-extensions, + + # optional-dependencies + rich, + shellingham, + + # tests + pytest-xdist, + pytestCheckHook, + writableTmpDirAsHomeHook, + procps, +}: + +buildPythonPackage rec { + pname = "typer-slim"; + version = "0.19.2"; + pyproject = true; + + src = fetchFromGitHub { + owner = "fastapi"; + repo = "typer"; + tag = version; + hash = "sha256-mMsOEI4FpLkLkpjxjnUdmKdWD65Zx3Z1+L+XsS79k44="; + }; + + postPatch = '' + for f in $(find tests -type f -print); do + # replace `sys.executable -m coverage run` with `sys.executable` + sed -z -i 's/"-m",\n\?\s*"coverage",\n\?\s*"run",//g' "$f" + done + ''; + + env.TIANGOLO_BUILD_PACKAGE = "typer-slim"; + + build-system = [ pdm-backend ]; + + dependencies = [ + click + typing-extensions + ]; + + optional-dependencies = { + standard = [ + rich + shellingham + ]; + }; + + nativeCheckInputs = [ + pytest-xdist + pytestCheckHook + writableTmpDirAsHomeHook + ] + ++ lib.concatAttrValues optional-dependencies + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + procps + ]; + + disabledTests = [ + "test_scripts" + # Likely related to https://github.com/sarugaku/shellingham/issues/35 + # fails also on Linux + "test_show_completion" + "test_install_completion" + ] + ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [ + "test_install_completion" + ]; + + pythonImportsCheck = [ "typer" ]; + + meta = { + description = "Library for building CLI applications"; + homepage = "https://typer.tiangolo.com/"; + changelog = "https://github.com/tiangolo/typer/releases/tag/${version}"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ winpat ]; + }; +} diff --git a/pkgs/development/python-modules/typer/default.nix b/pkgs/development/python-modules/typer/default.nix index e8f4a22ca4fd..6e1daa7b91e0 100644 --- a/pkgs/development/python-modules/typer/default.nix +++ b/pkgs/development/python-modules/typer/default.nix @@ -1,97 +1,20 @@ { lib, - stdenv, - buildPythonPackage, - fetchFromGitHub, - - # build-system - pdm-backend, - - # dependencies - click, - typing-extensions, - - # optional-dependencies - rich, - shellingham, - - # tests - pytest-xdist, - pytestCheckHook, - writableTmpDirAsHomeHook, - procps, - - # typer or typer-slim - package ? "typer", + mkPythonMetaPackage, + typer-slim, }: -buildPythonPackage rec { - pname = package; - version = "0.19.2"; - pyproject = true; - - src = fetchFromGitHub { - owner = "fastapi"; - repo = "typer"; - tag = version; - hash = "sha256-mMsOEI4FpLkLkpjxjnUdmKdWD65Zx3Z1+L+XsS79k44="; - }; - - postPatch = '' - for f in $(find tests -type f -print); do - # replace `sys.executable -m coverage run` with `sys.executable` - sed -z -i 's/"-m",\n\?\s*"coverage",\n\?\s*"run",//g' "$f" - done - ''; - - env.TIANGOLO_BUILD_PACKAGE = package; - - build-system = [ pdm-backend ]; - - dependencies = [ - click - typing-extensions - ] - # typer includes the standard optional by default - # https://github.com/tiangolo/typer/blob/0.12.3/pyproject.toml#L71-L72 - ++ lib.optionals (package == "typer") optional-dependencies.standard; - - optional-dependencies = { - standard = [ - rich - shellingham - ]; - }; - - doCheck = package == "typer"; # tests expect standard dependencies - - nativeCheckInputs = [ - pytest-xdist - pytestCheckHook - writableTmpDirAsHomeHook - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - procps - ]; - - disabledTests = [ - "test_scripts" - # Likely related to https://github.com/sarugaku/shellingham/issues/35 - # fails also on Linux - "test_show_completion" - "test_install_completion" - ] - ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [ - "test_install_completion" - ]; - - pythonImportsCheck = [ "typer" ]; - +mkPythonMetaPackage { + pname = "typer"; + inherit (typer-slim) version optional-dependencies; + dependencies = [ typer-slim ] ++ typer-slim.optional-dependencies.standard; meta = { - description = "Library for building CLI applications"; - homepage = "https://typer.tiangolo.com/"; - changelog = "https://github.com/tiangolo/typer/releases/tag/${version}"; - license = lib.licenses.mit; - maintainers = with lib.maintainers; [ winpat ]; + inherit (typer-slim.meta) + changelog + description + homepage + license + maintainers + ; }; } diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index e1bba01f0de6..ee857cfe810e 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -19255,7 +19255,7 @@ self: super: with self; { typer-shell = callPackage ../development/python-modules/typer-shell { }; - typer-slim = self.typer.override { package = "typer-slim"; }; + typer-slim = callPackage ../development/python-modules/typer-slim { }; types-aiobotocore = callPackage ../development/python-modules/types-aiobotocore { };