From 71bb783971ab0c47a9b2ba3e99872ec4716487df Mon Sep 17 00:00:00 2001 From: nialov Date: Tue, 14 Jan 2025 17:29:49 +0200 Subject: [PATCH] build: migrate nix build files from nix-extra --- {docs_src/marimo => marimos}/validation.py | 2 +- nix/package.nix | 112 +++++++++++++++++++ per-system.nix | 10 +- pyproject.toml | 2 +- tests/{marimo => marimos}/test_validation.py | 2 +- 5 files changed, 120 insertions(+), 8 deletions(-) rename {docs_src/marimo => marimos}/validation.py (100%) create mode 100644 nix/package.nix rename tests/{marimo => marimos}/test_validation.py (97%) diff --git a/docs_src/marimo/validation.py b/marimos/validation.py similarity index 100% rename from docs_src/marimo/validation.py rename to marimos/validation.py index bd19b7f..e20705c 100644 --- a/docs_src/marimo/validation.py +++ b/marimos/validation.py @@ -16,11 +16,11 @@ def _(): from pathlib import Path import geopandas as gpd + import marimo as mo import pyogrio import fractopo.general import fractopo.tval.trace_validation - import marimo as mo return BytesIO, Path, fractopo, gpd, logging, mo, pyogrio diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..54dcfd9 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,112 @@ +{ buildPythonPackage, lib, click, pytest, geopandas, joblib, matplotlib, numpy +, pandas, rich, scikit-learn, scipy, seaborn, shapely, typer, pytest-regressions +, hypothesis, poetry-core, sphinxHook, pandoc, sphinx-autodoc-typehints +, sphinx-rtd-theme, sphinx-gallery, nbsphinx, notebook, ipython, coverage +, powerlaw, python-ternary, marimo, + +}: + +let + + baseFiles = + [ ../pyproject.toml ../fractopo ../README.rst ../tests ../marimos ]; + docFiles = baseFiles ++ [ ../docs_src ../examples ]; + mkSrc = files: + let + fs = lib.fileset; + sourceFiles = fs.intersection (fs.gitTracked ../.) (fs.unions files); + src = fs.toSource { + root = ../.; + fileset = sourceFiles; + }; + in src; + self = buildPythonPackage { + pname = "fractopo"; + version = "0.7.0"; + + src = mkSrc baseFiles; + + # TODO: Conflicts when other package also includes the same file + # nix puts both in site-packages/ directory + # postPatch = '' + # substituteInPlace pyproject.toml \ + # --replace-fail 'include = ["CHANGELOG.md"]' "" + # ''; + format = "pyproject"; + + nativeBuildInputs = [ + # Uses poetry for install + poetry-core + ]; + + passthru = { + # Enables building package without tests + # nix build .#fractopo.passthru.no-check + no-check = self.overridePythonAttrs (_: { doCheck = false; }); + # Documentation without tests + documentation = self.overridePythonAttrs (prevAttrs: { + src = mkSrc docFiles; + doCheck = false; + nativeBuildInputs = prevAttrs.nativeBuildInputs ++ [ + # Documentation dependencies + sphinxHook + pandoc + sphinx-autodoc-typehints + sphinx-rtd-theme + sphinx-gallery + nbsphinx + notebook + ipython + ]; + sphinxRoot = "docs_src"; + outputs = [ "out" "doc" ]; + }); + }; + + propagatedBuildInputs = [ + click + geopandas + joblib + matplotlib + numpy + pandas + powerlaw + python-ternary + rich + scikit-learn + scipy + seaborn + shapely + typer + ]; + + checkInputs = [ pytest pytest-regressions hypothesis coverage marimo ]; + + # TODO: Should this be precheck or does postInstall affect the docs build as well? + postInstall = '' + HOME="$(mktemp -d)" + export HOME + FRACTOPO_DISABLE_CACHE="1" + export FRACTOPO_DISABLE_CACHE + ''; + + checkPhase = '' + runHook preCheck + python -m coverage run --source fractopo -m pytest --hypothesis-seed=1 + runHook postCheck + ''; + + postCheck = '' + python -m coverage report --fail-under 70 + ''; + + pythonImportsCheck = [ "fractopo" ]; + + meta = with lib; { + homepage = "https://github.com/nialov/fractopo"; + description = "Fracture Network analysis"; + license = licenses.mit; + maintainers = [ maintainers.nialov ]; + }; + }; +in self diff --git a/per-system.nix b/per-system.nix index cae7064..b8ff4d2 100644 --- a/per-system.nix +++ b/per-system.nix @@ -1,4 +1,4 @@ -({ self, inputs, ... }: +({ inputs, ... }: { perSystem = { self', config, system, pkgs, lib, ... }: @@ -12,10 +12,10 @@ (final: prev: { pythonPackagesExtensions = prev.pythonPackagesExtensions ++ [ - (_: pythonPrev: { - "fractopo" = pythonPrev.fractopo.overridePythonAttrs - # Test with local source - (_: { src = self.outPath; }); + (pythonFinal: _: { + fractopo = pythonFinal.callPackage ./nix/package.nix { + inherit inputs; + }; }) ]; inherit (final.python3Packages) fractopo; diff --git a/pyproject.toml b/pyproject.toml index b89b626..7fed6fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ classifiers = [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3 :: Only" ] -include = ["CHANGELOG.md"] +# include = ["CHANGELOG.md"] [tool.poetry.scripts] fractopo = "fractopo.__main__:APP" diff --git a/tests/marimo/test_validation.py b/tests/marimos/test_validation.py similarity index 97% rename from tests/marimo/test_validation.py rename to tests/marimos/test_validation.py index 4801253..ba95e7c 100644 --- a/tests/marimo/test_validation.py +++ b/tests/marimos/test_validation.py @@ -8,7 +8,7 @@ SAMPLE_DATA_DIR = Path(__file__).parent.parent.joinpath("sample_data/") VALIDATION_NOTEBOOK = Path(__file__).parent.parent.parent.joinpath( - "docs_src/marimo/validation.py" + "marimos/validation.py" ) PYTHON_INTERPRETER = sys.executable