Skip to content

Commit

Permalink
fix(translate): Ensure creation of directories uses abspath
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswmackey committed Dec 11, 2024
1 parent 3c01ac3 commit 63e1e71
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
24 changes: 4 additions & 20 deletions honeybee_doe2/cli/translate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""honeybee-doe2 translation commands."""
import sys
import os
import json
import logging
import click

from ladybug.commandutil import process_content_to_output
from honeybee.typing import clean_doe2_string
from honeybee.model import Model
from honeybee_energy.schedule.ruleset import ScheduleRuleset
Expand Down Expand Up @@ -128,7 +128,7 @@ def model_to_inp(
exclude_interior_walls, exclude_interior_ceilings, equest_version)

# write out the INP file
return _process_content_to_output(inp_str, output_file)
return process_content_to_output(inp_str, output_file)


@translate.command('schedules-to-inp')
Expand Down Expand Up @@ -215,7 +215,7 @@ def schedule_to_inp(schedule_json, output_file=None):
inp_str = '\n'.join(inp_str_list)

# write out the INP file
return _process_content_to_output(inp_str, output_file)
return process_content_to_output(inp_str, output_file)


@translate.command('schedules-from-inp')
Expand Down Expand Up @@ -272,20 +272,4 @@ def schedule_from_inp(schedule_inp, array=False, output_file=None, dictionary=Tr
hb_objs = {sch.identifier: sch.to_dict() for sch in schedules}
# write out the JSON file
content_str = json.dumps(hb_objs)
return _process_content_to_output(content_str, output_file)


def _process_content_to_output(content_str, output_file):
"""Process content strings for various types of output_files."""
if output_file is None:
return content_str
elif isinstance(output_file, str):
if not os.path.isdir(os.path.dirname(output_file)):
os.makedirs(os.path.dirname(output_file))
with open(output_file, 'w') as of:
of.write(content_str)
else:
if 'stdout' not in str(output_file):
if not os.path.isdir(os.path.dirname(output_file.name)):
os.makedirs(os.path.dirname(output_file.name))
output_file.write(content_str)
return process_content_to_output(content_str, output_file)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
honeybee-energy>=1.105.50
honeybee-energy>=1.109.33

0 comments on commit 63e1e71

Please sign in to comment.