2023-07-20 23:08:11 +00:00
|
|
|
{ pkgs ? import <nixpkgs> { }
|
|
|
|
, lib ? pkgs.lib
|
|
|
|
, python3 ? pkgs.python3
|
|
|
|
, ruff ? pkgs.ruff
|
|
|
|
, runCommand ? pkgs.runCommand
|
|
|
|
, installShellFiles ? pkgs.installShellFiles
|
2023-07-25 11:46:58 +00:00
|
|
|
, zerotierone ? pkgs.zerotierone
|
|
|
|
, bubblewrap ? pkgs.bubblewrap
|
2023-07-20 23:08:11 +00:00
|
|
|
}:
|
|
|
|
let
|
2023-07-20 16:07:27 +00:00
|
|
|
pyproject = builtins.fromTOML (builtins.readFile ./pyproject.toml);
|
|
|
|
name = pyproject.project.name;
|
2023-07-25 11:46:58 +00:00
|
|
|
# Override license so that we can build zerotierone without
|
|
|
|
# having to re-import nixpkgs.
|
|
|
|
zerotierone' = zerotierone.overrideAttrs (_old: { meta = { }; });
|
2023-07-20 16:07:27 +00:00
|
|
|
|
|
|
|
src = lib.cleanSource ./.;
|
|
|
|
|
|
|
|
dependencies = lib.attrValues {
|
2023-07-20 23:08:11 +00:00
|
|
|
inherit (python3.pkgs)
|
|
|
|
argcomplete
|
|
|
|
;
|
2023-07-20 16:07:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
devDependencies = lib.attrValues {
|
|
|
|
inherit (pkgs) ruff;
|
|
|
|
inherit (python3.pkgs)
|
|
|
|
black
|
|
|
|
mypy
|
|
|
|
pytest
|
|
|
|
pytest-cov
|
2023-07-21 00:01:39 +00:00
|
|
|
pytest-subprocess
|
2023-07-20 16:07:27 +00:00
|
|
|
setuptools
|
|
|
|
wheel
|
|
|
|
;
|
|
|
|
};
|
|
|
|
|
|
|
|
package = python3.pkgs.buildPythonPackage {
|
|
|
|
inherit name src;
|
|
|
|
format = "pyproject";
|
|
|
|
nativeBuildInputs = [
|
|
|
|
python3.pkgs.setuptools
|
2023-07-20 23:08:11 +00:00
|
|
|
installShellFiles
|
2023-07-20 16:07:27 +00:00
|
|
|
];
|
|
|
|
propagatedBuildInputs =
|
|
|
|
dependencies
|
|
|
|
++ [ ];
|
2023-07-25 16:54:26 +00:00
|
|
|
passthru.tests = { inherit clan-mypy clan-pytest; };
|
2023-07-20 16:07:27 +00:00
|
|
|
passthru.devDependencies = devDependencies;
|
2023-07-25 11:46:58 +00:00
|
|
|
|
|
|
|
makeWrapperArgs = [
|
|
|
|
"--set CLAN_NIXPKGS ${pkgs.path}"
|
|
|
|
];
|
|
|
|
|
2023-07-20 23:08:11 +00:00
|
|
|
postInstall = ''
|
|
|
|
installShellCompletion --bash --name clan \
|
|
|
|
<(${python3.pkgs.argcomplete}/bin/register-python-argcomplete --shell bash clan)
|
|
|
|
installShellCompletion --fish --name clan.fish \
|
|
|
|
<(${python3.pkgs.argcomplete}/bin/register-python-argcomplete --shell fish clan)
|
|
|
|
'';
|
2023-07-24 14:49:32 +00:00
|
|
|
meta.mainProgram = "clan";
|
2023-07-20 16:07:27 +00:00
|
|
|
};
|
|
|
|
|
2023-07-21 09:23:10 +00:00
|
|
|
checkPython = python3.withPackages (_ps: devDependencies ++ dependencies);
|
2023-07-20 16:07:27 +00:00
|
|
|
|
2023-07-21 11:31:13 +00:00
|
|
|
clan-mypy = runCommand "${name}-mypy" { } ''
|
2023-07-20 16:07:27 +00:00
|
|
|
cp -r ${src} ./src
|
|
|
|
chmod +w -R ./src
|
|
|
|
cd src
|
|
|
|
${checkPython}/bin/mypy .
|
2023-07-21 11:31:13 +00:00
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
2023-07-25 11:46:58 +00:00
|
|
|
clan-pytest = runCommand "${name}-tests"
|
|
|
|
{
|
|
|
|
nativeBuildInputs = [ zerotierone' bubblewrap ];
|
|
|
|
} ''
|
2023-07-21 11:31:13 +00:00
|
|
|
cp -r ${src} ./src
|
|
|
|
chmod +w -R ./src
|
|
|
|
cd src
|
2023-07-25 17:00:16 +00:00
|
|
|
${checkPython}/bin/python -m pytest ./tests
|
2023-07-20 16:07:27 +00:00
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
package
|