-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing user to specify a target version #58
Conversation
Minimum allowed coverage is Generated by 🐒 cobertura-action against d49a19f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about all the diffs. I used an automatic formatter (black) that changed a lot of things. I also:
- added type hints to the functions
- deprecated the
convert_hpxml_to_3
function. It'll throw a warning if someone uses it. It's not used in the default cli anymore.
def convert_hpxml_to_version( | ||
hpxml_version: int, hpxml_file: File, hpxml_out_file: File | ||
) -> None: | ||
schema_version = detect_hpxml_version(hpxml_file) | ||
major_version = schema_version[0] | ||
if major_version == 1: | ||
hpxml2_file = tempfile.NamedTemporaryFile() | ||
convert_hpxml1_to_2(hpxml_file, hpxml2_file) | ||
convert_hpxml2_to_3(hpxml2_file, hpxml3_file) | ||
elif major_version == 2: | ||
convert_hpxml2_to_3(hpxml_file, hpxml3_file) | ||
if hpxml_version <= major_version: | ||
raise exc.HpxmlTranslationError( | ||
f"HPXML version requested is {hpxml_version} but input file version is {major_version}" | ||
) | ||
version_translator_funcs = {1: convert_hpxml1_to_2, 2: convert_hpxml2_to_3} | ||
if hpxml_version - 1 not in version_translator_funcs.keys(): | ||
raise exc.HpxmlTranslationError(f"HPXML version {hpxml_version} not available") | ||
current_file = hpxml_file | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
for current_version in range(major_version, hpxml_version): | ||
next_version = current_version + 1 | ||
next_file = ( | ||
hpxml_out_file | ||
if current_version + 1 == hpxml_version | ||
else pathlib.Path(tmpdir, f"{next_version}.xml") | ||
) | ||
version_translator_funcs[current_version](current_file, next_file) | ||
current_file = next_file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most pertinent code.
hpxml_version_translator/__init__.py
Outdated
type=int, | ||
default=3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we ask for the full version number? A software tool might very specifically restrict the version of HPXML they want. For example, it might require v2.0, whereas if the user specified 2 here they would get v2.3 automatically. We might as well be as useful as possible, right?
It wouldn't fundamentally change any of the logic in the translator, just the final version number that ends up in the HPXML file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I 100% agree with the argument that it wouldn't change the logic of the translator. We'd also need to have all the minor version schemas available to validate against as well to make sure we didn't add anything extra.
Co-authored-by: Scott Horowitz <scott.horowitz@nrel.gov>
Fixes #56