-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try detecting git commit from existing git repo
Move process invocation to separate function
- Loading branch information
Showing
5 changed files
with
90 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
__all__ = [ | ||
"call_subprocess", | ||
"SubprocessResult", | ||
] | ||
|
||
import asyncio | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass() | ||
class SubprocessResult: | ||
"""Represents the result of a subprocess call.""" | ||
|
||
return_code: int | ||
stdout: bytes | ||
stderr: bytes | ||
|
||
def __bool__(self) -> bool: | ||
return self.return_code == 0 | ||
|
||
|
||
async def call_subprocess( | ||
executable: str, | ||
*args: str, | ||
) -> SubprocessResult: | ||
"""Calls the given executable with the given arguments.""" | ||
proc = await asyncio.subprocess.create_subprocess_exec( | ||
"/usr/bin/env", | ||
executable, | ||
*args, | ||
stdin=asyncio.subprocess.DEVNULL, | ||
stdout=asyncio.subprocess.PIPE, | ||
stderr=asyncio.subprocess.PIPE, | ||
) | ||
out, err = await proc.communicate() | ||
return SubprocessResult(proc.returncode, out, err) |