diff --git a/wetb/fast/fast_io.py b/wetb/fast/fast_io.py index 7d331df5903f74899c1a329c8989f2bbbc8799fd..78e4859f016d3e1ff218fed3b532d16aba65e909 100644 --- a/wetb/fast/fast_io.py +++ b/wetb/fast/fast_io.py @@ -37,7 +37,7 @@ def load_output(filename): """ assert os.path.isfile(filename), "File, %s, does not exists" % filename - with open(filename, 'r') as f: + with open(filename, 'r', encoding='utf-8') as f: try: f.readline() except UnicodeDecodeError: @@ -45,7 +45,7 @@ def load_output(filename): return load_ascii_output(filename) def load_ascii_output(filename): - with open(filename) as f: + with open(filename, encoding='utf-8') as f: info = {} info['name'] = os.path.splitext(os.path.basename(filename))[0] try: diff --git a/wetb/hawc2/ascii2bin/ascii2bin.py b/wetb/hawc2/ascii2bin/ascii2bin.py index 11a09717917ec135e58de913e94dca69ac2d3d8b..f8280ae9ada6c572eb4c207591e8995786e0bf63 100644 --- a/wetb/hawc2/ascii2bin/ascii2bin.py +++ b/wetb/hawc2/ascii2bin/ascii2bin.py @@ -24,7 +24,7 @@ class TextUI(object): sys.path.append(".") def size_from_file(selfilename): - with open(selfilename) as f: + with open(selfilename, encoding='utf-8') as f: info = f.readlines()[8].split() scans = int(info[0]) no_sensors = int(info[1]) @@ -39,7 +39,7 @@ def ascii2bin(ascii_selfilename, bin_selfilename=None, ui=TextUI()): # Read, convert and write sel file - with open(ascii_selfilename) as f: + with open(ascii_selfilename, encoding='utf-8') as f: lines = f.readlines() if "BINARY" in lines[8]: @@ -54,7 +54,7 @@ def ascii2bin(ascii_selfilename, bin_selfilename=None, ui=TextUI()): scale_factors = pandas_dat_ascii2bin(ascii_datfilename, bin_selfilename.replace('.sel', '.dat'), ui) for sf in scale_factors: lines.append(" %.5E\n" % sf) - with open(bin_selfilename, 'w') as f: + with open(bin_selfilename, 'w', encoding='utf-8') as f: f.writelines(lines) if ui is not None: ui.show_message("Finish converting %s to %s" % (ascii_selfilename, bin_selfilename)) diff --git a/wetb/hawc2/at_time_file.py b/wetb/hawc2/at_time_file.py index bc1bb4f241bec4f4a211d5a239b7f927904aab42..38cbff60dd6c82d728fc53c2d3ab1a1bcb5418d9 100644 --- a/wetb/hawc2/at_time_file.py +++ b/wetb/hawc2/at_time_file.py @@ -27,7 +27,7 @@ class AtTimeFile(object): -5.34743208242399 """ def __init__(self, filename): - with open(filename) as fid: + with open(filename, encoding='utf-8') as fid: lines = fid.readlines() self.attribute_names = lines[2].lower().replace("#", "").split() data = np.array([[float(l) for l in lines[i].split() ] for i in range(3, len(lines))]) diff --git a/wetb/hawc2/cmp_test_cases.py b/wetb/hawc2/cmp_test_cases.py index b1d4f1a2140d5078104e2e84115d53e0b4567baa..1745aa455e66087649a605f2586c76d150fca2e4 100644 --- a/wetb/hawc2/cmp_test_cases.py +++ b/wetb/hawc2/cmp_test_cases.py @@ -32,9 +32,9 @@ class CompareTestCases(unittest.TestCase): def compare_lines(self, ref_file, test_file, skip_first=0): - with open(ref_file) as ref: + with open(ref_file, encoding='utf-8') as ref: ref_lines = ref.readlines() - with open(test_file) as test: + with open(test_file, encoding='utf-8') as test: test_lines = test.readlines() self.assertEqual(len(ref_lines), len(test_lines), "\nNumber of lines differs in: '%s' and '%s'" % (ref_file, test_file)) for i, (ref_l, test_l) in enumerate(zip(ref_lines[skip_first:], test_lines[skip_first:])): diff --git a/wetb/hawc2/htc_file.py b/wetb/hawc2/htc_file.py index 54a742a53645cb1425e658c9dcbb62c3c141db3f..7893858db89cd7587f141775dc6702bf1b018f17 100644 --- a/wetb/hawc2/htc_file.py +++ b/wetb/hawc2/htc_file.py @@ -59,7 +59,7 @@ class HTCFile(HTCContents, HTCDefaults): def readlines(self, filename): self.htc_inputfiles.append(filename) htc_lines = [] - with open(filename) as fid: + with open(filename, encoding='utf-8') as fid: lines = fid.readlines() for l in lines: if l.lower().lstrip().startswith('continue_in_file'): @@ -85,7 +85,7 @@ class HTCFile(HTCContents, HTCDefaults): # exist_ok does not exist in Python27 if not os.path.exists(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename))#, exist_ok=True) - with open(filename, 'w') as fid: + with open(filename, 'w', encoding='utf-8') as fid: fid.write(str(self)) def set_name(self, name, folder="htc"): diff --git a/wetb/hawc2/log_file.py b/wetb/hawc2/log_file.py index d8cde89f98bb058bb549937dbc1b6c6370bf2d9e..fec59087fb398479ed90fe18e49ed113250d5263 100644 --- a/wetb/hawc2/log_file.py +++ b/wetb/hawc2/log_file.py @@ -70,7 +70,7 @@ class LogFile(object): # exist_ok does not exist in Python27 if not os.path.exists(os.path.dirname(self.filename)): os.makedirs(os.path.dirname(self.filename))#, exist_ok=True) - with open(self.filename, 'w'): + with open(self.filename, 'w', encoding='utf-8'): pass self.reset() diff --git a/wetb/hawc2/sel_file.py b/wetb/hawc2/sel_file.py index a01c0183a505c6dec40ba98fa6775a878f2180cf..891bc13a8805a8945f72b8bab972387048bd1154 100644 --- a/wetb/hawc2/sel_file.py +++ b/wetb/hawc2/sel_file.py @@ -48,7 +48,7 @@ class SelFile(object): def __init__(self, sel_filename): if not os.path.isfile(sel_filename) or os.path.splitext(sel_filename)[1] != ".sel": raise Warning("%s cannot be found or is not a legal *.sel file" % os.path.realpath(sel_filename)) - with open(sel_filename) as f: + with open(sel_filename, encoding='utf-8') as f: lines = f.readlines() @@ -139,6 +139,6 @@ def save(sel_filename, version, time, scans, no_sensors, duration, sensors, scal for sf in scale_factors: lines.append(" %.5E" % sf) - with open(sel_filename, 'w') as f: + with open(sel_filename, 'w', encoding='utf-8') as f: f.write("\n".join(lines)) diff --git a/wetb/hawc2/shear_file.py b/wetb/hawc2/shear_file.py index 04a768beb4d20d2832604c2d08f3264aca16c8f0..4cccd759f56599d6d625137294b254cf975478fa 100644 --- a/wetb/hawc2/shear_file.py +++ b/wetb/hawc2/shear_file.py @@ -54,7 +54,7 @@ def save(filename, y_coordinates, z_coordinates, u=None, v=None, w=None): # exist_ok does not exist in Python27 if not os.path.exists(os.path.dirname(filename)): os.makedirs(os.path.dirname(filename))#, exist_ok=True) - with open(filename, 'w') as fid: + with open(filename, 'w', encoding='utf-8') as fid: fid.write(" # autogenerated shear file\n") fid.write(" %d %d\n" % (len(y_coordinates), len(z_coordinates))) for i, l in enumerate(['v', 'u', 'w']): diff --git a/wetb/hawc2/simulation.py b/wetb/hawc2/simulation.py index f4d38e7003da64372460d12e266db75c2720d8ba..151f29b0a8fff5a0ae4b470d8bc2916ab1248181 100644 --- a/wetb/hawc2/simulation.py +++ b/wetb/hawc2/simulation.py @@ -116,7 +116,7 @@ class Simulation(object): additional_files_file = os.path.join(self.modelpath, 'additional_files.txt') additional_files = {} if os.path.isfile(additional_files_file): - with open(additional_files_file) as fid: + with open(additional_files_file, encoding='utf-8') as fid: additional_files = json.load(fid) return additional_files @@ -124,7 +124,7 @@ class Simulation(object): additional_files = self.additional_files() additional_files['input'] = additional_files.get('input', []) + [file] additional_files_file = os.path.join(self.modelpath, 'additional_files.txt') - with open(additional_files_file, 'w') as fid: + with open(additional_files_file, 'w', encoding='utf-8') as fid: json.dump(additional_files, fid) def prepare_simulation(self): @@ -304,7 +304,7 @@ class SimulationThread(Thread): p.set_nice(psutil.BELOW_NORMAL_PRIORITY_CLASS) self.process.communicate() errorcode = self.process.returncode - with open(self.modelpath + self.sim.stdout_filename) as fid: + with open(self.modelpath + self.sim.stdout_filename, encoding='utf-8') as fid: stdout = fid.read() self.res = errorcode, stdout diff --git a/wetb/prepost/Simulations.py b/wetb/prepost/Simulations.py index 5d5b2a0320623aefec3476e433f5f247bc069ab9..5594417c413749e25830ed6d1c088c860fe155d2 100755 --- a/wetb/prepost/Simulations.py +++ b/wetb/prepost/Simulations.py @@ -433,7 +433,7 @@ def run_local(cases, silent=False, check_log=True): """ # remember the current working directory - cwd = os.getcwd() + cwd = str(os.getcwd()) nr = len(cases) if not silent: print('') diff --git a/wetb/prepost/dlcdefs.py b/wetb/prepost/dlcdefs.py index 21dd670070e012023e77d73ea45e43cb2f019198..2d439c148b1fbed8854e6cc9353c1e59b280e54c 100644 --- a/wetb/prepost/dlcdefs.py +++ b/wetb/prepost/dlcdefs.py @@ -32,7 +32,7 @@ def configure_dirs(verbose=False): Automatically configure required directories to launch simulations """ - P_RUN = os.getcwd() + P_RUN = str(os.getcwd()) p_run_root = os.sep.join(P_RUN.split(os.sep)[:-2]) # MODEL SOURCES, exchanche file sources P_SOURCE = P_RUN diff --git a/wetb/utils/cython_compile/cython_compile.py b/wetb/utils/cython_compile/cython_compile.py index 02213aee94cbdb50211d595a9a501def2955fad9..f05fe5d4570f37ec404298f4372e01f84089a8d7 100644 --- a/wetb/utils/cython_compile/cython_compile.py +++ b/wetb/utils/cython_compile/cython_compile.py @@ -42,7 +42,7 @@ def wrap(f, autodeclare, *args, **kwargs): # Generate name: "c:\documents\project\mymodule.py" -> mymodule_myfunction # When called from ipython notebooks, filename is an object e.g: "<ipython-input-12-e897f9fefc0c>" # therefore <,>,- is removed to make it a legal python module name - name = os.path.relpath(inspect.getabsfile(f), os.getcwd()).replace(".py", "") + name = os.path.relpath(inspect.getabsfile(f), str(os.getcwd())).replace(".py", "") name = name.replace("<", "").replace(">", "").replace("-", "") name = "%s_%s" % (name, f.__name__) if name.startswith(".."): @@ -70,7 +70,7 @@ def wrap(f, autodeclare, *args, **kwargs): # Write pyrex code lines to .pyx file pyx_filename = name.replace("\\", "/") + ".pyx" - with open(pyx_filename, 'w') as fid: + with open(pyx_filename, 'w', encoding='utf-8') as fid: fid.writelines(pyx_lines) # compile, import compiled module_name and delete temporary files @@ -151,7 +151,7 @@ def cython_import(import_module_name, compiler=None): fid.close() # compile, import compiled module and delete temporary files - module_relname = os.path.relpath(eval(module_name).__file__, os.getcwd()).replace(os.path.sep, ".")[:-3] + module_relname = os.path.relpath(eval(module_name).__file__, str(os.getcwd())).replace(os.path.sep, ".")[:-3] return compile_and_cleanup(import_module_name, pyx_filename, module_relname, compiler) return eval(module_name)