Skip to content

Commit

Permalink
Use capture_output instead of 2x subprocess.PIPE
Browse files Browse the repository at this point in the history
They are equivalent but the former is shorter:
https://docs.python.org/3/library/subprocess.html#subprocess.run

Signed-off-by: Lukas Puehringer <[email protected]>
  • Loading branch information
lukpueh committed Feb 10, 2023
1 parent b03f127 commit f23d800
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions securesystemslib/gpg/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def is_available_gnupg(gnupg: str, timeout=GPG_TIMEOUT) -> bool:
try:
subprocess.run( # nosec
gpg_version_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
timeout=timeout,
check=True,
)
Expand Down
6 changes: 2 additions & 4 deletions securesystemslib/gpg/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def create_signature(content, keyid=None, homedir=None, timeout=GPG_TIMEOUT):
command,
input=content,
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
timeout=timeout,
)

Expand Down Expand Up @@ -316,8 +315,7 @@ def export_pubkey(keyid, homedir=None, timeout=GPG_TIMEOUT):
command = gpg_export_pubkey_command(keyid=keyid, homearg=homearg)
gpg_process = subprocess.run( # nosec
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
timeout=timeout,
check=True,
)
Expand Down
6 changes: 2 additions & 4 deletions tests/test_gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ def setUpClass(self): # pylint: disable=bad-classmethod-argument
cmd = gpg_export_pubkey_command(keyid=keyid, homearg=homearg)
proc = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
timeout=GPG_TIMEOUT,
check=True,
)
Expand All @@ -234,8 +233,7 @@ def setUpClass(self): # pylint: disable=bad-classmethod-argument
cmd = gpg_export_pubkey_command(keyid=keyid, homearg=homearg)
proc = subprocess.run(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
capture_output=True,
timeout=GPG_TIMEOUT,
check=True,
)
Expand Down

0 comments on commit f23d800

Please sign in to comment.