Skip to content

Commit

Permalink
Remove incorrect user of TOX_WORK_DIR global
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 30, 2025
1 parent 25143c7 commit 5440d5c
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 48 deletions.
8 changes: 4 additions & 4 deletions .config/constraints.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,4 @@ cython_debug/
/src/*/_version.py

.DS_Store
_readthedocs
34 changes: 15 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -375,6 +372,7 @@ git_describe_command = [
"v*.*"
]
local_scheme = "no-local-version"
tag_regex = "^(?P<prefix>v)?(?P<version>\\d+[^\\+]*)(?P<suffix>.*)?$"
write_to = "src/tox_ansible/_version.py"

[tool.tomlsort]
Expand All @@ -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"
]
17 changes: 8 additions & 9 deletions src/tox_ansible/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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]


Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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),
Expand Down
20 changes: 14 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand All @@ -94,6 +101,7 @@ deps =
set_env =
{[testenv]set_env}
PIP_CONSTRAINT = /dev/null
UV_CONSTRAINT = /dev/null

[testenv:pkg]
description =
Expand Down

0 comments on commit 5440d5c

Please sign in to comment.