From 9d942c5b6c92047da5c76525a16d8a3f7cf50b1b Mon Sep 17 00:00:00 2001 From: jonboh Date: Sun, 21 Apr 2024 16:08:16 +0200 Subject: [PATCH] solidpython2: init at 2.1.0 --- .../python-modules/solidpython2/default.nix | 49 +++++++++++++++++++ .../solidpython2/difftool_tests.patch | 35 +++++++++++++ pkgs/top-level/python-packages.nix | 2 + 3 files changed, 86 insertions(+) create mode 100644 pkgs/development/python-modules/solidpython2/default.nix create mode 100644 pkgs/development/python-modules/solidpython2/difftool_tests.patch diff --git a/pkgs/development/python-modules/solidpython2/default.nix b/pkgs/development/python-modules/solidpython2/default.nix new file mode 100644 index 000000000000..54dd8e2c2004 --- /dev/null +++ b/pkgs/development/python-modules/solidpython2/default.nix @@ -0,0 +1,49 @@ +{ buildPythonPackage +, fetchFromGitHub +, lib +, ply +, setuptools +, poetry-core +, withOpenSCAD ? false +, openscad +}: +buildPythonPackage rec { + pname = "solidpython2"; + version = "2.1.0"; + pyproject = true; + src = fetchFromGitHub { + owner = "jeff-dh"; + repo = "SolidPython"; + rev = "v${version}"; + hash = "sha256-Tq3hrsC2MmueCqChk6mY/u/pCjF/pFuU2o3K+qw7ImY="; + }; + + # NOTE: this patch makes tests runnable outside the source-tree + # - it uses diff instead of git-diff + # - modifies the tests output to resemble the paths resulting from running inside the source-tree + # - drop the openscad image geneneration tests, these don't work on the nix sandbox due to the need for xserver + patches = [ ./difftool_tests.patch ]; + + propagatedBuildInputs = lib.optionals withOpenSCAD [openscad]; + + build-system = [ + poetry-core + ]; + dependencies = [ + ply + setuptools + ]; + pythonImportsCheck = [ "solid2" ]; + checkPhase = '' + runHook preCheck + python $TMPDIR/source/tests/run_tests.py + runHook postCheck + ''; + + meta = with lib; { + homepage = "https://github.com/jeff-dh/SolidPython"; + description = "A python frontend for solid modelling that compiles to OpenSCAD"; + license = licenses.lgpl2Plus; + maintainers = with maintainers; [ jonboh ]; + }; +} diff --git a/pkgs/development/python-modules/solidpython2/difftool_tests.patch b/pkgs/development/python-modules/solidpython2/difftool_tests.patch new file mode 100644 index 000000000000..a5c950a9fc03 --- /dev/null +++ b/pkgs/development/python-modules/solidpython2/difftool_tests.patch @@ -0,0 +1,35 @@ +diff --git a/tests/examples_test.py b/tests/examples_test.py +index 77204fd..9784389 100644 +--- a/tests/examples_test.py ++++ b/tests/examples_test.py +@@ -48,14 +48,19 @@ class ExamplesTest(unittest.TestCase): + subprocess.check_call(["python3", f.as_posix()]) + # copy generated scad file to examples_scad/ + copyWithRelativeIncludes(f.with_suffix(".scad"), test_scad_file) +- # call git diff test/examples_scad/{f}.scad +- diff = subprocess.check_output(["git", "diff", +- test_scad_file.as_posix()]) +- # make sure there's no diff +- self.assertEqual(diff.decode(), "") +- # render with openscad +- subprocess.check_call([get_openscad_executable(), "-o", +- test_scad_file.with_suffix(".png"), +- "--preview", "-", +- test_scad_file], +- stderr=subprocess.DEVNULL) ++ subprocess.check_call( ++ [ ++ "sed", ++ "-i", ++ f"s#^include <.*/solid2#include <../../solid2#g", ++ test_scad_file.as_posix(), ++ ] ++ ) ++ nixsrc = os.getenv("src") ++ subprocess.check_call( ++ [ ++ "diff", ++ f"{nixsrc}/tests/examples_scad/{f.with_suffix('.scad').name}", ++ test_scad_file.as_posix(), ++ ] ++ ) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 05c01a7cf9ed..e1fe4cf20c79 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -14046,6 +14046,8 @@ self: super: with self; { solc-select = callPackage ../development/python-modules/solc-select { }; + solidpython2 = callPackage ../development/python-modules/solidpython2 { }; + solo-python = disabledIf (!pythonAtLeast "3.6") (callPackage ../development/python-modules/solo-python { }); somajo = callPackage ../development/python-modules/somajo { };