-
Notifications
You must be signed in to change notification settings - Fork 2
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
[NEAT-235] Excel Importer/Exporter Support Last 🛟 #444
Conversation
0aa4679
to
3efefbc
Compare
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
4616cbc
to
8d9e272
Compare
elif reference_result: | ||
sheets = reference_result.sheets | ||
original_role = reference_result.role | ||
read_info_by_sheet = reference_result.read_info_by_sheet | ||
else: | ||
raise ValueError( | ||
"No rules were generated. This should have been caught earlier. " f"Bug in {type(self).__name__}." | ||
) |
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 case could not happen due to the logic above, so I removed it and thus simplified the logic.
@@ -241,25 +257,29 @@ def _create_metadata_sheet_user_rules(self, rules: Rules) -> dict[str, Any]: | |||
# Excel does not support timezone in datetime strings | |||
now_iso = datetime.now().replace(tzinfo=None).isoformat() | |||
is_info = isinstance(rules, InformationRules) | |||
is_dms = not is_info |
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 dangerous, as it will break if we add asset rules
is_dms = not is_info | ||
is_extension = self.new_model_id is not None | ||
is_solution = is_extension and self.new_model_id != existing_model_id | ||
is_dms = isinstance(rules, DMSRules) |
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 whole function needs a rewrite, have captured it in https://cognitedata.atlassian.net/browse/NEAT-240
sheets: user, last, and reference. The user sheets are used for inputting rules from a user. The last sheets | ||
are used for the last version of the same model as the user, while the reference sheets are used for | ||
the model the user is building on. The options are: | ||
* "user": The rules are written to the user sheets. This is used when you want to modify the rules |
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.
Nice!
@@ -170,17 +189,14 @@ def _write_sheets(self, workbook: Workbook, dumped_rules: dict[str, Any], rules: | |||
for cell in sheet["2"]: | |||
cell.font = Font(bold=True, size=14) | |||
|
|||
def _write_metadata_sheet(self, workbook: Workbook, metadata: dict[str, Any], is_reference: bool = False) -> None: | |||
def _write_metadata_sheet(self, workbook: Workbook, metadata: dict[str, Any], sheet_prefix: str = "") -> None: |
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 makes us future proof with sheet_prefix
, nice !
metadata["prefix" if is_info else "space"] = self.new_model_id[0] # type: ignore[index] | ||
metadata["title" if is_info else "externalId"] = self.new_model_id[1] # type: ignore[index] | ||
metadata["version"] = self.new_model_id[2] # type: ignore[index] | ||
elif is_solution and self.dump_as == "reference" and rules.reference: | ||
metadata["prefix" if is_info else "space"] = "YOUR_PREFIX" | ||
metadata["title" if is_info else "externalId"] = "YOUR_TITLE" |
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.
title is converted to name
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.
my thinking is that prefix
is turned into both external_id
and space
, alt would be to remove all illegal characters from title
and turn it to external_id
@@ -292,7 +292,8 @@ def run(self, rules: MultiRuleData) -> FlowMessage: # type: ignore[override, sy | |||
if role != "input" and role is not None: | |||
output_role = RoleTypes[role] | |||
|
|||
excel_exporter = exporters.ExcelExporter(styling=styling, output_role=output_role, is_reference=is_reference) | |||
dump_as = "reference" if is_reference else "user" |
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.
If not mistaken this cannot currently export user-last-ref ?
Ended up simplifying the logic in both the Importer and Exporter.