Skip to content

Commit

Permalink
Add nox tool support
Browse files Browse the repository at this point in the history
  • Loading branch information
gotmax23 authored and ssbarnea committed Jan 11, 2024
1 parent 86f6fe7 commit abc834d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
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
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
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)

0 comments on commit abc834d

Please sign in to comment.