Skip to content

Commit

Permalink
build: migrate nix build files from nix-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
nialov committed Jan 14, 2025
1 parent 761f295 commit 71bb783
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs_src/marimo/validation.py → marimos/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
112 changes: 112 additions & 0 deletions nix/package.nix
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions per-system.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
({ self, inputs, ... }:
({ inputs, ... }:

{
perSystem = { self', config, system, pkgs, lib, ... }:
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 71bb783

Please sign in to comment.