Skip to content

Commit

Permalink
Add flags to test scripts to allow intalling and running from another…
Browse files Browse the repository at this point in the history
… path
  • Loading branch information
stealthycoin committed Jan 4, 2023
1 parent f9064e8 commit 23e30c4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 26 deletions.
68 changes: 51 additions & 17 deletions scripts/ci/install-build-system
Original file line number Diff line number Diff line change
@@ -1,27 +1,61 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import tarfile
import tempfile
import os
import glob
from subprocess import check_call
import shutil

_dname = os.path.dirname
from pathlib import Path
from subprocess import check_call

REPO_ROOT = _dname(_dname(_dname(os.path.abspath(__file__))))
REPO_ROOT = Path(__file__).parents[2]
os.chdir(REPO_ROOT)


def run(command):
return check_call(command, shell=True)
def run(command, cwd=None):
print(f"Running command: {command}")
return check_call(command, shell=True, cwd=cwd)


def main(sdist_path=None):
run("pip install --no-build-isolation -r requirements-base.txt")
run("pip install --no-build-isolation -r requirements.txt")
run("pip install --no-build-isolation -r requirements-test.txt")
run(
"pip install --no-build-isolation -r requirements/download-deps/bootstrap-lock.txt"
)
if sdist_path is None:
wheel_dist = _build_sdist_and_wheel()
else:
wheel_dist = _build_wheel(sdist_path)
run("pip install %s" % wheel_dist)


def _build_wheel(sdist_path):
build_dir = REPO_ROOT / "dist"
with tempfile.TemporaryDirectory() as tempdir:
with tarfile.open(sdist_path, "r:gz") as tar:
tar.extractall(tempdir)
unpacked_sdist = os.path.join(tempdir, os.listdir(tempdir)[0])
run(f"python -m build -w -o {build_dir}", cwd=unpacked_sdist)
return _find_wheel_file()
return wheel_dist


def _build_sdist_and_wheel():
if os.path.isdir("dist") and os.listdir("dist"):
shutil.rmtree("dist")
run("python -m build")
return _find_wheel_file()


def _find_wheel_file():
return glob.glob(os.path.join("dist", "*.whl"))[0]


run("pip install --no-build-isolation -r requirements-base.txt")
run('pip install --no-build-isolation -r requirements.txt')
run('pip install --no-build-isolation -r requirements-test.txt')
run(
"pip install --no-build-isolation -r requirements/download-deps/bootstrap-lock.txt"
)
if os.path.isdir('dist') and os.listdir('dist'):
shutil.rmtree('dist')
run('python -m build')
wheel_dist = glob.glob(os.path.join('dist', '*.whl'))[0]
run('pip install %s' % wheel_dist)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--use-sdist", default=None, type=os.path.abspath)
args = parser.parse_args()
main(args.use_sdist)
25 changes: 18 additions & 7 deletions scripts/ci/run-build-system-tests
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import argparse
import os
import sys

from contextlib import contextmanager
from pathlib import Path
from subprocess import check_call

_dname = os.path.dirname

REPO_ROOT = _dname(_dname(_dname(os.path.abspath(__file__))))
RUN_TESTS_SCRIPTS = os.path.join(REPO_ROOT, 'scripts', 'ci', 'run-tests')
REPO_ROOT = Path(__file__).parents[2].absolute()
RUN_TESTS_SCRIPTS = os.path.join(REPO_ROOT, "scripts", "ci", "run-tests")


@contextmanager
Expand All @@ -25,9 +26,19 @@ def run(command):
return check_call(command, shell=True)


if __name__ == "__main__":
with cd(os.path.join(REPO_ROOT, "tests")):
def main(tests_path=None):
if tests_path is None:
tests_path = REPO_ROOT / "tests"
with cd(tests_path):
run(
f"{sys.executable} {RUN_TESTS_SCRIPTS} "
f"--tests-path {tests_path} "
f"backends/build_system/ --allow-repo-root-on-path"
)


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--tests-path", default=None, type=os.path.abspath)
args = parser.parse_args()
main(args.tests_path)
17 changes: 15 additions & 2 deletions scripts/ci/run-tests
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# Don't run tests from the root repo dir.
# We want to ensure we're importing from the installed
# binary package not from the CWD.
Expand Down Expand Up @@ -94,10 +94,23 @@ if __name__ == "__main__":
"Ignore a test subdirectory. Can be specified multiple times."
)
)
parser.add_argument(
"--tests-path",
default=None,
type=os.path.abspath,
help=(
"Optional path to an alternate test directory to use."
)
)
raw_args = parser.parse_args()
test_runner, test_args, test_dirs = process_args(raw_args)

tests_path = raw_args.tests_path
if tests_path is None:
tests_path = os.path.join(REPO_ROOT, "tests")

cmd = f"{test_runner} {test_args}{test_dirs}"
print(f"CDing to {tests_path}")
print(f"Running {cmd}...")
with cd(os.path.join(REPO_ROOT, "tests")):
with cd(tests_path):
run(cmd, allow_repo_root_on_path=raw_args.allow_repo_root_on_path)

0 comments on commit 23e30c4

Please sign in to comment.