From 2074fa159b50bb41ac326d85e256d6fec30bfe5e Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Thu, 29 May 2025 13:30:26 -0700 Subject: [PATCH] python3Packages.quickjs: init at 1.19.4 Due to the new quickjs release on 2025-04-26, there's a minor patch needed to fix things up. --- ...pdate-for-QuickJS-2025-04-26-release.patch | 66 +++++++++++++++++++ .../python-modules/quickjs/default.nix | 58 ++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 3 files changed, 126 insertions(+) create mode 100644 pkgs/development/python-modules/quickjs/0001-Update-for-QuickJS-2025-04-26-release.patch create mode 100644 pkgs/development/python-modules/quickjs/default.nix diff --git a/pkgs/development/python-modules/quickjs/0001-Update-for-QuickJS-2025-04-26-release.patch b/pkgs/development/python-modules/quickjs/0001-Update-for-QuickJS-2025-04-26-release.patch new file mode 100644 index 000000000000..05501f6a220c --- /dev/null +++ b/pkgs/development/python-modules/quickjs/0001-Update-for-QuickJS-2025-04-26-release.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Philip Taron +Date: Thu, 29 May 2025 17:16:43 -0700 +Subject: [PATCH] Update for QuickJS 2025-04-26 release + +Signed-off-by: Philip Taron +--- + setup.py | 6 +++--- + test_quickjs.py | 6 +++--- + 2 files changed, 6 insertions(+), 6 deletions(-) + +diff --git a/setup.py b/setup.py +index 9d17af357dcadc40478789ef9c82ac82632967d3..d0b4ff2bd7f3450f6f055ee9e2eda6b591d70689 100644 +--- a/setup.py ++++ b/setup.py +@@ -16,7 +16,7 @@ if sys.platform == "win32": + # system PATH when compiling. + # 3. The code below will moneky-patch distutils to work. + import distutils.cygwinccompiler +- distutils.cygwinccompiler.get_msvcr = lambda: [] ++ distutils.cygwinccompiler.get_msvcr = lambda: [] + # Make sure that pthreads is linked statically, otherwise we run into problems + # on computers where it is not installed. + extra_link_args = ["-static"] +@@ -26,7 +26,7 @@ def get_c_sources(include_headers=False): + sources = [ + "module.c", + "upstream-quickjs/cutils.c", +- "upstream-quickjs/libbf.c", ++ "upstream-quickjs/dtoa.c", + "upstream-quickjs/libregexp.c", + "upstream-quickjs/libunicode.c", + "upstream-quickjs/quickjs.c", +@@ -34,7 +34,7 @@ def get_c_sources(include_headers=False): + if include_headers: + sources += [ + "upstream-quickjs/cutils.h", +- "upstream-quickjs/libbf.h", ++ "upstream-quickjs/dtoa.h", + "upstream-quickjs/libregexp-opcode.h", + "upstream-quickjs/libregexp.h", + "upstream-quickjs/libunicode-table.h", +diff --git a/test_quickjs.py b/test_quickjs.py +index 1f6dec7ccd15092e98e80a9139ae2acff359b010..9444234655fba9d932ce92c82b9d8da8fe83ad5b 100644 +--- a/test_quickjs.py ++++ b/test_quickjs.py +@@ -105,8 +105,8 @@ class Context(unittest.TestCase): + else: + self.fail("Expected exception.") + +- self.assertIn("at funcA (:3)\n", msg) +- self.assertIn("at funcB (:6)\n", msg) ++ self.assertIn("at funcA (:3:24)\n", msg) ++ self.assertIn("at funcB (:6:26)\n", msg) + + def test_memory_limit(self): + code = """ +@@ -508,7 +508,7 @@ class FunctionTest(unittest.TestCase): + """) + + self.assertEqual(f(100), 100) +- limit = 500 ++ limit = 1500 + with self.assertRaises(quickjs.StackOverflow): + f(limit) + f.set_max_stack_size(2000 * limit) diff --git a/pkgs/development/python-modules/quickjs/default.nix b/pkgs/development/python-modules/quickjs/default.nix new file mode 100644 index 000000000000..1d5726bee259 --- /dev/null +++ b/pkgs/development/python-modules/quickjs/default.nix @@ -0,0 +1,58 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + setuptools, + poetry-core, + pytestCheckHook, + pkgs, +}: + +let + inherit (pkgs) quickjs srcOnly; +in + +buildPythonPackage rec { + pname = "quickjs"; + version = "1.19.4"; + pyproject = true; + + src = fetchFromGitHub { + owner = "PetterS"; + repo = "quickjs"; + tag = version; + hash = "sha256-nLloXJWOuaK/enZfwXJI94IcsAMYrkBtG4i3gmxuhfw="; + }; + + patches = [ ./0001-Update-for-QuickJS-2025-04-26-release.patch ]; + + # Upstream uses Git submodules; let's de-vendor and use Nix, so that we gain security fixes like + # https://github.com/NixOS/nixpkgs/pull/407469 + prePatch = '' + rmdir upstream-quickjs + ln -s ${srcOnly quickjs} upstream-quickjs + ''; + + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail poetry>=1.5.0 poetry \ + --replace-fail poetry poetry-core \ + --replace-fail 'version = "0"' 'version = "${version}"' + ''; + + build-system = [ + poetry-core + setuptools + ]; + + nativeCheckInputs = [ pytestCheckHook ]; + + pythonImportsCheck = [ "quickjs" ]; + + meta = { + description = "Python wrapper around the quickjs C library"; + homepage = "https://github.com/PetterS/quickjs"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ philiptaron ]; + }; +} diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index ea594d439326..08ce80666cde 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -14898,6 +14898,8 @@ self: super: with self; { queuelib = callPackage ../development/python-modules/queuelib { }; + quickjs = callPackage ../development/python-modules/quickjs { }; + quil = callPackage ../development/python-modules/quil { }; quixote = callPackage ../development/python-modules/quixote { };