Skip to content

Commit

Permalink
Merge pull request #246963 from tjni/python-ninja
Browse files Browse the repository at this point in the history
python3.pkgs.ninja-python: replace with a stub implementation
  • Loading branch information
FRidh authored Aug 7, 2023
2 parents decf1f8 + 39dd3d1 commit 92e83bf
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 69 deletions.
7 changes: 0 additions & 7 deletions pkgs/development/python-modules/meson-python/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand Down
71 changes: 23 additions & 48 deletions pkgs/development/python-modules/ninja/default.nix
Original file line number Diff line number Diff line change
@@ -1,72 +1,47 @@
{ 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 ];
maintainers = with maintainers; [ _999eagle tjni ];
};
}
10 changes: 0 additions & 10 deletions pkgs/development/python-modules/ninja/no-download.patch

This file was deleted.

9 changes: 9 additions & 0 deletions pkgs/development/python-modules/ninja/stub/ninja/__init__.py
Original file line number Diff line number Diff line change
@@ -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:]))
11 changes: 11 additions & 0 deletions pkgs/development/python-modules/ninja/stub/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions pkgs/tools/misc/nanoemoji/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ python3.pkgs.buildPythonApplication rec {
absl-py
fonttools
lxml
ninja-python
ninja
picosvg
pillow
regex
Expand All @@ -50,7 +50,7 @@ python3.pkgs.buildPythonApplication rec {
nativeCheckInputs = with python3.pkgs; [
pytestCheckHook

ninja-python
ninja
picosvg
];

Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/python-aliases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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
Expand Down
6 changes: 4 additions & 2 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6443,7 +6443,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 { };

Expand Down Expand Up @@ -7035,7 +7037,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 { };

Expand Down

0 comments on commit 92e83bf

Please sign in to comment.