Initial commit

This commit is contained in:
Zhongwei Li
2025-11-29 18:02:30 +08:00
commit e03e44248d
17 changed files with 785 additions and 0 deletions

View File

@@ -0,0 +1,76 @@
{
lib,
buildPythonPackage,
fetchFromGitHub,
setuptools,
docstring-parser,
gitpython,
httpx,
pydantic-settings,
pydantic,
python-dotenv,
python-multipart,
pyyaml,
rich,
tomli,
typer,
typing-extensions,
# optional
tantivy,
pylance,
lancedb,
qdrant-client,
unstructured,
markdown,
aiofiles,
}:
buildPythonPackage rec {
pname = "agno";
version = "1.7.11";
pyproject = true;
src = fetchFromGitHub {
owner = "agno-agi";
repo = "agno";
rev = "v${version}";
hash = "sha256-9oO4qyYCgMnC1jtFr39Y76t/5/ybUGIhECP+PLhm92s=";
};
sourceRoot = "${src.name}/libs/agno";
build-system = [ setuptools ];
dependencies = [
docstring-parser
gitpython
httpx
pydantic-settings
pydantic
python-dotenv
python-multipart
pyyaml
rich
tomli
typer
typing-extensions
];
optional-dependencies = {
lancedb = [ lancedb tantivy ];
pylance = [ pylance ]; # Useful for lancedb "hybrid" search
qdrant = [ qdrant-client ];
markdown = [ unstructured markdown aiofiles ];
};
pythonImportsCheck = [ "agno" ];
meta = {
description = "Full-stack framework for building Multi-Agent Systems with memory, knowledge and reasoning";
homepage = "https://github.com/agno-agi/agno";
license = lib.licenses.mpl20;
maintainers = with lib.maintainers; [ ];
mainProgram = "agno";
platforms = lib.platforms.all;
};
}

View File

@@ -0,0 +1,61 @@
{ lib, buildPythonPackage, fetchFromGitHub, pythonRelaxDepsHook, setuptools
, holidays, joblib, matplotlib, nfoursid, numpy, pandas, pmdarima, pyod
, requests, scikit-learn, scipy, shap
# , statsforecast
, statsmodels, tbats, tqdm, typing-extensions, xarray, xgboost
, pytorch-lightning }:
buildPythonPackage rec {
pname = "darts";
version = "0.31.0";
format = "pyproject";
src = fetchFromGitHub {
owner = "unit8co";
repo = pname;
rev = version;
hash = "sha256-piSYRJIFr3RQTt/idfTRrqx/dD794He4d2F9flBJv7Q=";
};
nativeBuildInputs = [ pythonRelaxDepsHook ];
buildInputs = [ setuptools ];
propagatedBuildInputs = [
holidays
joblib
matplotlib
nfoursid
numpy
pandas
pmdarima
pyod
requests
scikit-learn
scipy
shap
# statsforecast
statsmodels
tbats
tqdm
typing-extensions
xarray
xgboost
pytorch-lightning
];
pythonRelaxDeps = [ "pmdarima" ];
pythonRemoveDeps = [ "statsforecast" ];
pythonImportsCheck = [ "darts" ];
meta = with lib; {
description = ''
A python library for user-friendly forecasting and anomaly detection on time series
'';
homepage = "https://unit8co.github.io/darts/";
license = licenses.asl20;
maintainers = with maintainers; [ breakds ];
};
}

View File

@@ -0,0 +1,47 @@
# Package a Python Module with Nix
Packaging a Python module (`buildPythonPackage`) involves determining the source, dependencies, and build system, typically from `pyproject.toml`. Ensure all dependencies are already packaged before referencing them.
More complex cases require special handling. Below are examples for different scenarios.
## Normal Python Module
See the simple example: [tyro](./tyro/package.nix)
## Customize Build System and Disable Tests
Some Python modules require additional build tools, or have tests that cannot run in the Nix sandbox. See [Swanboard](./swanboard/package.nix) for an example.
## Customize Source Root and Optional Dependencies
See [agno](./agno/package.nix) for examples of:
- Using `sourceRoot` when the Python module's root differs from the project root (specify the relative path).
- Handling optional dependencies: include them in `optional-dependencies` when available, or safely omit them if not yet packaged.
## Rust-Backed Python Module
For Python packages implemented in Rust with Python bindings, use `rustPlatform` as a helper. See [tantivy](./tantivy/package.nix) for an example.
## Relax or Remove Dependencies
When dependency requirements cannot be satisfied, investigate further:
1. **Version mismatch**: If the dependency is packaged but the version requirement is too strict, add it to `pythonRelaxDeps` to bypass version checking.
2. **Missing dependency**: If the dependency is not packaged, assess whether it's essential for your use case. If not, add it to `pythonRemoveDeps`.
See [darts](./darts/package.nix) for an example.
## Updating an Existing Python Package
Besides the general update steps, also:
1. **Update dependencies**: Check `pyproject.toml` or `setup.py` for changed dependencies and update:
- `dependencies` - Runtime dependencies
- `build-system` - Build-time dependencies (e.g., setuptools, poetry-core)
- `optional-dependencies` - If relevant to your use case
2. **Handle breaking changes**: New versions may:
- Drop Python version support (update `pythonOlder` or `disabled`)
- Change build backends (update `build-system` based on `pyproject.toml`)
- Add new test dependencies (update `nativeCheckInputs` or `checkInputs`)

