Skip to content

Commit

Permalink
fixed issue #401
Browse files Browse the repository at this point in the history
: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
  • Loading branch information
Santosh Philip committed Nov 26, 2022
1 parent 3cdcf6d commit bc1a53b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.swp
tags
*~
*.pyc
Expand Down
36 changes: 34 additions & 2 deletions eppy/modeleditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions eppy/runningnotes.txt
Original file line number Diff line number Diff line change
@@ -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
----------

Expand Down
11 changes: 11 additions & 0 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit bc1a53b

Please sign in to comment.