Unverified Commit 7b22218f authored by Jacek Galowicz's avatar Jacek Galowicz Committed by GitHub
Browse files

Merge pull request #258165 from Mic92/nixos-tests-cleanup

nixos/test-driver: modernize project setup and switch to new, stricter linting/type checking settings
parents cad9cf0d f1450e66
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
@@ -4,19 +4,20 @@
, qemu_pkg ? qemu_test
, coreutils
, imagemagick_light
, libtiff
, netpbm
, qemu_test
, socat
, ruff
, tesseract4
, vde2
, extraPythonPackages ? (_ : [])
}:

python3Packages.buildPythonApplication rec {
python3Packages.buildPythonApplication {
  pname = "nixos-test-driver";
  version = "1.1";
  src = ./.;
  format = "pyproject";

  propagatedBuildInputs = [
    coreutils
@@ -31,14 +32,13 @@ python3Packages.buildPythonApplication rec {
    ++ extraPythonPackages python3Packages;

  doCheck = true;
  nativeCheckInputs = with python3Packages; [ mypy pylint black ];
  nativeCheckInputs = with python3Packages; [ mypy ruff black ];
  checkPhase = ''
    mypy --disallow-untyped-defs \
          --no-implicit-optional \
          --pretty \
          --no-color-output \
          --ignore-missing-imports ${src}/test_driver
    pylint --errors-only --enable=unused-import ${src}/test_driver
    black --check --diff ${src}/test_driver
    echo -e "\x1b[32m## run mypy\x1b[0m"
    mypy test_driver extract-docstrings.py
    echo -e "\x1b[32m## run ruff\x1b[0m"
    ruff .
    echo -e "\x1b[32m## run black\x1b[0m"
    black --check --diff .
  '';
}
+25 −17
Original line number Diff line number Diff line
import ast
import sys
from pathlib import Path

"""
This program takes all the Machine class methods and prints its methods in
@@ -40,10 +41,13 @@ some_function(param1, param2)

"""

assert len(sys.argv) == 2

with open(sys.argv[1], "r") as f:
    module = ast.parse(f.read())
def main() -> None:
    if len(sys.argv) != 2:
        print(f"Usage: {sys.argv[0]} <path-to-test-driver>")
        sys.exit(1)

    module = ast.parse(Path(sys.argv[1]).read_text())

    class_definitions = (node for node in module.body if isinstance(node, ast.ClassDef))

@@ -55,12 +59,16 @@ function_definitions = [
    ]
    function_definitions.sort(key=lambda x: x.name)

for f in function_definitions:
    docstr = ast.get_docstring(f)
    for function in function_definitions:
        docstr = ast.get_docstring(function)
        if docstr is not None:
        args = ", ".join((a.arg for a in f.args.args[1:]))
            args = ", ".join(a.arg for a in function.args.args[1:])
            args = f"({args})"

        docstr = "\n".join((f"    {l}" for l in docstr.strip().splitlines()))
            docstr = "\n".join(f"    {line}" for line in docstr.strip().splitlines())

            print(f"{function.name}{args}\n\n:{docstr[1:]}\n")


        print(f"{f.name}{args}\n\n:{docstr[1:]}\n")
if __name__ == "__main__":
    main()
+44 −0
Original line number Diff line number Diff line
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "nixos-test-driver"
version = "0.0.0"

[project.scripts]
nixos-test-driver = "test_driver:main"
generate-driver-symbols = "test_driver:generate_driver_symbols"

[tool.setuptools.packages]
find = {}

[tool.setuptools.package-data]
test_driver = ["py.typed"]

[tool.ruff]
line-length = 88

select = ["E", "F", "I", "U", "N"]
ignore = ["E501"]

# xxx: we can import https://pypi.org/project/types-colorama/ here
[[tool.mypy.overrides]]
module = "colorama.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "ptpython.*"
ignore_missing_imports = true

[tool.black]
line-length = 88
target-version = ['py39']
include = '\.pyi?$'

[tool.mypy]
python_version = "3.10"
warn_redundant_casts = true
disallow_untyped_calls = true
disallow_untyped_defs = true
no_implicit_optional = true

nixos/lib/test-driver/setup.py

deleted100644 → 0
+0 −14
Original line number Diff line number Diff line
from setuptools import setup, find_packages

setup(
  name="nixos-test-driver",
  version='1.1',
  packages=find_packages(),
  package_data={"test_driver": ["py.typed"]},
  entry_points={
    "console_scripts": [
      "nixos-test-driver=test_driver:main",
      "generate-driver-symbols=test_driver:generate_driver_symbols"
    ]
  },
)
+2 −0
Original line number Diff line number Diff line
with import ../../.. {};
pkgs.callPackage ./default.nix {}
Loading