Skip to content

Commit

Permalink
Merge pull request #61 from samuelduchesne/feature/MacOsFix
Browse files Browse the repository at this point in the history
Silent OSX install is different after 9.2. This pull request fixes that. Also changes error handling in run_eplus
  • Loading branch information
samuelduchesne committed Jan 29, 2020
2 parents 60a7eca + c1f1bd7 commit 0415e97
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 66 deletions.
18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ATTCHBASE=98; ATTCHNUM=8232; fi
- if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then ATTCHBASE=86; ATTCHNUM=8231; fi
- EXTRAS_DOWNLOAD_URL=http://energyplus.helpserve.com/Knowledgebase/Article/GetAttachment/$ATTCHBASE/$ATTCHNUM
- curl -SLO $EXTRAS_DOWNLOAD_URL
- curl -SL $EXTRAS_DOWNLOAD_URL -o $ATTCHNUM.zip
# install EnergyPlus
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then
sudo hdiutil attach $ENERGYPLUS_DOWNLOAD_FILENAME.$EXT;
sudo installer -pkg /Volumes/$ENERGYPLUS_DOWNLOAD_FILENAME/$ENERGYPLUS_DOWNLOAD_FILENAME.pkg -target /; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
sudo chmod +x $ENERGYPLUS_DOWNLOAD_FILENAME.$EXT;
echo "y\r" | sudo ./$ENERGYPLUS_DOWNLOAD_FILENAME.$EXT;
sudo tar zxvf $ATTCHNUM -C /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater;
sudo tar zxvf $ATTCHNUM.zip -C /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater;
sudo chmod -R a+rwx /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater;
sudo chmod -R a+rwx /usr/local/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/ExampleFiles; fi
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then
sudo tar zxvf $ATTCHNUM -C /Applications/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater;
curl -SLO https://raw.githubusercontent.com/NREL/EnergyPlus/3cf5e1c8e6944e8a7760b80078c6945073cc8364/cmake/qtifw/install_script.qs;
sudo hdiutil attach $ENERGYPLUS_DOWNLOAD_FILENAME.$EXT;
sudo /Volumes/$ENERGYPLUS_DOWNLOAD_FILENAME/$ENERGYPLUS_DOWNLOAD_FILENAME.app/Contents/MacOS/$ENERGYPLUS_DOWNLOAD_FILENAME --verbose --script install_script.qs;
sudo tar zxvf $ATTCHNUM.zip -C /Applications/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess;
sudo chmod -R a+rwx /Applications/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/PreProcess/IDFVersionUpdater;
sudo chmod -R a+rwx /Applications/EnergyPlus-$ENERGYPLUS_INSTALL_VERSION/ExampleFiles; fi
- if [ "$TRAVIS_OS_NAME" == "windows" ]; then
sudo chmod +x $ENERGYPLUS_DOWNLOAD_FILENAME.$EXT;
echo "y\r" | sudo ./$ENERGYPLUS_DOWNLOAD_FILENAME.$EXT; fi
# clean install files
# remove install files
- sudo rm $ENERGYPLUS_DOWNLOAD_FILENAME.$EXT
- sudo rm $ATTCHNUM
- sudo rm $ATTCHNUM.zip

# Install python for Linux
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
Expand Down Expand Up @@ -91,7 +91,7 @@ install:
- pip install --upgrade pip
- pip install .[dev]
script:
- py.test --cov=archetypal --verbose tests/
- py.test --cov=archetypal tests/
after_success:
- coverage report -m
- coveralls
86 changes: 41 additions & 45 deletions archetypal/idfclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ def _eppy_load(
)
except FileNotFoundError:
# Loading the idf object will raise a FileNotFoundError if the
# version of EnergyPlus is not included
# version of EnergyPlus is not installed
log("Transitioning idf file {}".format(file))
# if they don't fit, upgrade file
file = idf_version_updater(file, out_dir=output_folder, to_version=ep_version)
Expand Down Expand Up @@ -2292,7 +2292,9 @@ def idf_version_updater(idf_file, to_version=None, out_dir=None, simulname=None)
if not out_dir.isdir():
# check if dir exists
out_dir.makedirs_p()
with TemporaryDirectory(prefix="transition_run_", suffix=simulname, dir=out_dir) as tmp:
with TemporaryDirectory(
prefix="transition_run_", suffix=simulname, dir=out_dir
) as tmp:
log("temporary dir (%s) created" % tmp, lg.DEBUG)
idf_file = Path(idf_file.copy(tmp)).abspath() # copy and return abspath

