From 59e31b3c56ce8d1c1e19b173049931a95127ec0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 23 Aug 2023 12:32:06 +0200 Subject: [PATCH] fix mypy errors --- formatter.nix | 9 ++++++-- pkgs/clan-cli/clan_cli/__init__.py | 19 ++++++---------- pkgs/clan-cli/default.nix | 36 +++++++++++------------------- 3 files changed, 27 insertions(+), 37 deletions(-) diff --git a/formatter.nix b/formatter.nix index bcd04f69b..a6019c09b 100644 --- a/formatter.nix +++ b/formatter.nix @@ -5,11 +5,17 @@ imports = [ inputs.treefmt-nix.flakeModule ]; - perSystem = { pkgs, ... }: { + perSystem = { self', pkgs, ... }: { treefmt.projectRootFile = "flake.nix"; treefmt.flakeCheck = true; treefmt.flakeFormatter = 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 = { command = "sh"; options = [ @@ -38,4 +44,3 @@ }; }; } - diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index 31c8b2ffc..0b5619cb5 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -1,22 +1,18 @@ import argparse 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 .ssh import cli as ssh_cli -argcomplete = None +argcomplete: Optional[ModuleType] = None try: - import argcomplete + import argcomplete # type: ignore[no-redef] except ImportError: 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) def main() -> None: @@ -26,9 +22,8 @@ def main() -> None: parser_admin = subparsers.add_parser("admin", help="administrate a clan") admin.register_parser(parser_admin) - if config: - parser_config = subparsers.add_parser("config", help="set nixos configuration") - config.register_parser(parser_config) + parser_config = subparsers.add_parser("config", help="set nixos configuration") + config.register_parser(parser_config) parser_ssh = subparsers.add_parser("ssh", help="ssh to a remote machine") ssh_cli.register_parser(parser_ssh) diff --git a/pkgs/clan-cli/default.nix b/pkgs/clan-cli/default.nix index 9939d1b10..883fe175b 100644 --- a/pkgs/clan-cli/default.nix +++ b/pkgs/clan-cli/default.nix @@ -3,7 +3,6 @@ , black , bubblewrap , installShellFiles -, mypy , nix , openssh , pytest @@ -31,7 +30,6 @@ let pytest pytest-cov pytest-subprocess - mypy openssh stdenv.cc ]; @@ -60,27 +58,17 @@ python3.pkgs.buildPythonPackage { ]; propagatedBuildInputs = dependencies; - passthru.tests = { - clan-mypy = runCommand "clan-mypy" { } '' - export CLAN_OPTIONS_FILE="${CLAN_OPTIONS_FILE}" - cp -r ${source} ./src - chmod +w -R ./src - cd ./src - ${checkPython}/bin/mypy . - touch $out - ''; - clan-pytest = runCommand "clan-tests" - { - 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.tests.clan-pytest = runCommand "clan-tests" + { + 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 = [ ruff @@ -89,6 +77,8 @@ python3.pkgs.buildPythonPackage { wheel ] ++ testDependencies; + passthru.testDependencies = testDependencies; + makeWrapperArgs = [ "--set CLAN_FLAKE ${self}" ];