diff --git a/buildingspy/CHANGES.txt b/buildingspy/CHANGES.txt index 9b48d7c6..b77e0464 100644 --- a/buildingspy/CHANGES.txt +++ b/buildingspy/CHANGES.txt @@ -3,7 +3,8 @@ BuildingsPy Changelog Version 5.2.1, ... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - +- In buildingspy/development/regressiontest.py, changed MODELICAPATH on Windows to use ';' instead of ':' + (https://github.com/lbl-srg/BuildingsPy/issues/609) - Updated pyfunnel to version 2.0.1 to fix plotting issues. With this change, Python 2 is no longer supported. (https://github.com/lbl-srg/BuildingsPy/issues/599) diff --git a/buildingspy/__init__.py b/buildingspy/__init__.py index ffa7a56b..4bd90679 100644 --- a/buildingspy/__init__.py +++ b/buildingspy/__init__.py @@ -9,3 +9,14 @@ version_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'VERSION')) with open(version_path) as f: __version__ = f.read().strip() + +class BuildingsPy: + """Class with static methods that are used in various modules. + + """ + @staticmethod + def getModelicaPathSeparator(): + ''' Returns the `MODELICAPATH` separator, which is `;` on Windows and `:` otherwise. + ''' + import platform + return ';' if platform.system() == 'Windows' else ':' diff --git a/buildingspy/development/regressiontest.py b/buildingspy/development/regressiontest.py index 6d42a587..ee909477 100644 --- a/buildingspy/development/regressiontest.py +++ b/buildingspy/development/regressiontest.py @@ -3673,6 +3673,7 @@ def _write_python_runscripts(self, iPro, tra_data_pro): import inspect import buildingspy.development.regressiontest as r import jinja2 + from buildingspy import BuildingsPy directory = self._temDir[iPro] @@ -3721,10 +3722,7 @@ def _getStartStopTime(key, dat): model_modifier = "" # Get delimiter for MODELICAPATH - if os.name == 'nt': - col = ";" - else: - col = ":" + col = BuildingsPy.getModelicaPathSeparator() # Get the MODELICAPATH if 'MODELICAPATH' in os.environ: diff --git a/buildingspy/simulate/OpenModelica.py b/buildingspy/simulate/OpenModelica.py index f76afc94..e66dcad1 100644 --- a/buildingspy/simulate/OpenModelica.py +++ b/buildingspy/simulate/OpenModelica.py @@ -192,6 +192,7 @@ def _translate_and_simulate(self, simulate): # import datetime from sys import platform + from buildingspy import BuildingsPy # Delete output files self.deleteOutputFiles() @@ -211,10 +212,7 @@ def _translate_and_simulate(self, simulate): file_name = "{}.py".format(self.modelName.replace(".", "_")) # Get delimiter for MODELICAPATH - if os.name == 'nt': - col = ";" - else: - col = ":" + col = BuildingsPy.getModelicaPathSeparator() # Get the MODELICAPATH if 'MODELICAPATH' in os.environ: diff --git a/buildingspy/simulate/base_simulator.py b/buildingspy/simulate/base_simulator.py index 01068901..8aecf127 100644 --- a/buildingspy/simulate/base_simulator.py +++ b/buildingspy/simulate/base_simulator.py @@ -548,17 +548,15 @@ def prependToModelicaPath(env, path): >>> env = os.environ.copy() >>> env = s.prependToModelicaPath(env, os.getcwd()) - ''' + ''' + from buildingspy import BuildingsPy + if path is None: return env else: if 'MODELICAPATH' in env: - import platform - - if platform.system() == 'Windows': - env['MODELICAPATH'] = ";".join([path, env['MODELICAPATH']]) - else: - env['MODELICAPATH'] = ":".join([path, env['MODELICAPATH']]) + env['MODELICAPATH'] = BuildingsPy.getModelicaPathSeparator().join( + [path, env['MODELICAPATH']]) else: env['MODELICAPATH'] = path return env