dev: Switch to ruff for python linting & formatting

It combines multiple tools and is much faster.
This commit is contained in:
Felix Uhl committed 2024-11-08 20:12:05 +01:00
1 parent 0d54c7ad3f
commit da8a997397
6 files changed
+15 -16

No files matched your search

+2 -3
View File
@@ -4,8 +4,7 @@
"jnoortheen.nix-ide", "jnoortheen.nix-ide",
"ms-python.python", "ms-python.python",
"ms-python.debugpy", "ms-python.debugpy",
"ms-python.black-formatter", "ms-python.mypy-type-checker",
"ms-python.isort", "charliermarsh.ruff"
"ms-python.mypy-type-checker"
] ]
} }
+8 -5
View File
@@ -80,15 +80,13 @@
{ {
default = pkgs.mkShell { default = pkgs.mkShell {
name = "disko-dev"; name = "disko-dev";
packages = with pkgs; [ packages = (with pkgs; [
ruff # Formatter and linter
(python3.withPackages (ps: [ (python3.withPackages (ps: [
ps.black # Code formatter
ps.isort # Import sorter
ps.mypy # Static type checker ps.mypy # Static type checker
ps.autoflake # Remove unused imports automatically
ps.pytest # Test runner ps.pytest # Test runner
])) ]))
]; ]);
}; };
}); });
@@ -110,6 +108,7 @@
nixpkgs-fmt nixpkgs-fmt
deno deno
deadnix deadnix
ruff
]; ];
text = '' text = ''
showUsage() { showUsage() {
@@ -154,12 +153,16 @@
nixpkgs-fmt -- "''${files[@]}" nixpkgs-fmt -- "''${files[@]}"
deno fmt -- "''${files[@]}" deno fmt -- "''${files[@]}"
deadnix --edit -- "''${files[@]}" deadnix --edit -- "''${files[@]}"
ruff check --fix
ruff format
else else
set -o xtrace set -o xtrace
nixpkgs-fmt --check -- "''${files[@]}" nixpkgs-fmt --check -- "''${files[@]}"
deno fmt --check -- "''${files[@]}" deno fmt --check -- "''${files[@]}"
deadnix -- "''${files[@]}" deadnix -- "''${files[@]}"
ruff check
ruff format --check
fi fi
} }
+1 -1
View File
@@ -112,7 +112,7 @@ def parse_args() -> argparse.Namespace:
add_common_apply_args(parser) add_common_apply_args(parser)
# Other commands # Other commands
generate_parser = mode_parsers.add_parser( _generate_parser = mode_parsers.add_parser(
"generate", "generate",
help=MODE_DESCRIPTION["generate"], help=MODE_DESCRIPTION["generate"],
) )
-1
View File
@@ -1,6 +1,5 @@
import argparse import argparse
import json import json
from logging import info
from typing import Any, assert_never from typing import Any, assert_never
from disko_lib.ansi import Colors from disko_lib.ansi import Colors
+4 -5
View File
@@ -2,7 +2,7 @@ import json
from pathlib import Path from pathlib import Path
from typing import Any from typing import Any
from disko_lib.logging import ReadableMessage from disko_lib.logging import ReadableMessage
from .colors import * from .colors import PLACEHOLDER, RESET, FLAG, COMMAND, INVALID, FILE, VALUE, EM, EM_WARN
ERR_ARGUMENTS_HELP_TXT = f"Provide either {PLACEHOLDER}disko_file{RESET} as the second argument or \ ERR_ARGUMENTS_HELP_TXT = f"Provide either {PLACEHOLDER}disko_file{RESET} as the second argument or \
{FLAG}--flake{RESET}/{FLAG}-f{RESET} {PLACEHOLDER}flake-uri{RESET}." {FLAG}--flake{RESET}/{FLAG}-f{RESET} {PLACEHOLDER}flake-uri{RESET}."
@@ -12,7 +12,7 @@ def err_command_failed(*, command: str, exit_code: int, stderr: str) -> Readable
return ReadableMessage( return ReadableMessage(
"error", "error",
f""" f"""
Command failed: {COMMAND}{command}{COMMAND} Command failed: {COMMAND}{command}{RESET}
Exit code: {INVALID}{exit_code}{RESET} Exit code: {INVALID}{exit_code}{RESET}
stderr: {stderr} stderr: {stderr}
""", """,
@@ -20,7 +20,6 @@ def err_command_failed(*, command: str, exit_code: int, stderr: str) -> Readable
def err_eval_config_failed(*, args: dict[str, Any], stderr: str) -> ReadableMessage: def err_eval_config_failed(*, args: dict[str, Any], stderr: str) -> ReadableMessage:
return ReadableMessage( return ReadableMessage(
"error", "error",
f""" f"""
@@ -51,7 +50,7 @@ def err_missing_arguments() -> list[ReadableMessage]:
return [ return [
ReadableMessage( ReadableMessage(
"error", "error",
f"Missing arguments!", "Missing arguments!",
), ),
ReadableMessage("help", ERR_ARGUMENTS_HELP_TXT), ReadableMessage("help", ERR_ARGUMENTS_HELP_TXT),
] ]
@@ -61,7 +60,7 @@ def err_too_many_arguments() -> list[ReadableMessage]:
return [ return [
ReadableMessage( ReadableMessage(
"error", "error",
f"Too many arguments!", "Too many arguments!",
), ),
ReadableMessage("help", ERR_ARGUMENTS_HELP_TXT), ReadableMessage("help", ERR_ARGUMENTS_HELP_TXT),
] ]
-1
View File
@@ -1,6 +1,5 @@
import json import json
from pathlib import Path, PosixPath from pathlib import Path, PosixPath
import pytest
from disko_lib.messages import err_unsupported_pttype, warn_generate_partial_failure from disko_lib.messages import err_unsupported_pttype, warn_generate_partial_failure
from disko_lib.result import DiskoError, DiskoSuccess from disko_lib.result import DiskoError, DiskoSuccess