From 2af6de63ab2cfbefa55759d126e89c6a32935bad Mon Sep 17 00:00:00 2001 From: June Stepp Date: Mon, 20 Oct 2025 14:45:45 -0500 Subject: [PATCH] python3Packages.typesense: init at 1.1.1 --- .../python-modules/typesense/default.nix | 78 +++++++++++++++++++ .../typesense/generated-temp-path.patch | 18 +++++ .../typesense/linux-only-metrics.patch | 48 ++++++++++++ pkgs/top-level/python-packages.nix | 4 + 4 files changed, 148 insertions(+) create mode 100644 pkgs/development/python-modules/typesense/default.nix create mode 100644 pkgs/development/python-modules/typesense/generated-temp-path.patch create mode 100644 pkgs/development/python-modules/typesense/linux-only-metrics.patch diff --git a/pkgs/development/python-modules/typesense/default.nix b/pkgs/development/python-modules/typesense/default.nix new file mode 100644 index 000000000000..78441621aa8d --- /dev/null +++ b/pkgs/development/python-modules/typesense/default.nix @@ -0,0 +1,78 @@ +{ + lib, + buildPythonPackage, + fetchFromGitHub, + setuptools, + requests, + pytestCheckHook, + typesense, + curl, + pytest-mock, + requests-mock, + python-dotenv, + faker, + isort, +}: + +buildPythonPackage rec { + pname = "typesense"; + version = "1.1.1"; + pyproject = true; + + src = fetchFromGitHub { + owner = "typesense"; + repo = "typesense-python"; + tag = "v${version}"; + hash = "sha256-vo9DW4kinb00zWW4yX8ibyelQxW3eVabn+oMddPEd18="; + }; + + patches = [ + # See . + ./linux-only-metrics.patch + ./generated-temp-path.patch + ]; + + build-system = [ setuptools ]; + + dependencies = [ requests ]; + + nativeCheckInputs = [ + pytestCheckHook + typesense + curl + pytest-mock + requests-mock + python-dotenv + faker + isort + ]; + disabledTestMarks = [ "open_ai" ]; + disabledTests = [ "import_typing_extensions" ]; + + __darwinAllowLocalNetworking = true; + + preCheck = '' + TYPESENSE_API_KEY="xyz" \ + TYPESENSE_DATA_DIR="$(mktemp -d)" \ + typesense-server & + + typesense_pid=$! + + # Wait for typesense to finish starting. + timeout 20 bash -c ' + while ! curl -s --fail localhost:8108/health; do sleep 1; done + ' || false + ''; + postCheck = '' + kill $typesense_pid + ''; + + pythonImportsCheck = [ "typesense" ]; + + meta = { + description = "Python client for Typesense, an open source and typo tolerant search engine"; + homepage = "https://github.com/typesense/typesense-python"; + license = lib.licenses.asl20; + teams = [ lib.teams.ngi ]; + }; +} diff --git a/pkgs/development/python-modules/typesense/generated-temp-path.patch b/pkgs/development/python-modules/typesense/generated-temp-path.patch new file mode 100644 index 000000000000..ddb15e2ea64d --- /dev/null +++ b/pkgs/development/python-modules/typesense/generated-temp-path.patch @@ -0,0 +1,18 @@ +diff --git a/tests/operations_test.py b/tests/operations_test.py +index 34bb74c..39f9265 100644 +--- a/tests/operations_test.py ++++ b/tests/operations_test.py +@@ -51,11 +51,11 @@ def test_cache_clear(actual_operations: Operations) -> None: + assert response["success"] + + +-def test_snapshot(actual_operations: Operations) -> None: ++def test_snapshot(actual_operations: Operations, tmp_path) -> None: + """Test that the Operations object can perform the snapshot operation.""" + response = actual_operations.perform( + "snapshot", +- {"snapshot_path": "/tmp"}, # noqa: S108 ++ {"snapshot_path": str(tmp_path)}, # noqa: S108 + ) + + assert response["success"] diff --git a/pkgs/development/python-modules/typesense/linux-only-metrics.patch b/pkgs/development/python-modules/typesense/linux-only-metrics.patch new file mode 100644 index 000000000000..ac667a3e42f1 --- /dev/null +++ b/pkgs/development/python-modules/typesense/linux-only-metrics.patch @@ -0,0 +1,48 @@ +From 9f0024ae3a0377d15788256c72af7a692d250afc Mon Sep 17 00:00:00 2001 +From: dotlambda +Date: Thu, 23 Oct 2025 13:40:33 -0700 +Subject: [PATCH] test(metrics): some metrics only exists on Linux + +--- + tests/metrics_test.py | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +diff --git a/tests/metrics_test.py b/tests/metrics_test.py +index 1e1ea47..fecf3c0 100644 +--- a/tests/metrics_test.py ++++ b/tests/metrics_test.py +@@ -2,6 +2,8 @@ + + from __future__ import annotations + ++import platform ++ + from typesense.metrics import Metrics + + +@@ -9,13 +11,15 @@ def test_actual_retrieve(actual_metrics: Metrics) -> None: + """Test that the Debug object can retrieve a debug on Typesense server and verify response structure.""" + response = actual_metrics.retrieve() + +- assert "system_cpu_active_percentage" in response ++ if platform.system() == "Linux": ++ assert "system_cpu_active_percentage" in response ++ assert "system_network_received_bytes" in response ++ assert "system_network_sent_bytes" in response ++ + assert "system_disk_total_bytes" in response + assert "system_disk_used_bytes" in response + assert "system_memory_total_bytes" in response + assert "system_memory_used_bytes" in response +- assert "system_network_received_bytes" in response +- assert "system_network_sent_bytes" in response + assert "typesense_memory_active_bytes" in response + assert "typesense_memory_allocated_bytes" in response + assert "typesense_memory_fragmentation_ratio" in response +@@ -23,4 +27,4 @@ def test_actual_retrieve(actual_metrics: Metrics) -> None: + assert "typesense_memory_mapped_bytes" in response + assert "typesense_memory_metadata_bytes" in response + assert "typesense_memory_resident_bytes" in response +- assert "typesense_memory_retained_bytes" in response +\ No newline at end of file ++ assert "typesense_memory_retained_bytes" in response diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 5277ed027e11..6c3d704f0516 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -19619,6 +19619,10 @@ self: super: with self; { types-xxhash = callPackage ../development/python-modules/types-xxhash { }; + typesense = callPackage ../development/python-modules/typesense { + inherit (pkgs) typesense curl; + }; + typesentry = callPackage ../development/python-modules/typesentry { }; typeshed-client = callPackage ../development/python-modules/typeshed-client { };