Expand Down Expand Up @@ -2376,50 +2378,44 @@ def idf_version_updater(idf_file, to_version=None, out_dir=None, simulname=None)

# Otherwise,
# build a list of command line arguments
with cd(vupdater_path):
transitions = [
key
for key in trans_exec
if tuple(map(int, key.split("-")))
< tuple(map(int, to_version.split("-")))
and tuple(map(int, key.split("-")))
>= tuple(map(int, versionid.split("-")))
]
for trans in transitions:
try:
exists = Path(trans_exec[trans]).exists()
if not exists:
raise FileNotFoundError(
errno.ENOENT,
os.strerror(errno.ENOENT),
Path(trans_exec[trans]),
)
except KeyError:
# there is no more updates to perfrom
result = 0
except FileNotFoundError:
raise EnergyPlusProcessError(
cmd=trans_exec[trans],
stderr="The specified EnergyPlus version (v{}) does not have the"
" required transition program '{}' in the PreProcess folder. "
"See the documentation (archetypal.readthedocs.io/troubleshooting.html#missing-transition-programs) to solve "
"this issue".format(to_version, trans_exec[trans]),
)
else:
cmd = [trans_exec[trans], idf_file]
try:
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
process_output, error_output = process.communicate()
log(process_output.decode("utf-8"), lg.DEBUG)
except CalledProcessError as exception:
log(
"{} failed with error\n".format(
idf_version_updater.__name__, str(exception)
),
lg.ERROR,
try:
with cd(vupdater_path):
transitions = [
key
for key in trans_exec
if tuple(map(int, key.split("-")))
< tuple(map(int, to_version.split("-")))
and tuple(map(int, key.split("-")))
>= tuple(map(int, versionid.split("-")))
]
for trans in transitions:
if not trans_exec[trans].exists():
raise EnergyPlusProcessError(
cmd=trans_exec[trans],
stderr="The specified EnergyPlus version (v{}) does not have"
" the required transition program '{}' in the "
"PreProcess folder. See the documentation "
"(archetypal.readthedocs.io/troubleshooting.html#missing-transition-programs) "
"to solve this issue".format(to_version, trans_exec[trans]),
idf=idf_file.basename()
)
else:
cmd = [trans_exec[trans], idf_file]
try:
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
process_output, error_output = process.communicate()
log(process_output.decode("utf-8"), lg.DEBUG)
except CalledProcessError as exception:
log(
"{} failed with error\n".format(
idf_version_updater.__name__, str(exception)
),
lg.ERROR,
)
except EnergyPlusProcessError as e:
raise e
for f in Path(tmp).files("*.idfnew"):
f.copy(out_dir / idf_file.basename())
return Path(out_dir / idf_file.basename())
Expand Down
20 changes: 8 additions & 12 deletions archetypal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def validate_trnsys_folder(trnsys_default_folder):
else:
warnings.warn(
"The TRNSYS path does not exist. Please set the TRNSYS "
"path with the --trnsys-default-folder option".format(trnsys_default_folder)
"path with the --trnsys-default-folder option".format(
trnsys_default_folder
)
)
return None
else:
Expand Down Expand Up @@ -647,22 +649,17 @@ def copy_file(files, where=None):
return _unpack_tuple(list(files.values()))


class Error(Exception):
"""Base class for exceptions in this module."""

pass


class EnergyPlusProcessError(Error):
class EnergyPlusProcessError(Exception):
"""EnergyPlus Process call error"""

def __init__(self, cmd, stderr, idf=None):
def __init__(self, cmd, stderr, idf):
"""
Args:
cmd:
stderr:
idf:
"""
super().__init__(stderr)
self.cmd = cmd
self.idf = idf
self.stderr = stderr
Expand All @@ -673,10 +670,11 @@ def __str__(self):
return msg


class EnergyPlusVersionError(Error):
class EnergyPlusVersionError(Exception):
"""EnergyPlus Version call error"""

def __init__(self, idf_file, idf_version, ep_version):
super(EnergyPlusVersionError, self).__init__(None)
self.idf_file = idf_file
self.idf_version = idf_version
self.ep_version = ep_version
Expand Down Expand Up @@ -711,8 +709,6 @@ def cd(path):
log("inside {0}".format(os.getcwd()))
try:
yield
except:
log("Exception caught: ", sys.exc_info()[0])
finally:
os.chdir(CWD)
log("finally inside {0}".format(os.getcwd()))
Expand Down

0 comments on commit 0415e97

Please sign in to comment.