From 99524a94ff31e1443a09d4b5326f5e69dd698b71 Mon Sep 17 00:00:00 2001 From: Theodore Ni <3806110+tjni@users.noreply.github.com> Date: Thu, 3 Aug 2023 06:33:36 -0700 Subject: [PATCH 1/4] python3.pkgs.ninja-python: add tjni as a maintainer of this stub --- pkgs/development/python-modules/ninja/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/development/python-modules/ninja/default.nix b/pkgs/development/python-modules/ninja/default.nix index d3ab12c29a55b..056c7663fb213 100644 --- a/pkgs/development/python-modules/ninja/default.nix +++ b/pkgs/development/python-modules/ninja/default.nix @@ -67,6 +67,6 @@ buildPythonPackage rec { description = "A small build system with a focus on speed"; homepage = "https://github.com/scikit-build/ninja-python-distributions"; license = licenses.asl20; - maintainers = with maintainers; [ _999eagle ]; + maintainers = with maintainers; [ _999eagle tjni ]; }; } From d36556b8a5db361933833d33876f4e8a815d1e0d Mon Sep 17 00:00:00 2001 From: Theodore Ni <3806110+tjni@users.noreply.github.com> Date: Thu, 3 Aug 2023 06:06:34 -0700 Subject: [PATCH 2/4] python3.pkgs.ninja-python: replace with a stub implementation Instead of packaging the upstream package, which downloads Ninja from the web, we can stub it out to use ninja from nixpkgs. --- .../python-modules/ninja/default.nix | 69 ++++++------------- .../python-modules/ninja/no-download.patch | 10 --- .../ninja/stub/ninja/__init__.py | 9 +++ .../python-modules/ninja/stub/pyproject.toml | 11 +++ 4 files changed, 42 insertions(+), 57 deletions(-) delete mode 100644 pkgs/development/python-modules/ninja/no-download.patch create mode 100644 pkgs/development/python-modules/ninja/stub/ninja/__init__.py create mode 100644 pkgs/development/python-modules/ninja/stub/pyproject.toml diff --git a/pkgs/development/python-modules/ninja/default.nix b/pkgs/development/python-modules/ninja/default.nix index 056c7663fb213..0ff6785693029 100644 --- a/pkgs/development/python-modules/ninja/default.nix +++ b/pkgs/development/python-modules/ninja/default.nix @@ -1,70 +1,45 @@ { lib , buildPythonPackage -, fetchFromGitHub -, fetchurl -, cmake -, setuptools-scm -, scikit-build -, pytestCheckHook -, pytest-virtualenv +, flit-core +, ninja }: -let - # these must match NinjaUrls.cmake - ninja_src_url = "https://github.com/Kitware/ninja/archive/v1.11.1.g95dee.kitware.jobserver-1.tar.gz"; - ninja_src_sha256 = "7ba84551f5b315b4270dc7c51adef5dff83a2154a3665a6c9744245c122dd0db"; - ninja_src = fetchurl { - url = ninja_src_url; - sha256 = ninja_src_sha256; - }; -in + buildPythonPackage rec { pname = "ninja"; - version = "1.11.1"; + inherit (ninja) version; format = "pyproject"; - src = fetchFromGitHub { - owner = "scikit-build"; - repo = "ninja-python-distributions"; - rev = version; - hash = "sha256-scCYsSEyN+u3qZhNhWYqHpJCl+JVJJbKz+T34gOXGJM="; - }; - patches = [ - # make sure cmake doesn't try to download the ninja sources - ./no-download.patch - ]; + src = ./stub; - inherit ninja_src; postUnpack = '' - # assume that if the hash matches, the source should be fine - if ! grep "${ninja_src_sha256}" $sourceRoot/NinjaUrls.cmake; then - echo "ninja_src_sha256 doesn't match the hash in NinjaUrls.cmake!" - exit 1 - fi - mkdir -p "$sourceRoot/Ninja-src" - pushd "$sourceRoot/Ninja-src" - tar -xavf ${ninja_src} --strip-components 1 - popd - ''; + substituteInPlace "$sourceRoot/pyproject.toml" \ + --subst-var version - postPatch = '' - sed -i '/cov/d' setup.cfg + substituteInPlace "$sourceRoot/ninja/__init__.py" \ + --subst-var-by BIN_DIR "${ninja}/bin" ''; - dontUseCmakeConfigure = true; + inherit (ninja) setupHook; nativeBuildInputs = [ - setuptools-scm - scikit-build - cmake + flit-core ]; - nativeCheckInputs = [ - pytestCheckHook - pytest-virtualenv + preBuild = '' + cp "${ninja.src}/misc/ninja_syntax.py" ninja/ninja_syntax.py + ''; + + pythonImportsCheck = [ + "ninja" + "ninja.ninja_syntax" ]; meta = with lib; { description = "A small build system with a focus on speed"; + longDescription = '' + This is a stub of the ninja package on PyPI that uses the ninja program + provided by nixpkgs instead of downloading ninja from the web. + ''; homepage = "https://github.com/scikit-build/ninja-python-distributions"; license = licenses.asl20; maintainers = with maintainers; [ _999eagle tjni ]; diff --git a/pkgs/development/python-modules/ninja/no-download.patch b/pkgs/development/python-modules/ninja/no-download.patch deleted file mode 100644 index 0937a5fde1ea9..0000000000000 --- a/pkgs/development/python-modules/ninja/no-download.patch +++ /dev/null @@ -1,10 +0,0 @@ ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -64,6 +64,7 @@ - # Download selected source archive - ExternalProject_add(download_ninja_source - SOURCE_DIR ${Ninja_SOURCE_DIR} -+ DOWNLOAD_COMMAND "" - URL ${${src_archive}_url} - URL_HASH SHA256=${${src_archive}_sha256} - DOWNLOAD_DIR ${ARCHIVE_DOWNLOAD_DIR} diff --git a/pkgs/development/python-modules/ninja/stub/ninja/__init__.py b/pkgs/development/python-modules/ninja/stub/ninja/__init__.py new file mode 100644 index 0000000000000..d85e4b6dab344 --- /dev/null +++ b/pkgs/development/python-modules/ninja/stub/ninja/__init__.py @@ -0,0 +1,9 @@ +import os +import subprocess +import sys + +def _program(name, args): + return subprocess.call([os.path.join('@BIN_DIR@', name)] + args, close_fds=False) + +def ninja(): + raise SystemExit(_program('ninja', sys.argv[1:])) diff --git a/pkgs/development/python-modules/ninja/stub/pyproject.toml b/pkgs/development/python-modules/ninja/stub/pyproject.toml new file mode 100644 index 0000000000000..0a8a6314288a6 --- /dev/null +++ b/pkgs/development/python-modules/ninja/stub/pyproject.toml @@ -0,0 +1,11 @@ +[build-system] +requires = ["flit_core"] +build-backend = "flit_core.buildapi" + +[project] +name = "ninja" +version = "@version@" +description = "Ninja is a small build system with a focus on speed" + +[project.scripts] +ninja = "ninja:ninja" From a586a9e55fcb0c3e961c49f9945f1078fb60ea7f Mon Sep 17 00:00:00 2001 From: Theodore Ni <3806110+tjni@users.noreply.github.com> Date: Thu, 3 Aug 2023 20:04:15 -0700 Subject: [PATCH 3/4] python3.pkgs.ninja: rename from ninja-python I am hoping this can be a transparent shim for most if not all Python packages that acts as a proxy to the actual ninja package in nixpkgs. If this works, doing it this way simplifies rolling out the new Python build hooks that do stricter build dependency validation. --- pkgs/tools/misc/nanoemoji/default.nix | 4 ++-- pkgs/top-level/python-aliases.nix | 1 + pkgs/top-level/python-packages.nix | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgs/tools/misc/nanoemoji/default.nix b/pkgs/tools/misc/nanoemoji/default.nix index 93817ff847987..401783bcc4a1a 100644 --- a/pkgs/tools/misc/nanoemoji/default.nix +++ b/pkgs/tools/misc/nanoemoji/default.nix @@ -36,7 +36,7 @@ python3.pkgs.buildPythonApplication rec { absl-py fonttools lxml - ninja-python + ninja picosvg pillow regex @@ -50,7 +50,7 @@ python3.pkgs.buildPythonApplication rec { nativeCheckInputs = with python3.pkgs; [ pytestCheckHook - ninja-python + ninja picosvg ]; diff --git a/pkgs/top-level/python-aliases.nix b/pkgs/top-level/python-aliases.nix index 21f3ee1f4a4b2..34839da3c1e89 100644 --- a/pkgs/top-level/python-aliases.nix +++ b/pkgs/top-level/python-aliases.nix @@ -209,6 +209,7 @@ mapAliases ({ mutmut = throw "mutmut has been promoted to a top-level attribute"; # added 2022-10-02 net2grid = gridnet; # add 2022-04-22 nghttp2 = throw "in 1.52.0 removed deprecated python bindings."; # added 2023-06-08 + ninja-python = ninja; # add 2022-08-03 nose-cover3 = throw "nose-cover3 has been removed, it was using setuptools 2to3 translation feature, which has been removed in setuptools 58"; # added 2022-02-16 nose_progressive = throw "nose_progressive has been removed, it was using setuptools 2to3 translation feature, which has been removed in setuptools 58"; #added 2023-02-21 notifymuch = throw "notifymuch has been promoted to a top-level attribute"; # added 2022-10-02 diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 008e5ecd4247d..7424e43e9c805 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -7036,7 +7036,7 @@ self: super: with self; { nine = callPackage ../development/python-modules/nine { }; - ninja-python = callPackage ../development/python-modules/ninja { }; + ninja = callPackage ../development/python-modules/ninja { inherit (pkgs) ninja; }; nipy = callPackage ../development/python-modules/nipy { }; From 39dd3d18bc2819b332d480aa1dd8d1084d0a635a Mon Sep 17 00:00:00 2001 From: Theodore Ni <3806110+tjni@users.noreply.github.com> Date: Thu, 3 Aug 2023 22:12:05 -0700 Subject: [PATCH 4/4] python3.pkgs.meson-python: depend on top-level ninja This is a build tool that depends on a ninja binary directly, not through the ninja PyPI package. --- pkgs/development/python-modules/meson-python/default.nix | 7 ------- pkgs/top-level/python-packages.nix | 4 +++- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/pkgs/development/python-modules/meson-python/default.nix b/pkgs/development/python-modules/meson-python/default.nix index 866512a4cfdd6..4b45ee4e77d34 100644 --- a/pkgs/development/python-modules/meson-python/default.nix +++ b/pkgs/development/python-modules/meson-python/default.nix @@ -43,13 +43,6 @@ buildPythonPackage rec { ./add-build-flags.sh ]; - # Ugly work-around. Drop ninja dependency. - # We already have ninja, but it comes without METADATA. - # Building ninja-python-distributions is the way to go. - postPatch = '' - substituteInPlace pyproject.toml --replace "'ninja'," "" - ''; - meta = { changelog = "https://github.com/mesonbuild/meson-python/blob/${version}/CHANGELOG.rst"; description = "Meson Python build backend (PEP 517)"; diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 7424e43e9c805..9d7df6be84d2e 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -6442,7 +6442,9 @@ self: super: with self; { mesonpep517 = callPackage ../development/python-modules/mesonpep517 { }; - meson-python = callPackage ../development/python-modules/meson-python { }; + meson-python = callPackage ../development/python-modules/meson-python { + inherit (pkgs) ninja; + }; messagebird = callPackage ../development/python-modules/messagebird { };