simplify clan cli build expression

also re-expose missing age
This commit is contained in:
Jörg Thalheim
2023-08-03 13:07:00 +02:00
parent e603ee6f49
commit cb0197fcf3
2 changed files with 68 additions and 72 deletions

View File

@@ -1,5 +1,4 @@
{ pkgs { lib
, lib
, python3 , python3
, ruff , ruff
, runCommand , runCommand
@@ -8,45 +7,65 @@
, bubblewrap , bubblewrap
, sops , sops
, age , age
, black
, nix
, mypy
, setuptools
, self , self
, argcomplete
, pytest
, pytest-cov
, pytest-subprocess
, wheel
}: }:
let let
pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml); dependencies = [ argcomplete ];
name = pyproject.project.name;
src = lib.cleanSource ./.; testDependencies = [
dependencies = lib.attrValues {
inherit (python3.pkgs)
argcomplete
;
};
devDependencies = lib.attrValues {
inherit (pkgs) ruff;
inherit (python3.pkgs)
black
mypy
pytest pytest
pytest-cov pytest-cov
pytest-subprocess pytest-subprocess
setuptools mypy
wheel ];
;
};
package = python3.pkgs.buildPythonPackage { checkPython = python3.withPackages (_ps: dependencies ++ testDependencies);
inherit name src; in
python3.pkgs.buildPythonPackage {
name = "clan";
src = lib.cleanSource ./.;
format = "pyproject"; format = "pyproject";
nativeBuildInputs = [ nativeBuildInputs = [
python3.pkgs.setuptools setuptools
installShellFiles installShellFiles
]; ];
propagatedBuildInputs = propagatedBuildInputs = dependencies;
dependencies
++ [ ]; passthru.tests = {
passthru.tests = { inherit clan-mypy clan-pytest; }; clan-mypy = runCommand "clan-mypy" { } ''
passthru.devDependencies = devDependencies; cp -r ${./.} ./src
chmod +w -R ./src
cd src
${checkPython}/bin/mypy .
touch $out
'';
clan-pytest = runCommand "clan-tests"
{
nativeBuildInputs = [ age zerotierone bubblewrap sops nix ];
} ''
cp -r ${./.} ./src
chmod +w -R ./src
cd src
${checkPython}/bin/python -m pytest ./tests
touch $out
'';
};
passthru.devDependencies = [
ruff
black
setuptools
wheel
] ++ testDependencies;
makeWrapperArgs = [ makeWrapperArgs = [
"--set CLAN_FLAKE ${self}" "--set CLAN_FLAKE ${self}"
@@ -54,32 +73,9 @@ let
postInstall = '' postInstall = ''
installShellCompletion --bash --name clan \ installShellCompletion --bash --name clan \
<(${python3.pkgs.argcomplete}/bin/register-python-argcomplete --shell bash clan) <(${argcomplete}/bin/register-python-argcomplete --shell bash clan)
installShellCompletion --fish --name clan.fish \ installShellCompletion --fish --name clan.fish \
<(${python3.pkgs.argcomplete}/bin/register-python-argcomplete --shell fish clan) <(${argcomplete}/bin/register-python-argcomplete --shell fish clan)
''; '';
meta.mainProgram = "clan"; meta.mainProgram = "clan";
}; }
checkPython = python3.withPackages (_ps: devDependencies ++ dependencies);
clan-mypy = runCommand "${name}-mypy" { } ''
cp -r ${src} ./src
chmod +w -R ./src
cd src
${checkPython}/bin/mypy .
touch $out
'';
clan-pytest = runCommand "${name}-tests"
{
nativeBuildInputs = [ zerotierone bubblewrap sops age ];
} ''
cp -r ${src} ./src
chmod +w -R ./src
cd src
${checkPython}/bin/python -m pytest ./tests
touch $out
'';
in
package

View File

@@ -5,7 +5,7 @@
inherit (self'.packages) clan; inherit (self'.packages) clan;
}; };
packages = { packages = {
clan = pkgs.callPackage ./default.nix { clan = pkgs.python3.pkgs.callPackage ./default.nix {
inherit self; inherit self;
zerotierone = self'.packages.zerotierone; zerotierone = self'.packages.zerotierone;
}; };