From bc1a53b6b0f960eeb2de87e608da09c2c0bfe3ae Mon Sep 17 00:00:00 2001 From: Santosh Philip Date: Sat, 26 Nov 2022 12:50:57 -0800 Subject: [PATCH] fixed issue #401 :Problem: idf.run() does a saveas("in.idf") and does NOT go back to original name :Solution: do saveas("ranmdomname.idf") and go back to original name --- .gitignore | 1 + eppy/modeleditor.py | 36 +++++++++++++++++++++++++++++++++-- eppy/runningnotes.txt | 44 +++++++++++++++++++++++++++++++++++++++++++ tests/test_runner.py | 11 +++++++++++ 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 15f98305..7a8ceb06 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.swp tags *~ *.pyc diff --git a/eppy/modeleditor.py b/eppy/modeleditor.py index 48df8226..5b30e5de 100644 --- a/eppy/modeleditor.py +++ b/eppy/modeleditor.py @@ -1055,14 +1055,46 @@ def run(self, **kwargs): """ # write the IDF to the current directory - self.saveas("in.idf") + import uuid + t_suffix = uuid.uuid4().hex + temp_name = f"{t_suffix}.idf" + + idfname = self.idfname + idfabsname = self.idfabsname + + + self.saveas(temp_name) + + # if `idd` is not passed explicitly, use the IDF.iddname idd = kwargs.pop("idd", self.iddname) epw = kwargs.pop("weather", self.epw) try: run(self, weather=epw, idd=idd, **kwargs) finally: - os.remove("in.idf") + self.idfname = idfname + self.idfabsname = idfabsname + os.remove(temp_name) + + def runfile(self, **kwargs): + """Run an IDF file on the disk with a given EnergyPlus weather file. This is a + wrapper for the EnergyPlus command line interface. + + This is different from run() which can run a file that is only in memory + + Parameters + ---------- + kwargs : + See eppy.runner.functions.run() + + """ + idd = kwargs.pop("idd", self.iddname) + epw = kwargs.pop("weather", self.epw) + try: + run(self, weather=epw, idd=idd, **kwargs) + finally: + # os.remove("in.idf") + pass def getiddgroupdict(self): """Return a idd group dictionary diff --git a/eppy/runningnotes.txt b/eppy/runningnotes.txt index 6a0cc0b5..2eb42d15 100644 --- a/eppy/runningnotes.txt +++ b/eppy/runningnotes.txt @@ -1,3 +1,47 @@ + + + +2022-11-26 +---------- + +Plan: + +- don't change existing functions - idf.run and runIDFs +- make new functions that will run files from the disk +- idf.run -> idf.runfile +- runIDFs -> runIDFfiles + +Status: + +- OK .. both of the above are working +- TODO + - duplicate the tests + - Update doc strings for new function + - include these functions in user documentation. +- need to restore idf.idfname to the original name +- see +- https://stackoverflow.com/questions/8577137/how-can-i-create-a-tmp-file-in-python +- for temporary file names. + + +2022-11-25 +---------- + +- removed saveas("in.idf") from idf.run() +- runs works and runIDFs() works +- tests are failing - fix them. + +notes: + +- idf.run() should work only on a file that is on disk +- So a file has to be saved onto disk before it can be run +- The tests in tests_runner do not have this expaection. So they fail +- ###### +- the fact that they have to saved has to in the documentation. +- both function doc and readthedocs + + + 2022-11-24 ---------- diff --git a/tests/test_runner.py b/tests/test_runner.py index a65b5a41..e0bd773a 100644 --- a/tests/test_runner.py +++ b/tests/test_runner.py @@ -271,6 +271,17 @@ def test_run(self, test_idf): files = os.listdir("run_outputs") assert set(files) == set(self.expected_files) + def test_run_retain_idfname(self, test_idf): + """ + idf.run() changes idfname. Confirm that the name is restored + + """ + idfname = test_idf.idfname + idfabsname = test_idf.idfabsname + test_idf.run(output_directory="run_outputs") + assert test_idf.idfname == idfname + assert test_idf.idfabsname == idfabsname + def test_run_readvars(self, test_idf): """ End to end test of idf.run function with readvars set True.