def init_from_shell(self, filepath: str, shell: str = None) -> None: """Init variables from a shell sourcing a file.""" if shell is None: shell = self._shell_path cmd = [shell, "-c", f"source {filepath} &>/dev/null && env"] result = run_cmd(cmd, env=self._shell_env) if result.returncode != 0: logging.error(f"Error: error sourcing file from shell: {filepath}") self.init_from_str(result.stdout)
def _run_cmd(self, cmd, must_succeed=True) -> subprocess.CompletedProcess: return run_cmd(cmd, must_succeed=must_succeed)