1{ 2 lib, 3 python, 4 buildPythonPackage, 5 fetchFromGitHub, 6 hatchling, 7 hatch-autorun, 8 pytestCheckHook, 9 runCommand, 10}: 11 12buildPythonPackage rec { 13 pname = "auto-lazy-imports"; # matches pypi 14 version = "0.4.2"; 15 pyproject = true; 16 17 src = fetchFromGitHub { 18 owner = "hmiladhia"; 19 repo = "lazyimports"; 20 tag = "v${version}"; 21 hash = "sha256-DPk/fupBuYmm7Xy5+qFkqeRoglflECuX8A0C2ncARhI="; 22 }; 23 24 build-system = [ 25 hatchling 26 hatch-autorun 27 ]; 28 29 pythonImportsCheck = [ 30 "lazyimports" 31 ]; 32 33 nativeCheckInputs = [ 34 pytestCheckHook 35 ]; 36 37 preInstallCheck = '' 38 if [[ -f "$out/${python.sitePackages}"/hatch_autorun_auto_lazy_imports.pth ]]; then 39 echo >&2 "Found hatch_autorun_auto_lazy_imports.pth in site-packages" 40 else 41 echo >&2 "ERROR: no hatch_autorun_auto_lazy_imports.pth file found in site-packages, please re-check derivation assumptions" 42 false 43 fi 44 ''; 45 46 preCheck = '' 47 # Makes python load the .pth file in site-packages 48 export NIX_PYTHONPATH="$out/${python.sitePackages}''${NIX_PYTHONPATH:+:"$NIX_PYTHONPATH"}" 49 ''; 50 51 # check if NIX_PYTHONPATH is properly set in downstream environments 52 passthru.tests = { 53 check-autorun-pyenv = 54 runCommand "${pname}-check-autorun-pyenv" 55 { 56 nativeBuildInputs = [ 57 (python.withPackages (ps: [ 58 ps.auto-lazy-imports 59 ps.pytest 60 ])) 61 ]; 62 } 63 '' 64 pytest ${src}/tests && touch $out 65 ''; 66 67 # TODO: this requires user to set NIX_PYTHONPATH 68 # check-autorun-env = 69 # runCommand "${pname}-check-autorun-env" 70 # { 71 # nativeBuildInputs = [ 72 # python 73 # python.pkgs.auto-lazy-imports 74 # python.pkgs.pytest 75 # ]; 76 # } 77 # '' 78 # pytest ${src}/tests && touch $out 79 # ''; 80 }; 81 82 meta = { 83 description = "Enable lazy imports using native python syntax"; 84 homepage = "https://github.com/hmiladhia/lazyimports"; 85 license = lib.licenses.mit; 86 maintainers = with lib.maintainers; [ pbsds ]; 87 }; 88}