Skip to content

Commit

Permalink
Add antsibull-fileutils dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Aug 29, 2024
1 parent 8f674f6 commit 77a1350
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/antsibull-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/antsibull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/nox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions changelogs/fragments/166-antsibull-fileutils.yml
Original file line number Diff line number Diff line change
@@ -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).
43 changes: 39 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"antsibull-fileutils >= 1.0.0, < 2.0.0",
"aiofiles",
"aiohttp >= 3.3.0",
"build",
Expand All @@ -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",
Expand Down

0 comments on commit 77a1350

Please sign in to comment.