Browse Source

added repo caching to noxfile

main
Holger Frey 1 year ago
parent
commit
ab691a4709
  1. 45
      noxfile.py

45
noxfile.py

@ -1,9 +1,42 @@ @@ -1,9 +1,42 @@
import pathlib
import tempfile
import typing
import nox
class RepoCache:
"""class for caching checkouts of downstream repos
By caching the checkouts for downstream test runs,
the nox invokation is faster and there is less load
on the git server and network.
"""
_checkouts: typing.ClassVar = {}
@classmethod
def clone(cls, session: nox.Session, repo: str) -> str:
"""clones a git repo only once
Arguments:
session: the nox session in use
repo: a git repo url
Returns:
path to a temporary directory containing the
cloned git repo
"""
tmpdir = cls._checkouts.get(repo, None)
if tmpdir is None:
tmpdir = tempfile.TemporaryDirectory()
session.run("git", "clone", repo, tmpdir.name, external=True)
cls._checkouts[repo] = tmpdir
return tmpdir.name
@nox.session(python=["3.9", "3.10", "3.11"])
def tests(session):
session.install(".[test]")
@ -19,12 +52,10 @@ def tests(session): @@ -19,12 +52,10 @@ def tests(session):
],
)
def downstream(session, repo, test_dir):
session.install(".")
with tempfile.TemporaryDirectory() as tmpdir:
session.run("git", "clone", repo, tmpdir, external=True)
tmpdir = RepoCache.clone(session, repo)
session.install(f"{tmpdir}[test]")
session.install(".")
session.install(f"{tmpdir}[test]")
test_path = pathlib.Path(tmpdir) / test_dir
session.run("pytest", test_path)
test_path = pathlib.Path(tmpdir) / test_dir
session.run("pytest", test_path)

Loading…
Cancel
Save