Newer
Older
import os
import subprocess
import time
from pathlib import Path
EPICS_BASE = os.environ.get("EPICS_BASE")
E3_REQUIRE_VERSION = os.environ.get("E3_REQUIRE_VERSION")
"""
Set a number of environment variables needed for require to build a module
"""
assert "EPICS_BASE" in env
assert Path(env["EPICS_BASE"]).is_dir
assert "E3_REQUIRE_VERSION" in env
assert env["E3_REQUIRE_VERSION"]
E3_REQUIRE_LOCATION = f"{EPICS_BASE}/require/{E3_REQUIRE_VERSION}"
assert Path(E3_REQUIRE_LOCATION).is_dir()
env["E3_REQUIRE_LOCATION"] = E3_REQUIRE_LOCATION
REQUIRE_CONFIG = f"{E3_REQUIRE_LOCATION}/configure"
env["REQUIRE_CONFIG"] = REQUIRE_CONFIG
env["E3_MODULE_VERSION"] = "0.0.0"
return env
def run_make(wrapper, *args, **kwargs):
"""
Attempt to run `make <args>` in the specified path with <kwargs> as environment variables
"""
make_cmd = ["make", "-C", wrapper.path] + list(args)
make_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=test_env,
encoding="utf-8",
)
outs, errs = p.communicate()
return p.returncode, outs, errs
def get_env_var(wrapper, var: str):
"""
Fetch an environment variable from the module build environment
"""
_, out, _ = run_make(wrapper, "cellvars")
for line in out.split("\n"):
if line.startswith(var):
return line.split("=")[1].strip()
print(f"run_ioc_get_output {module} {version} {cell_path}")
with IOC("-r", f"{module},{version}", "-l", cell_path) as ioc:
time.sleep(1)
return ioc.proc.returncode, ioc.outs, ioc.errs