diff --git a/.config/constraints.txt b/.config/constraints.txt index 53f934a..d9d0aac 100644 --- a/.config/constraints.txt +++ b/.config/constraints.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# tox run deps +# tox run -e deps ansible-compat==25.1.1 # via pytest-ansible astroid==3.3.8 # via pylint attrs==25.1.0 # via jsonschema, referencing @@ -15,7 +15,7 @@ cfgv==3.4.0 # via pre-commit chardet==5.2.0 # via tox charset-normalizer==3.4.1 # via requests click==8.1.8 # via black, mkdocs, mkdocstrings, pydoclint -colorama==0.4.6 # via griffe, mkdocs-material, tox +colorama==0.4.6 # via click, griffe, mkdocs, mkdocs-material, pylint, pytest, tox coverage==7.6.10 # via tox-ansible (pyproject.toml) cryptography==44.0.0 # via ansible-core csscompressor==0.9.5 # via mkdocs-minify-plugin @@ -25,7 +25,6 @@ dill==0.3.9 # via pylint distlib==0.3.9 # via virtualenv dnspython==2.7.0 # via linkchecker docstring-parser-fork==0.0.12 # via pydoclint -exceptiongroup==1.2.2 # via pytest execnet==2.1.1 # via pytest-xdist filelock==3.17.0 # via tox, virtualenv ghp-import==2.1.0 # via mkdocs @@ -96,7 +95,6 @@ termcolor==2.5.0 # via mkdocs-macros-plugin text-unidecode==1.3 # via python-slugify tinycss2==1.4.0 # via cairosvg, cssselect2 toml-sort==0.24.2 # via tox-ansible (pyproject.toml) -tomli==2.2.1 # via black, coverage, mypy, pydoclint, pylint, pyproject-api, pytest, tox tomlkit==0.13.2 # via pylint, toml-sort tox==4.24.1 # via tox-ansible (pyproject.toml) types-pyyaml==6.0.12.20241230 # via tox-ansible (pyproject.toml) @@ -107,5 +105,7 @@ webencodings==0.5.1 # via cssselect2, tinycss2 # The following packages were excluded from the output: # ansible-core +# exceptiongroup # resolvelib +# tomli # typing-extensions diff --git a/.gitignore b/.gitignore index 1b1aca1..e9f95a5 100644 --- a/.gitignore +++ b/.gitignore @@ -169,3 +169,4 @@ cython_debug/ /src/*/_version.py .DS_Store +_readthedocs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3919a75..6bad9a3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,6 +6,8 @@ ci: autofix_commit_msg: "chore: auto fixes from pre-commit.com hooks" skip: + # https://github.com/pre-commit-ci/issues/issues/55 + - lock - deps repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -19,11 +21,6 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/asottile/add-trailing-comma.git - rev: v3.1.0 - hooks: - - id: add-trailing-comma - - repo: https://github.com/Lucas-C/pre-commit-hooks.git rev: v1.5.5 hooks: @@ -33,7 +30,7 @@ repos: .config/pydoclint-baseline.txt )$ - - repo: https://github.com/pycontribs/mirrors-prettier + - repo: https://github.com/rbubley/mirrors-prettier rev: v3.4.2 hooks: - id: prettier @@ -64,11 +61,6 @@ repos: - id: ruff-format # must be after ruff types_or: [python, pyi] - - repo: https://github.com/psf/black # must be after ruff - rev: 25.1.0 - hooks: - - id: black - - repo: https://github.com/streetsidesoftware/cspell-cli rev: v8.17.1 hooks: @@ -106,21 +98,25 @@ repos: # Keep last due to being considerably slower than the others: - repo: local hooks: - - id: up + - id: deps + # To run it execute: `pre-commit run pip-compile-upgrade --hook-stage manual` name: Upgrade constraints files and requirements - files: ^(pyproject\.toml|requirements\.txt)$ + files: ^(pyproject\.toml|\.config/.*)$ + always_run: true language: python - entry: python3 -m uv pip compile --python-version=3.10 -q --all-extras --output-file=.config/constraints.txt pyproject.toml --upgrade + language_version: "3.10" # minimal we support officially https://github.com/astral-sh/uv/issues/3883 + entry: python3 -m uv pip compile -q --all-extras --universal --output-file=.config/constraints.txt pyproject.toml --upgrade pass_filenames: false stages: - manual additional_dependencies: - - uv>=0.4.3 - - id: deps + - uv>=0.5.25 + - id: lock name: Check constraints files and requirements - files: ^(pyproject\.toml|requirements\.txt)$ + files: ^(pyproject\.toml|\.config/.*)$ language: python - entry: python3 -m uv pip compile --python-version=3.10 -q --all-extras --output-file=.config/constraints.txt pyproject.toml + language_version: "3.10" # minimal we support officially https://github.com/astral-sh/uv/issues/3883 + entry: python3 -m uv pip compile -q --all-extras --universal --output-file=.config/constraints.txt pyproject.toml pass_filenames: false additional_dependencies: - - uv>=0.4.3 + - uv>=0.5.25 diff --git a/.readthedocs.yml b/.readthedocs.yml index 78a84d9..6592c91 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -11,7 +11,7 @@ build: python: "3.11" commands: - pip install --user tox - - python3 -m tox -e docs -- --strict --site-dir=_readthedocs/html/ + - python3 -m tox -e docs python: install: - method: pip diff --git a/pyproject.toml b/pyproject.toml index 2aaf4ab..039d213 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,9 +43,6 @@ documentation = "https://ansible.readthedocs.io/projects/tox-ansible/" homepage = "https://github.com/ansible/tox-ansible" repository = "https://github.com/ansible/tox-ansible" -[tool.black] -line-length = 100 - [tool.coverage.report] exclude_also = ["if TYPE_CHECKING:", "pragma: no cover"] fail_under = 81 @@ -375,6 +372,7 @@ git_describe_command = [ "v*.*" ] local_scheme = "no-local-version" +tag_regex = "^(?Pv)?(?P\\d+[^\\+]*)(?P.*)?$" write_to = "src/tox_ansible/_version.py" [tool.tomlsort] @@ -384,5 +382,14 @@ sort_table_keys = true [tool.uv.pip] annotation-style = "line" -custom-compile-command = "tox run deps" -no-emit-package = ["ansible-core", "pip", "resolvelib", "typing_extensions", "uv"] +custom-compile-command = "tox run -e deps" +no-emit-package = [ + "ansible-core", + "exceptiongroup", + "pip", + "resolvelib", + "ruamel-yaml-clib", + "tomli", + "typing_extensions", + "uv" +] diff --git a/src/tox_ansible/plugin.py b/src/tox_ansible/plugin.py index 5bbb168..6e42004 100644 --- a/src/tox_ansible/plugin.py +++ b/src/tox_ansible/plugin.py @@ -47,7 +47,6 @@ {integration, sanity, unit}-py3.12-{2.16, 2.17, 2.18, milestone, devel} {integration, sanity, unit}-py3.13-{2.18, milestone, devel} """ -TOX_WORK_DIR = Path() # Without the minimal pytest-ansible condition, installation may fail in some # cases (pip, uv). OUR_DEPS = [ @@ -178,8 +177,6 @@ def tox_add_core_config( ) logging.warning(msg) - global TOX_WORK_DIR # pylint: disable=global-statement # noqa: PLW0603 - TOX_WORK_DIR = state.conf.work_dir env_list = add_ansible_matrix(state) if not state.conf.options.gh_matrix: @@ -209,7 +206,7 @@ def tox_add_env_config(env_conf: EnvConfigSet, state: State) -> None: ]: return - galaxy_path = TOX_WORK_DIR / "galaxy.yml" + galaxy_path = env_conf._conf._root / "galaxy.yml" # noqa: SLF001 c_name, c_namespace = get_collection_name(galaxy_path=galaxy_path) pos_args = state.conf.pos_args(to_path=None) @@ -449,10 +446,11 @@ def conf_commands_for_integration_unit( The commands to run. """ args = f" {' '.join(pos_args)} " if pos_args else " " + root = Path(__file__).parents[2].resolve() # Use pytest ansible unit inject only to inject the collection path # into the collection finder - command = f"python3 -m pytest --ansible-unit-inject-only{args}{TOX_WORK_DIR}/tests/{test_type}" + command = f"python3 -m pytest --ansible-unit-inject-only{args}{root}/tests/{test_type}" return [command] @@ -521,7 +519,7 @@ def conf_commands_pre( if in_action(): group = "echo ::group::Copy the collection to the galaxy build dir" commands.append(group) - cd_tox_dir = f"cd {TOX_WORK_DIR}" + cd_tox_dir = f"cd {env_conf._conf._root.as_posix()}" # noqa: SLF001 copy_script = ( f"for file in $(git ls-files 2> /dev/null || ls); do\n\t" f"mkdir -p {galaxy_build_dir}/$(dirname $file);\n\t" @@ -570,20 +568,21 @@ def conf_deps(env_conf: EnvConfigSet, test_type: str) -> str: The dependencies. """ deps = [] + root = env_conf._conf._root # noqa: SLF001 if test_type in ["integration", "unit"]: deps.extend(OUR_DEPS) try: - with (TOX_WORK_DIR / "test-requirements.txt").open() as fileh: + with (root / "test-requirements.txt").open() as fileh: deps.extend(fileh.read().splitlines()) except FileNotFoundError: pass try: - with (TOX_WORK_DIR / "requirements-test.txt").open() as fileh: + with (root / "requirements-test.txt").open() as fileh: deps.extend(fileh.read().splitlines()) except FileNotFoundError: pass try: - with (TOX_WORK_DIR / "requirements.txt").open() as fileh: + with (root / "requirements.txt").open() as fileh: deps.extend(fileh.read().splitlines()) except FileNotFoundError: pass diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py index 39fc5ca..96643be 100644 --- a/tests/unit/test_plugin.py +++ b/tests/unit/test_plugin.py @@ -221,7 +221,8 @@ def test_conf_commands_unit(tmp_path: Path) -> None: pos_args=None, ) assert len(result) == 1 - assert result[0] == "python3 -m pytest --ansible-unit-inject-only ./tests/unit" + path = Path("./tests/unit").resolve().as_posix() + assert result[0] == f"python3 -m pytest --ansible-unit-inject-only {path}" def test_conf_commands_sanity(tmp_path: Path) -> None: @@ -282,7 +283,8 @@ def test_conf_commands_integration(tmp_path: Path) -> None: pos_args=None, ) assert len(result) == 1 - assert result[0] == "python3 -m pytest --ansible-unit-inject-only ./tests/integration" + path = Path("./tests/integration").resolve().as_posix() + assert result[0] == f"python3 -m pytest --ansible-unit-inject-only {path}" def test_conf_commands_invalid(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None: @@ -315,7 +317,7 @@ def test_conf_commands_invalid(tmp_path: Path, caplog: pytest.LogCaptureFixture) assert "Unknown test type" in logs -def test_conf_deps(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: +def test_conf_deps(tmp_path: Path) -> None: """Test the conf_commands function. Args: @@ -329,7 +331,6 @@ def test_conf_deps(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: (tmp_path / "test-requirements.txt").write_text("test-requirement") (tmp_path / "requirements.txt").write_text("requirement") (tmp_path / "requirements-test.txt").write_text("requirement-test") - monkeypatch.setattr("tox_ansible.plugin.TOX_WORK_DIR", tmp_path) conf = Config.make( Parsed(work_dir=tmp_path, override=[], config_file=ini_file, root_dir=tmp_path), diff --git a/tox.ini b/tox.ini index 2ed72ba..288b85d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] requires = - tox>=4.11.3 - tox-uv + tox>=4.23.2 + tox-uv>=1.20.2 env_list = py deps @@ -28,6 +28,7 @@ pass_env = USER set_env = !milestone: PIP_CONSTRAINT = {toxinidir}/.config/constraints.txt + !milestone: UV_CONSTRAINT = {toxinidir}/.config/constraints.txt COVERAGE_COMBINED = {envdir}/.coverage COVERAGE_FILE = {env:COVERAGE_FILE:{envdir}/.coverage.{envname}} COVERAGE_PROCESS_START = {toxinidir}/pyproject.toml @@ -56,10 +57,13 @@ deps = extras = set_env = PIP_CONSTRAINT = /dev/null + UV_CONSTRAINT = /dev/null commands_pre = commands = - -pre-commit run --all-files --show-diff-on-failure --hook-stage manual up - -pre-commit autoupdate + pre-commit run --all-files --show-diff-on-failure --hook-stage manual deps + pre-commit run --all-files --show-diff-on-failure lock + pre-commit autoupdate + tox -e lint git diff --exit-code env_dir = {toxworkdir}/lint @@ -70,19 +74,22 @@ skip_install = false extras = docs set_env = + DYLD_FALLBACK_LIBRARY_PATH = /opt/homebrew/lib:{env:LD_LIBRARY_PATH} NO_COLOR = 1 TERM = dump commands = - mkdocs build {posargs:} + mkdocs build {posargs:--strict --site-dir=_readthedocs/html/} [testenv:lint] description = Enforce quality standards under {basepython} skip_install = true deps = pre-commit - pre-commit-uv + pre-commit-uv>=4.1.4 + uv>=0.5.25 set_env = PIP_CONSTRAINT = /dev/null + UV_CONSTRAINT = /dev/null commands = pre-commit run --show-diff-on-failure --all-files @@ -94,6 +101,7 @@ deps = set_env = {[testenv]set_env} PIP_CONSTRAINT = /dev/null + UV_CONSTRAINT = /dev/null [testenv:pkg] description =