Skip to content

Commit c429c68

Browse files
committed
Fixed ruff complaints about subprocess
1 parent 23be62d commit c429c68

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

bumpversion/scm.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args
4848
env["BUMPVERSION_NEW_VERSION"] = new_version
4949

5050
try:
51-
subprocess.run([*cls._COMMIT_COMMAND, f.name, *extra_args], env=env, capture_output=True, check=True)
51+
cmd = [*cls._COMMIT_COMMAND, f.name, *extra_args]
52+
subprocess.run(cmd, env=env, capture_output=True, check=True) # noqa: S603
5253
except subprocess.CalledProcessError as exc: # pragma: no-coverage
5354
err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {exc.output}"
5455
logger.exception(err_msg)
@@ -60,7 +61,7 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args
6061
def is_usable(cls) -> bool:
6162
"""Is the VCS implementation usable."""
6263
try:
63-
result = subprocess.run(cls._TEST_USABLE_COMMAND, check=True, capture_output=True)
64+
result = subprocess.run(cls._TEST_USABLE_COMMAND, check=True, capture_output=True) # noqa: S603
6465
return result.returncode == 0
6566
except (FileNotFoundError, PermissionError, NotADirectoryError, subprocess.CalledProcessError):
6667
return False
@@ -89,7 +90,7 @@ def tag(cls, name: str, sign: bool = False, message: Optional[str] = None) -> No
8990
def get_all_tags(cls) -> List[str]:
9091
"""Return all tags in VCS."""
9192
try:
92-
result = subprocess.run(cls._ALL_TAGS_COMMAND, text=True, check=True, capture_output=True)
93+
result = subprocess.run(cls._ALL_TAGS_COMMAND, text=True, check=True, capture_output=True) # noqa: S603
9394
return result.stdout.splitlines()
9495
except (FileNotFoundError, PermissionError, NotADirectoryError, subprocess.CalledProcessError):
9596
return []
@@ -189,7 +190,7 @@ def assert_nondirty(cls) -> None:
189190
"""Assert that the working directory is not dirty."""
190191
lines = [
191192
line.strip()
192-
for line in subprocess.check_output(["git", "status", "--porcelain"]).splitlines()
193+
for line in subprocess.check_output(["git", "status", "--porcelain"]).splitlines() # noqa: S603, S607
193194
if not line.strip().startswith(b"??")
194195
]
195196

@@ -202,7 +203,7 @@ def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
202203
"""Return information about the latest tag."""
203204
try:
204205
# git-describe doesn't update the git-index, so we do that
205-
subprocess.run(["git", "update-index", "--refresh", "-q"], capture_output=True)
206+
subprocess.run(["git", "update-index", "--refresh", "-q"], capture_output=True) # noqa: S603, S607
206207
except subprocess.CalledProcessError as e:
207208
logger.debug("Error when running git update-index: %s", e.stderr)
208209
return SCMInfo(tool=cls)
@@ -220,7 +221,7 @@ def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
220221
"--abbrev=40",
221222
f"--match={tag_pattern}",
222223
]
223-
result = subprocess.run(git_cmd, text=True, check=True, capture_output=True)
224+
result = subprocess.run(git_cmd, text=True, check=True, capture_output=True) # noqa: S603
224225
describe_out = result.stdout.strip().split("-")
225226
except subprocess.CalledProcessError as e:
226227
logger.debug("Error when running git describe: %s", e.stderr)
@@ -243,7 +244,7 @@ def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
243244
@classmethod
244245
def add_path(cls, path: Union[str, Path]) -> None:
245246
"""Add a path to the VCS."""
246-
subprocess.check_output(["git", "add", "--update", str(path)])
247+
subprocess.check_output(["git", "add", "--update", str(path)]) # noqa: S603, S607
247248

248249
@classmethod
249250
def tag(cls, name: str, sign: bool = False, message: Optional[str] = None) -> None:
@@ -263,7 +264,7 @@ def tag(cls, name: str, sign: bool = False, message: Optional[str] = None) -> No
263264
command += ["--sign"]
264265
if message:
265266
command += ["--message", message]
266-
subprocess.check_output(command)
267+
subprocess.check_output(command) # noqa: S603
267268

268269

269270
class Mercurial(SourceCodeManager):
@@ -279,23 +280,23 @@ def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
279280
current_version = None
280281
re_pattern = tag_pattern.replace("*", ".*")
281282
result = subprocess.run(
282-
["hg", "log", "-r", f"tag('re:{re_pattern}')", "--template", "{latesttag}\n"],
283+
["hg", "log", "-r", f"tag('re:{re_pattern}')", "--template", "{latesttag}\n"], # noqa: S603, S607
283284
text=True,
284285
check=True,
285286
capture_output=True,
286287
)
287288
result.check_returncode()
288289
if result.stdout:
289290
current_version = result.stdout.splitlines(keepends=False)[0].lstrip("v")
290-
is_dirty = len(subprocess.check_output(["hg", "status", "-mard"])) != 0
291+
is_dirty = len(subprocess.check_output(["hg", "status", "-mard"])) != 0 # noqa: S603, S607
291292
return SCMInfo(tool=cls, current_version=current_version, dirty=is_dirty)
292293

293294
@classmethod
294295
def assert_nondirty(cls) -> None:
295296
"""Assert that the working directory is clean."""
296297
lines = [
297298
line.strip()
298-
for line in subprocess.check_output(["hg", "status", "-mard"]).splitlines()
299+
for line in subprocess.check_output(["hg", "status", "-mard"]).splitlines() # noqa: S603, S607
299300
if not line.strip().startswith(b"??")
300301
]
301302

@@ -329,7 +330,7 @@ def tag(cls, name: str, sign: bool = False, message: Optional[str] = None) -> No
329330
raise SignedTagsError("Mercurial does not support signed tags.")
330331
if message:
331332
command += ["--message", message]
332-
subprocess.check_output(command)
333+
subprocess.check_output(command) # noqa: S603
333334

334335

335336
def get_scm_info(tag_pattern: str) -> SCMInfo:

0 commit comments

Comments
 (0)