From 77a1350ca6351e1789bd46840b1bafb8813f8204 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 29 Aug 2024 14:11:02 +0200 Subject: [PATCH] Add antsibull-fileutils dependency. --- .github/workflows/antsibull-docs.yml | 6 +++ .github/workflows/antsibull.yml | 6 +++ .github/workflows/nox.yml | 5 +++ README.md | 17 ++++++++ .../fragments/166-antsibull-fileutils.yml | 4 ++ noxfile.py | 43 +++++++++++++++++-- pyproject.toml | 2 +- 7 files changed, 78 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/166-antsibull-fileutils.yml diff --git a/.github/workflows/antsibull-docs.yml b/.github/workflows/antsibull-docs.yml index 88ee47f..e8bb5cc 100644 --- a/.github/workflows/antsibull-docs.yml +++ b/.github/workflows/antsibull-docs.yml @@ -37,6 +37,12 @@ jobs: ref: main path: antsibull-docs-parser + - name: Check out dependent project antsibull-fileutils + uses: actions/checkout@v4 + with: + repository: ansible-community/antsibull-fileutils + path: antsibull-fileutils + # nb: this is the first version of antsibull-docs that declares support # for antsibull-core v3. - name: Check out antsibull-docs main diff --git a/.github/workflows/antsibull.yml b/.github/workflows/antsibull.yml index 0e5c45a..2de0610 100644 --- a/.github/workflows/antsibull.yml +++ b/.github/workflows/antsibull.yml @@ -30,6 +30,12 @@ jobs: with: path: antsibull-core + - name: Check out dependent project antsibull-fileutils + uses: actions/checkout@v4 + with: + repository: ansible-community/antsibull-fileutils + path: antsibull-fileutils + # antsibull 0.61.0 depends on antsibull-changelog >= 0.24.0 as well, so install 0.24.0 of that - name: Check out antsibull-changelog 0.24.0 uses: actions/checkout@v4 diff --git a/.github/workflows/nox.yml b/.github/workflows/nox.yml index fe818eb..d7923c8 100644 --- a/.github/workflows/nox.yml +++ b/.github/workflows/nox.yml @@ -47,6 +47,11 @@ jobs: uses: actions/checkout@v4 with: path: antsibull-core + - name: Check out dependent project antsibull-fileutils + uses: actions/checkout@v4 + with: + repository: ansible-community/antsibull-fileutils + path: antsibull-fileutils - name: Install extra packages if: "matrix.packages != ''" run: | diff --git a/README.md b/README.md index 0142866..5197631 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,23 @@ Install and run `nox` to run all tests. That's it for simple contributions! `nox` will create virtual environments in `.nox` inside the checked out project and install the requirements needed to run the tests there. +--- + +antsibull-core depends on the sister antsibull-fileutils project. +By default, `nox` will install a development version of this project from Github. +If you're hacking on antsibull-fileutils alongside antsibull-core, +nox will automatically install this project from `../antsibull-fileutils` +when running tests if this path exists. +You can change this behavior through the `OTHER_ANTSIBULL_MODE` env var: + +- `OTHER_ANTSIBULL_MODE=auto` — the default behavior described above +- `OTHER_ANTSIBULL_MODE=local` — install the project from `../antsibull-fileutils`. + Fail if this path doesn't exist. +- `OTHER_ANTSIBULL_MODE=git` — install the project from the Github main branch +- `OTHER_ANTSIBULL_MODE=pypi` — install the latest version from PyPI + +--- + To run specific tests: 1. `nox -e test` to only run unit tests; diff --git a/changelogs/fragments/166-antsibull-fileutils.yml b/changelogs/fragments/166-antsibull-fileutils.yml new file mode 100644 index 0000000..634c480 --- /dev/null +++ b/changelogs/fragments/166-antsibull-fileutils.yml @@ -0,0 +1,4 @@ +minor_changes: + - Antsibull-core now depends on the new project antsibull-fileutils. Some code has been moved to that library; + that code is re-imported to avoid breaking changes for users of antsibull-core + (https://github.com/ansible-community/antsibull-core/pull/166). diff --git a/noxfile.py b/noxfile.py index 94aa6cc..d389ea3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -10,6 +10,7 @@ import nox +DEFAULT_MODE = os.environ.get("OTHER_ANTSIBULL_MODE", "auto") IN_CI = "GITHUB_ACTIONS" in os.environ ALLOW_EDITABLE = os.environ.get("ALLOW_EDITABLE", str(not IN_CI)).lower() in ( "1", @@ -33,11 +34,45 @@ def install(session: nox.Session, *args, editable=False, **kwargs): session.install(*args, "-U", **kwargs) +def other_antsibull( + mode: str | None = None, +) -> list[str | Path]: + if mode is None: + mode = DEFAULT_MODE + to_install: list[str | Path] = [] + args = ("antsibull-fileutils",) + for project in args: + path = Path("../", project) + path_exists = path.is_dir() + if mode == "auto": + if path_exists: + mode = "local" + else: + mode = "git" + if mode == "local": + if not path_exists: + raise ValueError(f"Cannot install {project}! {path} does not exist!") + if ALLOW_EDITABLE: + to_install.append("-e") + to_install.append(path) + elif mode == "git": + to_install.append( + f"{project} @ " + f"https://github.com/ansible-community/{project}/archive/main.tar.gz" + ) + elif mode == "pypi": + to_install.append(project) + else: + raise ValueError(f"install_other_antsibull: invalid argument mode={mode!r}") + return to_install + + @nox.session(python=["3.9", "3.10", "3.11", "3.12"]) def test(session: nox.Session): install( session, ".[test, coverage]", + *other_antsibull(), editable=True, ) covfile = Path(session.create_tmp(), ".coverage") @@ -58,7 +93,7 @@ def test(session: nox.Session): @nox.session def coverage(session: nox.Session): - install(session, ".[coverage]", editable=True) + install(session, ".[coverage]", *other_antsibull(), editable=True) combined = map(str, Path().glob(".nox/*/tmp/.coverage")) # Combine the results into a single .coverage file in the root session.run("coverage", "combine", "--keep", *combined) @@ -77,7 +112,7 @@ def lint(session: nox.Session): @nox.session def formatters(session: nox.Session): - install(session, ".[formatters]") + install(session, ".[formatters]", *other_antsibull()) posargs = list(session.posargs) if IN_CI: posargs.append("--check") @@ -87,7 +122,7 @@ def formatters(session: nox.Session): @nox.session def codeqa(session: nox.Session): - install(session, ".[codeqa]", editable=True) + install(session, ".[codeqa]", *other_antsibull(), editable=True) session.run("flake8", "src", *session.posargs) session.run("pylint", "--rcfile", ".pylintrc.automated", "src/antsibull_core") session.run("reuse", "lint") @@ -97,7 +132,7 @@ def codeqa(session: nox.Session): @nox.session def typing(session: nox.Session): # pyre does not work when we don't install ourself in editable mode 🙄. - install(session, "-e", ".[typing]") + install(session, "-e", ".[typing]", *other_antsibull()) session.run("mypy", "src/antsibull_core") purelib = ( diff --git a/pyproject.toml b/pyproject.toml index 1b03dea..159fe09 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ classifiers = [ ] requires-python = ">=3.9" dependencies = [ + "antsibull-fileutils >= 1.0.0, < 2.0.0", "aiofiles", "aiohttp >= 3.3.0", "build", @@ -36,7 +37,6 @@ dependencies = [ "perky", # pydantic v2 is a major rewrite "pydantic ~= 2.0", - "PyYAML", "semantic_version", # 0.5.0 introduces dict_config "twiggy >= 0.5.0",