Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR: Remove f-string without placeholders and specify exception type. #1011

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/1011.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove f-string without placeholders and specify exception type.
2 changes: 1 addition & 1 deletion src/ansys/mechanical/core/embedding/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

HAS_ANSYS_VIZ = True
"""Whether or not PyVista exists."""
except:
except ImportError:
HAS_ANSYS_VIZ = False


Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mechanical/core/embedding/app_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def add_mechanical_python_libraries(app_or_version):
elif isinstance(app_or_version, App):
installdir.append(os.environ[f"AWP_ROOT{app_or_version.version}"])
else:
raise ValueError(f"Invalid input: expected an integer (version) or an instance of App().")
raise ValueError("Invalid input: expected an integer (version) or an instance of App().")

location = os.path.join(installdir[0], "Addins", "ACT", "libraries", "Mechanical")
sys.path.append(location)
4 changes: 2 additions & 2 deletions src/ansys/mechanical/core/embedding/initializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def __is_lib_loaded(libname: str): # pragma: no cover
RTLD_NOLOAD = 4
try:
ctypes.CDLL(libname, RTLD_NOLOAD)
except:
except OSError:
return False
return True

Expand Down Expand Up @@ -174,7 +174,7 @@ def initialize(version: int = None):
)
return

if version == None:
if version is None:
version = _get_latest_default_version()

version = __check_for_supported_version(version=version)
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mechanical/core/embedding/logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@
@classmethod
def set_log_directory(cls, value: str) -> None:
"""Configure logging to write to a directory."""
if value == None:
if value is None:

Check warning on line 147 in src/ansys/mechanical/core/embedding/logger/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mechanical/core/embedding/logger/__init__.py#L147

Added line #L147 was not covered by tests
return
_get_backend().set_directory(value)

@classmethod
def set_log_base_directory(cls, directory: str) -> None:
"""Configure logging to write in a time-stamped subfolder in this directory."""
if directory == None:
if directory is None:

Check warning on line 154 in src/ansys/mechanical/core/embedding/logger/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mechanical/core/embedding/logger/__init__.py#L154

Added line #L154 was not covered by tests
return
_get_backend().set_base_directory(directory)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import Ansys

return Ansys.Common.WB1ManagedUtils.Logger
except:
except (ImportError, RuntimeError):

Check warning on line 44 in src/ansys/mechanical/core/embedding/logger/windows_api.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mechanical/core/embedding/logger/windows_api.py#L44

Added line #L44 was not covered by tests
raise Exception("Logging cannot be used until after Mechanical embedding is initialized.")


Expand Down
17 changes: 7 additions & 10 deletions src/ansys/mechanical/core/mechanical.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,14 +444,14 @@ def __init__(
self._disable_logging = False

if self._local:
self.log_info(f"Mechanical connection is treated as local.")
self.log_info("Mechanical connection is treated as local.")
else:
self.log_info(f"Mechanical connection is treated as remote.")
self.log_info("Mechanical connection is treated as remote.")

# connect and validate to the channel
self._multi_connect(timeout=timeout)

self.log_info("Mechanical is ready to accept grpc calls")
self.log_info("Mechanical is ready to accept grpc calls.")

def __del__(self): # pragma: no cover
"""Clean up on exit."""
Expand Down Expand Up @@ -480,9 +480,8 @@ def version(self) -> str:

>>> mechanical.version
'242'

"""
if self._version == None:
if self._version is None:
try:
self._disable_logging = True
script = (
Expand Down Expand Up @@ -537,7 +536,6 @@ def _multi_connect(self, n_attempts=5, timeout=60):
timeout : float, optional
Maximum allowable time in seconds for establishing a connection.
The default is ``60``.

"""
# This prevents a single failed connection from blocking other attempts
connected = False
Expand Down Expand Up @@ -1399,7 +1397,7 @@ def download(

if chunk_size > 4 * 1024 * 1024: # 4MB
raise ValueError(
f"Chunk sizes bigger than 4 MB can generate unstable behaviour in PyMechanical. "
"Chunk sizes bigger than 4 MB can generate unstable behaviour in PyMechanical. "
"Decrease the ``chunk_size`` value."
)

Expand Down Expand Up @@ -1518,8 +1516,8 @@ def save_chunks_to_file(self, responses, filename, progress_bar=False, target_na
if progress_bar:
if not _HAS_TQDM: # pragma: no cover
raise ModuleNotFoundError(
f"To use the keyword argument 'progress_bar', you need to have installed "
f"the 'tqdm' package.To avoid this message you can set 'progress_bar=False'."
"To use the keyword argument 'progress_bar', you need to have installed "
"the 'tqdm' package.To avoid this message you can set 'progress_bar=False'."
)

file_size = 0
Expand Down Expand Up @@ -1572,7 +1570,6 @@ def download_project(self, extensions=None, target_dir=None, progress_bar=False)
Download all the files in the project.

>>> local_file_path_list = mechanical.download_project()

"""
destination_directory = target_dir.rstrip("\\/")

Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mechanical/core/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def check_valid_start_instance(start_instance):

if start_instance.lower() not in ["true", "false"]:
raise ValueError(
f"The value for 'start_instance' should be 'True' or 'False' (case insensitive)."
"The value for 'start_instance' should be 'True' or 'False' (case insensitive)."
)

return start_instance.lower() == "true"
Expand Down
6 changes: 3 additions & 3 deletions src/ansys/mechanical/core/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ def map(
if progress_bar:
if not _HAS_TQDM: # pragma: no cover
raise ModuleNotFoundError(
f"To use the keyword argument 'progress_bar', you must have installed "
f"the 'tqdm' package. To avoid this message, you can set 'progress_bar=False'."
"To use the keyword argument 'progress_bar', you must have installed "
"the 'tqdm' package. To avoid this message, you can set 'progress_bar=False'."
)

pbar = tqdm(total=jobs_count, desc="Mechanical Running")
Expand Down Expand Up @@ -386,7 +386,7 @@ def run(name_local=""):
else:
run_thread.join()
if not complete[0]: # pragma: no cover
LOG.error(f"Stopped instance because running failed.")
LOG.error("Stopped instance because running failed.")
try:
obj.exit()
except Exception as e:
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def embedded_app(pytestconfig, request):
@pytest.fixture(autouse=True)
def mke_app_reset(request):
global EMBEDDED_APP
if EMBEDDED_APP == None:
if EMBEDDED_APP is None:
# embedded app was not started - no need to do anything
return
terminal_reporter = request.config.pluginmanager.getplugin("terminalreporter")
Expand All @@ -178,7 +178,7 @@ def mke_app_reset(request):

_CHECK_PROCESS_RETURN_CODE = os.name == "nt"

# set to true if you want to see all the subprocess stdout/stderr
# set to True if you want to see all the subprocess stdout/stderr
_PRINT_SUBPROCESS_OUTPUT_TO_CONSOLE = False


Expand Down Expand Up @@ -374,7 +374,7 @@ def mechanical_pool():
def pytest_addoption(parser):
mechanical_path = atp.get_mechanical_path(False)

if mechanical_path == None:
if mechanical_path is None:
parser.addoption("--ansys-version", default="242")
else:
mechanical_version = atp.version_from_path("mechanical", mechanical_path)
Expand Down
Loading