Files
app_skellington/scripts/smoke_import.py
T

55 lines
1.6 KiB
Python

"""Smoke-test an *installed* app_skellington (wheel, sdist or index release).
Run it from outside the source tree, so the installed copy is the one imported:
cd / && python /path/to/scripts/smoke_import.py [EXPECTED_VERSION]
"""
import importlib.metadata
import os
import pathlib
import subprocess
import sys
def fail(msg):
sys.exit("smoke FAILED: " + msg)
def main(argv):
expected = argv[1] if len(argv) > 1 else None
import app_skellington
location = pathlib.Path(app_skellington.__file__).resolve()
if "site-packages" not in location.parts:
fail("imported the source tree, not an installed copy: %s" % location)
from app_skellington import ( # noqa: F401 (the public API must import)
ApplicationContainer,
CommandTree,
Config,
LoggingLayer,
NoCommandSpecified,
ServiceNotFound,
SubMenu,
)
version = importlib.metadata.version("app_skellington")
if version.startswith("0.0"):
fail("setuptools_scm found no tags (shallow clone?): %s" % version)
if expected is not None and version != expected:
fail("expected version %s, got %s" % (expected, version))
# _bootstrap.py takes a different code path when APPSKELLINGTON_DEBUG is set.
env = dict(os.environ, APPSKELLINGTON_DEBUG="1")
proc = subprocess.run([sys.executable, "-c", "import app_skellington"], env=env)
if proc.returncode != 0:
fail("import failed with APPSKELLINGTON_DEBUG=1")
print("smoke ok:", version, location)
if __name__ == "__main__":
main(sys.argv)