def _guess_wrapped() -> Iterator[Tuple[str, str]]: for tool in BuildTool: tool_path = shutil.which(tool.cmd) if tool_path is None: die(f"Couldn't locate {tool} on the $PATH") yield (tool.blight_tool.env, tool_path)
def _export_guess_wrapped(): for variable, tool in blight.tool.TOOL_ENV_MAP.items(): tool_path = shutil.which(tool) if tool_path is None: die(f"Couldn't locate {tool} on the $PATH") _export(f"BLIGHT_WRAPPED_{variable}", tool_path)
def tool(): # NOTE(ww): Specifically *not* a click command! wrapped_basename = os.path.basename(sys.argv[0]) tool_classname = blight.tool.BLIGHT_TOOL_MAP.get(wrapped_basename) if tool_classname is None: die(f"Unknown blight wrapper requested: {wrapped_basename}") tool_class = getattr(blight.tool, tool_classname) tool = tool_class(sys.argv[1:]) try: tool.run() except BlightError as e: die(str(e))
def tool(): # NOTE(ww): Specifically *not* a click command! wrapped_basename = os.path.basename(sys.argv[0]) try: blight_tool = BlightTool(wrapped_basename) except ValueError: die(f"Unknown blight wrapper requested: {wrapped_basename}") tool_class = getattr(blight.tool, blight_tool.build_tool.value) tool = tool_class(sys.argv[1:]) try: tool.run() except BlightError as e: die(str(e))
def _swizzle_path(stubs: List[str], shim_specs: List[str]) -> str: blight_dir = Path(tempfile.mkdtemp(suffix=blight.util.SWIZZLE_SENTINEL)) for shim, tool in SHIM_MAP.items(): shim_path = blight_dir / shim with open(shim_path, "w+") as io: print("#!/bin/sh", file=io) print(f'{tool.blight_tool.value} "${{@}}"', file=io) shim_path.chmod(shim_path.stat().st_mode | stat.S_IEXEC) for shim_spec in shim_specs: try: (shim, tool_name) = shim_spec.split(":", 1) tool = BuildTool(tool_name.upper()) except ValueError: die(f"Malformatted custom shim spec: expected `shim:tool`, got {shim_spec} " f"(supported tools: {[t.value for t in BuildTool]})") if shim in SHIM_MAP: logger.warning( f"overriding default shim ({shim}) with custom tool ({tool})") shim_path = blight_dir / shim with open(shim_path, "w+") as io: print("#!/bin/sh", file=io) print(f'{tool.blight_tool.value} "${{@}}"', file=io) shim_path.chmod(shim_path.stat().st_mode | stat.S_IEXEC) for stub in stubs: stub_path = blight_dir / stub with open(stub_path, "w+") as io: print("#!/bin/sh", file=io) print("true", file=io) stub_path.chmod(stub_path.stat().st_mode | stat.S_IEXEC) return f"{blight_dir}:{unswizzled_path()}"
def test_die(): with pytest.raises(SystemExit): util.die(":(")