Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nox tool support #167

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .config/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ click >= 7.1.2
colorama # for Windows
diskcache >= 5.2.1
importlib-metadata
packaging
pip>=21.0.1 # py_package
pluggy
pygments
Expand Down
2 changes: 2 additions & 0 deletions playbooks/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
url: https://github.com/python/typeshed.git
- name: flask-babel
url: https://github.com/python-babel/flask-babel.git
- name: nox
url: https://github.com/wntrblm/nox
tasks:
- name: Show cache directory
ansible.builtin.debug:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pre-commit = "mk.tools.pre_commit:PreCommitTool"
shell = "mk.tools.shell:ShellTool"
taskfile = "mk.tools.taskfile:TaskfileTool"
tox = "mk.tools.tox:ToxTool"
nox = "mk.tools.nox:NoxTool"

[tool.black]

Expand Down
18 changes: 18 additions & 0 deletions samples/integration/nox.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
build
conda_tests-3.10
conda_tests-3.7
conda_tests-3.8
conda_tests-3.9
cover
docs
install
lint
lint2
test
tests-3.10
tests-3.11
tests-3.12
tests-3.7
tests-3.8
tests-3.9
uninstall
47 changes: 47 additions & 0 deletions src/mk/tools/nox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Implementation of the nox tool support.
"""

from __future__ import annotations

import json
import logging
from pathlib import Path

from packaging.version import Version

from mk.exec import run_or_fail
from mk.tools import Action, Tool

# This is the first version to support --json
_MINIMUM_NOX_VERSION = Version("2023.04.22")


class NoxTool(Tool):
name = "nox"

def is_present(self, path: Path) -> bool:
return (path / "noxfile.py").is_file()

def actions(self) -> list[Action]:
actions: list[Action] = []
version: str = run_or_fail(["nox", "--version"], tee=False).stderr.strip()
if Version(version) < _MINIMUM_NOX_VERSION:
logging.warning(
"Failed to retrieve nox sessions: "
"nox version %s is too old. Minimum supported version is %s.",
version,
_MINIMUM_NOX_VERSION,
)
return []
results = run_or_fail(["nox", "--list", "--json"], tee=False)
data = json.loads(results.stdout)
actions = [
Action(session["session"], tool=self, description=session["description"])
for session in data
]
return actions

def run(self, action: Action | None = None) -> None:
cmd = ["nox"] if not action else ["nox", "-s", action.name]
run_or_fail(cmd, tee=True)
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist =
pkg
py
integration
minversion = 3.23.0
minversion = 4.11.3
isolated_build = true
skip_missing_interpreters = false
requires =
Expand Down Expand Up @@ -100,11 +100,16 @@ description = Run integrations tests
setenv =
ANSIBLE_NOCOWS=1
ANSIBLE_FORCE_COLOR=1
extras =
test
deps =
-e .[test]
ansible-core>=2.12
nox
commands =
ansible --version
nox --version
mk test-integration
package = editable

[testenv:pkg]
description =
Expand Down