Skip to content

Commit

Permalink
fix: bandit warnings (#950)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
klmcadams and pyansys-ci-bot authored Oct 28, 2024
1 parent 4153cc3 commit b95edcf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/950.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bandit warnings
2 changes: 1 addition & 1 deletion src/ansys/mechanical/core/embedding/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ def _start_app(self, **kwargs) -> None:
try:
utils.sleep(40)
except:
pass
raise Exception("BackgroundApp cannot sleep.") # pragma: no cover
BackgroundApp.__stopped = True
9 changes: 6 additions & 3 deletions src/ansys/mechanical/core/embedding/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
"""Run Mechanical UI from Python."""

from pathlib import Path
from subprocess import Popen

# Subprocess is needed to launch the GUI and clean up the process on close.
# Excluding bandit check.
from subprocess import Popen # nosec: B404
import sys
import tempfile
import typing
Expand Down Expand Up @@ -113,7 +116,7 @@ def graphically_launch_temp(
if not self._dry_run:
# The subprocess that uses ansys-mechanical to launch the GUI of the temporary
# mechdb file
process = Popen(args)
process = Popen(args) # nosec: B603 # pragma: no cover
return process
else:
# Return a string containing the args
Expand All @@ -136,7 +139,7 @@ def _cleanup_gui(self, process: Popen, temp_mechdb_path: Path) -> None:
# Open a subprocess to remove the temporary mechdb file and folder when the process ends
Popen(
[sys.executable, cleanup_script, str(process.pid), temp_mechdb_path]
) # pragma: no cover
) # pragma: no cover # nosec: B603


def _is_saved(app: "ansys.mechanical.core.embedding.App") -> bool:
Expand Down
16 changes: 8 additions & 8 deletions src/ansys/mechanical/core/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@
"""Launch Mechanical in batch or UI mode."""
import errno
import os
import subprocess

# Subprocess is needed to start the backend. Excluding bandit check.
import subprocess # nosec: B404

from ansys.mechanical.core import LOG
from ansys.mechanical.core.misc import is_windows


class MechanicalLauncher:
Expand Down Expand Up @@ -90,17 +91,16 @@ def launch(self):
env_variables = self.__get_env_variables()
args_list = self.__get_commandline_args()

shell_value = False

if is_windows():
shell_value = True

LOG.info(f"Starting the process using {args_list}.")
if self.verbose:
command = " ".join(args_list)
print(f"Running {command}.")

process = subprocess.Popen(args_list, shell=shell_value, env=env_variables)
process = subprocess.Popen(
args_list,
stdout=subprocess.PIPE,
env=env_variables,
) # nosec: B603
LOG.info(f"Started the process:{process} using {args_list}.")

@staticmethod
Expand Down

0 comments on commit b95edcf

Please sign in to comment.