fix mypy errors

This commit is contained in:
Jörg Thalheim
2023-08-23 12:32:06 +02:00
parent 7b7a367ff4
commit 59e31b3c56
3 changed files with 27 additions and 37 deletions

View File

@@ -5,11 +5,17 @@
imports = [ imports = [
inputs.treefmt-nix.flakeModule inputs.treefmt-nix.flakeModule
]; ];
perSystem = { pkgs, ... }: { perSystem = { self', pkgs, ... }: {
treefmt.projectRootFile = "flake.nix"; treefmt.projectRootFile = "flake.nix";
treefmt.flakeCheck = true; treefmt.flakeCheck = true;
treefmt.flakeFormatter = true; treefmt.flakeFormatter = true;
treefmt.programs.shellcheck.enable = true; treefmt.programs.shellcheck.enable = true;
treefmt.programs.mypy.enable = true;
treefmt.programs.mypy.directories = {
"pkgs/clan-cli".extraPythonPackages = self'.packages.clan-cli.testDependencies;
};
treefmt.settings.formatter.nix = { treefmt.settings.formatter.nix = {
command = "sh"; command = "sh";
options = [ options = [
@@ -38,4 +44,3 @@
}; };
}; };
} }

View File

@@ -1,22 +1,18 @@
import argparse import argparse
import sys import sys
from types import ModuleType
from typing import Optional
from . import admin, secrets, update from . import admin, config, secrets, update
from .errors import ClanError from .errors import ClanError
from .ssh import cli as ssh_cli from .ssh import cli as ssh_cli
argcomplete = None argcomplete: Optional[ModuleType] = None
try: try:
import argcomplete import argcomplete # type: ignore[no-redef]
except ImportError: except ImportError:
pass pass
config = None
try:
from . import config
except ImportError: # jsonschema not installed
pass
# this will be the entrypoint under /bin/clan (see pyproject.toml config) # this will be the entrypoint under /bin/clan (see pyproject.toml config)
def main() -> None: def main() -> None:
@@ -26,9 +22,8 @@ def main() -> None:
parser_admin = subparsers.add_parser("admin", help="administrate a clan") parser_admin = subparsers.add_parser("admin", help="administrate a clan")
admin.register_parser(parser_admin) admin.register_parser(parser_admin)
if config: parser_config = subparsers.add_parser("config", help="set nixos configuration")
parser_config = subparsers.add_parser("config", help="set nixos configuration") config.register_parser(parser_config)
config.register_parser(parser_config)
parser_ssh = subparsers.add_parser("ssh", help="ssh to a remote machine") parser_ssh = subparsers.add_parser("ssh", help="ssh to a remote machine")
ssh_cli.register_parser(parser_ssh) ssh_cli.register_parser(parser_ssh)

View File

@@ -3,7 +3,6 @@
, black , black
, bubblewrap , bubblewrap
, installShellFiles , installShellFiles
, mypy
, nix , nix
, openssh , openssh
, pytest , pytest
@@ -31,7 +30,6 @@ let
pytest pytest
pytest-cov pytest-cov
pytest-subprocess pytest-subprocess
mypy
openssh openssh
stdenv.cc stdenv.cc
]; ];
@@ -60,27 +58,17 @@ python3.pkgs.buildPythonPackage {
]; ];
propagatedBuildInputs = dependencies; propagatedBuildInputs = dependencies;
passthru.tests = { passthru.tests.clan-pytest = runCommand "clan-tests"
clan-mypy = runCommand "clan-mypy" { } '' {
export CLAN_OPTIONS_FILE="${CLAN_OPTIONS_FILE}" nativeBuildInputs = [ age zerotierone bubblewrap sops nix openssh rsync stdenv.cc ];
cp -r ${source} ./src } ''
chmod +w -R ./src export CLAN_OPTIONS_FILE="${CLAN_OPTIONS_FILE}"
cd ./src cp -r ${source} ./src
${checkPython}/bin/mypy . chmod +w -R ./src
touch $out cd ./src
''; NIX_STATE_DIR=$TMPDIR/nix ${checkPython}/bin/python -m pytest -s ./tests
clan-pytest = runCommand "clan-tests" touch $out
{ '';
nativeBuildInputs = [ age zerotierone bubblewrap sops nix openssh rsync stdenv.cc ];
} ''
export CLAN_OPTIONS_FILE="${CLAN_OPTIONS_FILE}"
cp -r ${source} ./src
chmod +w -R ./src
cd ./src
NIX_STATE_DIR=$TMPDIR/nix ${checkPython}/bin/python -m pytest -s ./tests
touch $out
'';
};
passthru.devDependencies = [ passthru.devDependencies = [
ruff ruff
@@ -89,6 +77,8 @@ python3.pkgs.buildPythonPackage {
wheel wheel
] ++ testDependencies; ] ++ testDependencies;
passthru.testDependencies = testDependencies;
makeWrapperArgs = [ makeWrapperArgs = [
"--set CLAN_FLAKE ${self}" "--set CLAN_FLAKE ${self}"
]; ];