Skip to content

Commit 1c66915

Browse files
Fix Codacy
1 parent 2970d86 commit 1c66915

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

pyaedt/generic/general_methods.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def check_and_download_folder(local_path, remote_path, overwrite=True):
354354
return remote_path
355355

356356

357-
def open_file(file_path, file_options="r"):
357+
def open_file(file_path, file_options="r", encoding=None):
358358
"""Open a file and return the object.
359359
360360
Parameters
@@ -363,6 +363,10 @@ def open_file(file_path, file_options="r"):
363363
Full absolute path to the file (either local or remote).
364364
file_options : str, optional
365365
Options for opening the file.
366+
encoding : str, optional
367+
Name of the encoding used to decode or encode the file.
368+
The default used is platform dependent, but any encoding supported by Python can be
369+
passed.
366370
367371
Returns
368372
-------
@@ -373,15 +377,15 @@ def open_file(file_path, file_options="r"):
373377
dir_name = os.path.dirname(file_path)
374378
if "r" in file_options:
375379
if os.path.exists(file_path):
376-
return open(file_path, file_options)
380+
return open(file_path, file_options, encoding)
377381
elif settings.remote_rpc_session and settings.remote_rpc_session.filemanager.pathexists(
378382
file_path
379383
): # pragma: no cover
380384
local_file = os.path.join(tempfile.gettempdir(), os.path.split(file_path)[-1])
381385
settings.remote_rpc_session.filemanager.download_file(file_path, local_file)
382-
return open(local_file, file_options)
386+
return open(local_file, file_options, encoding)
383387
elif os.path.exists(dir_name):
384-
return open(file_path, file_options)
388+
return open(file_path, file_options, encoding)
385389
elif settings.remote_rpc_session and settings.remote_rpc_session.filemanager.pathexists(dir_name):
386390
return settings.remote_rpc_session.open_file(file_path, file_options)
387391
else:

pyaedt/generic/ibis_reader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ def parse_ibis_file(self):
621621
ibis_name = pyaedt.generic.general_methods.get_filename_without_extension(self._filename)
622622
ibis = Ibis(ibis_name, self._circuit)
623623

624-
file_to_open = check_and_download_file(self._filename)
624+
check_and_download_file(self._filename)
625625

626626
# Read *.ibis file.
627627
ibis_info = ibis_parsing(self._filename)
@@ -980,7 +980,7 @@ def parse_ibis_file(self):
980980

981981
ami_name = pyaedt.generic.general_methods.get_filename_without_extension(self._filename)
982982
ibis = AMI(ami_name, self._circuit)
983-
file_to_open = check_and_download_file(self._filename)
983+
check_and_download_file(self._filename)
984984

985985
# Read *.ibis file.
986986
ibis_info = ibis_parsing(self._filename)

0 commit comments

Comments
 (0)