View File

@@ -0,0 +1,44 @@
{ lib, buildPythonPackage, pythonOlder, fetchFromGitHub, pytestCheckHook
, hatchling, hatch-fancy-pypi-readme, hatch-requirements-txt, swankit, fastapi
, uvicorn, peewee, ujson, psutil, pyyaml, setuptools, nanoid, numpy }:
# TODO(breakds): Build the UI. It seemed pretty straight forward but
# for some reason I will run into this "dead spiral" of fetchYarnDeps
# always complain about a changed yarn.lock (and hash).
buildPythonPackage rec {
pname = "swanboard";
version = "0.1.7-beta.1";
format = "pyproject";
disabled = pythonOlder "3.8";
src = fetchFromGitHub {
owner = "SwanHubX";
repo = "SwanLab-Dashboard";
rev = "v${version}";
hash = "sha256-jBYlBJaEZPJ2tORfeSUnTpwyAjENh8QYTfVb6o2UNZg=";
};
build-system =
[ hatchling hatch-fancy-pypi-readme hatch-requirements-txt setuptools ];
dependencies = [ swankit fastapi uvicorn peewee ujson psutil pyyaml ];
pythonImportsCheck = [ "swanboard" ];
nativeCheckInputs = [ pytestCheckHook nanoid numpy ];
disabledTests = [
"test_get_package_version_installed"
"test_get_package_version_not_installed"
# Temporarily disable because there is a small bug that needs to be fixed.
"TestExperiment"
];
meta = with lib; {
description = "Swanlab's Dashboard";
homepage = "https://github.com/SwanHubX/SwanLab-Dashboard";
license = licenses.asl20;
maintainers = with maintainers; [ breakds ];
};
}

View File

@@ -0,0 +1,39 @@
{
lib
, buildPythonPackage
, fetchFromGitHub
, rustPlatform
}:
buildPythonPackage rec {
pname = "tantivy";
version = "0.25.0";
format = "pyproject";
src = fetchFromGitHub {
owner = "quickwit-oss";
repo = "tantivy-py";
tag = version;
hash = "sha256-ZVQOzKojBf7yNkgiOV4huNnuxCmiFwJb610sD4M2/MU=";
};
cargoDeps = rustPlatform.fetchCargoVendor {
inherit pname version src;
hash = "sha256-/OADcVm01PbHp3bcw62Zt6+9ZmT96Bic+EBbPUhdoOI=";
};
build-system = with rustPlatform; [ cargoSetupHook maturinBuildHook ];
pythonImportsCheck = [ "tantivy" ];
meta = {
description = ''
Python bindings for Tantivy; Tantivy is a full-text search engine library
inspired by Apache Lucene and written in Rust
'';
homepage = "https://github.com/quickwit-oss/tantivy-py";
changeLog = "https://github.com/quickwit-oss/tantivy-py/releases/tag/${version}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ breakds ];
};
}

View File

@@ -0,0 +1,27 @@
{ lib, buildPythonPackage, fetchFromGitHub, setuptools, docstring-parser
, typing-extensions, rich, shtab, typeguard, hatchling }:
buildPythonPackage rec {
pname = "tyro";
version = "0.9.9";
format = "pyproject";
src = fetchFromGitHub {
owner = "brentyi";
repo = pname;
rev = "v${version}";
hash = "sha256-iFKgnKd4606S/hEMHD7ZaTnGF16gmvbaE62nifw4o7c=";
};
build-system = [ hatchling ];
dependencies = [ docstring-parser typing-extensions rich shtab typeguard ];
pythonImportsCheck = [ "tyro" ];
meta = with lib; {
description = "tool for generating CLI interfaces in Python";
homepage = "https://brentyi.github.io/tyro";
license = licenses.mit;
};
}