MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / shell

Method shell

tests/harness/train_tracks_github_test.py:78–102  ·  view source on GitHub ↗
(self, code, owner=None, terminal_input=None, **env)

Source from the content-addressed store, hash-verified

76 )
77
78 def shell(self, code, owner=None, terminal_input=None, **env):
79 settings = self.env.copy()
80 settings.update(env)
81 if owner is not None:
82 settings["TRAIN_TRACKS_GITHUB_OWNER"] = owner
83 command = ["bash", "-eu", "-c", 'source "$HELPER"\n' + code]
84 if terminal_input is None:
85 return subprocess.run(
86 command, input="", capture_output=True, text=True, env=settings, timeout=10
87 )
88 master, slave = pty.openpty()
89 try:
90 with subprocess.Popen(
91 command, stdin=slave, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
92 text=True, env=settings,
93 ) as child:
94 os.close(slave)
95 slave = None
96 os.write(master, terminal_input.encode())
97 stdout, stderr = child.communicate(timeout=10)
98 return subprocess.CompletedProcess(command, child.returncode, stdout, stderr)
99 finally:
100 os.close(master)
101 if slave is not None:
102 os.close(slave)
103
104 def read_calls(self):
105 return [json.loads(line) for line in self.calls.read_text().splitlines()] if self.calls.exists() else []

Calls 6

copyMethod · 0.80
updateMethod · 0.45
runMethod · 0.45
closeMethod · 0.45
writeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected