MCPcopy Create free account
hub / github.com/apache/tvm / Sh

Class Sh

ci/scripts/jenkins/cmd_utils.py:47–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45
46
47class Sh:
48 def __init__(self, env=None, cwd=None):
49 self.env = os.environ.copy()
50 if env is not None:
51 self.env.update(env)
52 self.cwd = cwd
53
54 def tee(self, cmd: str, **kwargs):
55 """
56 Run 'cmd' in a shell then return the (process, stdout) as a tuple
57 """
58
59 logging.info(f"+ {cmd}")
60
61 kwargs = {
62 **self._default_popen_flags(),
63 **kwargs,
64 "stdout": subprocess.PIPE,
65 }
66 proc = subprocess.Popen(cmd, **kwargs)
67
68 stdout = []
69
70 def _tee_output(s):
71 stdout.append(s)
72 print(s, end="")
73
74 while proc.poll() is None:
75 _tee_output(proc.stdout.readline())
76 _tee_output(proc.stdout.read())
77
78 stdout = "".join(stdout)
79 if proc.returncode:
80 raise subprocess.CalledProcessError(proc.returncode, proc.args, stdout)
81
82 return proc, stdout
83
84 def run(self, cmd: str, **kwargs):
85 logging.info(f"+ {cmd}")
86
87 kwargs = {
88 **self._default_popen_flags(),
89 "check": True,
90 **kwargs,
91 }
92
93 return subprocess.run(cmd, **kwargs)
94
95 def _default_popen_flags(self):
96 return {
97 "shell": True,
98 "env": self.env,
99 "encoding": "utf-8",
100 "cwd": self.cwd,
101 }
102
103
104def tags_from_title(title: str) -> list[str]:

Callers 5

s3.pyFile · 0.90
any_docker_changes_sinceFunction · 0.90
does_commit_existFunction · 0.90
task_build.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected