Browse Source

added repo caching to noxfile

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

39
noxfile.py

@ -1,9 +1,42 @@
import pathlib import pathlib
import tempfile import tempfile
import typing
import nox 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"]) @nox.session(python=["3.9", "3.10", "3.11"])
def tests(session): def tests(session):
session.install(".[test]") session.install(".[test]")
@ -19,11 +52,9 @@ def tests(session):
], ],
) )
def downstream(session, repo, test_dir): def downstream(session, repo, test_dir):
session.install(".") tmpdir = RepoCache.clone(session, repo)
with tempfile.TemporaryDirectory() as tmpdir:
session.run("git", "clone", repo, tmpdir, external=True)
session.install(".")
session.install(f"{tmpdir}[test]") session.install(f"{tmpdir}[test]")
test_path = pathlib.Path(tmpdir) / test_dir test_path = pathlib.Path(tmpdir) / test_dir

Loading…
Cancel
Save