diff --git a/pyproject.toml b/pyproject.toml index 27143f9..871ee95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -340,6 +340,7 @@ parametrize-values-type = "tuple" known-first-party = ["ansible_dev_environment"] lines-after-imports = 2 # Ensures consistency for cases when there's variable vs function/class definitions after imports lines-between-types = 1 # Separate import/from with 1 line +required-imports = ["from __future__ import annotations"] [tool.ruff.lint.per-file-ignores] "_version.py" = ["SIM108"] diff --git a/src/ansible_dev_environment/__main__.py b/src/ansible_dev_environment/__main__.py index 28dba09..0dc665b 100644 --- a/src/ansible_dev_environment/__main__.py +++ b/src/ansible_dev_environment/__main__.py @@ -4,6 +4,8 @@ via :command:`python -m ansible_dev_environment`. """ +from __future__ import annotations + from ansible_dev_environment.cli import main diff --git a/src/ansible_dev_environment/subcommands/__init__.py b/src/ansible_dev_environment/subcommands/__init__.py index d48f1aa..00abef3 100644 --- a/src/ansible_dev_environment/subcommands/__init__.py +++ b/src/ansible_dev_environment/subcommands/__init__.py @@ -1,6 +1,7 @@ """The subcommands module contains all the subcommands for ansible-dev-environment.""" # ruff: noqa: F401 +from __future__ import annotations from .checker import Checker as Check from .inspector import Inspector as Inspect diff --git a/tests/conftest.py b/tests/conftest.py index 5e7fc1b..e09cb93 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,6 +16,8 @@ Tracing '/**/src//__init__.py' """ +from __future__ import annotations + import json import os import shutil @@ -23,8 +25,8 @@ import tempfile import warnings -from collections.abc import Generator from pathlib import Path +from typing import TYPE_CHECKING from urllib.request import HTTPError, urlopen import pytest @@ -33,7 +35,12 @@ import ansible_dev_environment # noqa: F401 from ansible_dev_environment.cli import Cli -from ansible_dev_environment.config import Config + + +if TYPE_CHECKING: + from collections.abc import Generator + + from ansible_dev_environment.config import Config GALAXY_CACHE = Path(__file__).parent.parent / ".cache" / ".galaxy_cache" diff --git a/tests/integration/test_basic.py b/tests/integration/test_basic.py index cdce183..b1c9259 100644 --- a/tests/integration/test_basic.py +++ b/tests/integration/test_basic.py @@ -1,5 +1,7 @@ """Basic smoke tests.""" +from __future__ import annotations + import json from pathlib import Path diff --git a/tests/test_argparser.py b/tests/test_argparser.py index a5ef043..c4a336d 100644 --- a/tests/test_argparser.py +++ b/tests/test_argparser.py @@ -1,5 +1,7 @@ """Tests for the arg_parser module.""" +from __future__ import annotations + import pytest from ansible_dev_environment.arg_parser import ( diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index d585774..586b257 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -1,13 +1,19 @@ """Test cli functionality.""" -from collections.abc import Generator +from __future__ import annotations + from pathlib import Path +from typing import TYPE_CHECKING import pytest from ansible_dev_environment.cli import Cli +if TYPE_CHECKING: + from collections.abc import Generator + + def main(cli: Cli) -> None: """Stub main function for testing. diff --git a/tests/unit/test_inspector.py b/tests/unit/test_inspector.py index b90d1c4..6aa5192 100644 --- a/tests/unit/test_inspector.py +++ b/tests/unit/test_inspector.py @@ -1,17 +1,24 @@ """Tests for the inspector module.""" +from __future__ import annotations + import copy import importlib import json import re import sys -import pytest +from typing import TYPE_CHECKING -from ansible_dev_environment.config import Config from ansible_dev_environment.subcommands import inspector +if TYPE_CHECKING: + import pytest + + from ansible_dev_environment.config import Config + + def test_output_no_color(session_venv: Config, capsys: pytest.CaptureFixture[str]) -> None: """Test the inspector output. diff --git a/tests/unit/test_installer.py b/tests/unit/test_installer.py index 9ee475e..3acec1c 100644 --- a/tests/unit/test_installer.py +++ b/tests/unit/test_installer.py @@ -1,5 +1,6 @@ # pylint: disable=C0302 """Tests for the installer.""" +from __future__ import annotations import os import shutil @@ -7,20 +8,23 @@ from argparse import Namespace from pathlib import Path -from typing import Any +from typing import TYPE_CHECKING, Any import pytest import yaml from ansible_dev_environment.arg_parser import parse from ansible_dev_environment.cli import Cli -from ansible_dev_environment.collection import Collection from ansible_dev_environment.config import Config -from ansible_dev_environment.output import Output from ansible_dev_environment.subcommands.installer import Installer from ansible_dev_environment.utils import subprocess_run +if TYPE_CHECKING: + from ansible_dev_environment.collection import Collection + from ansible_dev_environment.output import Output + + NAMESPACE = Namespace() NAMESPACE.verbose = 0 diff --git a/tests/unit/test_lister.py b/tests/unit/test_lister.py index 3277444..44a64cc 100644 --- a/tests/unit/test_lister.py +++ b/tests/unit/test_lister.py @@ -1,21 +1,29 @@ """Test the lister module.""" +from __future__ import annotations + import copy import tarfile -from pathlib import Path +from typing import TYPE_CHECKING -import pytest import yaml from ansible_dev_environment.arg_parser import parse from ansible_dev_environment.config import Config -from ansible_dev_environment.output import Output from ansible_dev_environment.subcommands.installer import Installer from ansible_dev_environment.subcommands.lister import Lister from ansible_dev_environment.utils import JSONVal, collect_manifests +if TYPE_CHECKING: + from pathlib import Path + + import pytest + + from ansible_dev_environment.output import Output + + def test_success(session_venv: Config, capsys: pytest.CaptureFixture[str]) -> None: """Test the lister. diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index 0370022..f940f6a 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -1,5 +1,7 @@ """Test the main file.""" +from __future__ import annotations + import runpy import pytest diff --git a/tests/unit/test_treemaker.py b/tests/unit/test_treemaker.py index 05f689a..aaa5fa0 100644 --- a/tests/unit/test_treemaker.py +++ b/tests/unit/test_treemaker.py @@ -1,15 +1,22 @@ """Test the treemaker module.""" +from __future__ import annotations + from argparse import Namespace -from pathlib import Path +from typing import TYPE_CHECKING from venv import EnvBuilder import pytest from ansible_dev_environment.config import Config -from ansible_dev_environment.output import Output from ansible_dev_environment.subcommands.treemaker import TreeMaker, TreeWithReqs, add_python_reqs -from ansible_dev_environment.utils import JSONVal + + +if TYPE_CHECKING: + from pathlib import Path + + from ansible_dev_environment.output import Output + from ansible_dev_environment.utils import JSONVal def test_tree_empty( diff --git a/tests/unit/test_uninstaller.py b/tests/unit/test_uninstaller.py index e4b1e28..18ced85 100644 --- a/tests/unit/test_uninstaller.py +++ b/tests/unit/test_uninstaller.py @@ -1,18 +1,25 @@ """Test the uninstaller module.""" +from __future__ import annotations + import copy -from pathlib import Path +from typing import TYPE_CHECKING import pytest from ansible_dev_environment.arg_parser import parse from ansible_dev_environment.config import Config -from ansible_dev_environment.output import Output from ansible_dev_environment.subcommands.installer import Installer from ansible_dev_environment.subcommands.uninstaller import UnInstaller +if TYPE_CHECKING: + from pathlib import Path + + from ansible_dev_environment.output import Output + + def test_many(session_venv: Config, capsys: pytest.CaptureFixture[str]) -> None: """Test the uninstaller with many collections.