Skip to content

Commit

Permalink
#68 changed import directives
Browse files Browse the repository at this point in the history
  • Loading branch information
Sealdolphin committed Jun 22, 2022
1 parent 58cac24 commit fb0e27b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 71 deletions.
1 change: 1 addition & 0 deletions source/incqueryserver-jupyter/iqs_jupyter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

# coding: utf-8
from iqs_jupyter.about import __version__
from iqs_client import models as schema

# end-user modules
from iqs_jupyter.core_extensions import *
Expand Down
12 changes: 6 additions & 6 deletions source/incqueryserver-jupyter/iqs_jupyter/analysis_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

import html

from iqs_client.models import AnalysisResults, AnalysisResult
from iqs_client import models as schema

from iqs_jupyter.helpers import cell_to_html as _cell_to_html
from iqs_jupyter.helpers import dict_to_element as _dict_to_element
from iqs_jupyter.core_extensions import validation_color_scale


def _monkey_patch_analysis_results_repr_html(self: AnalysisResults):
def _monkey_patch_analysis_results_repr_html(self: schema.AnalysisResults):
escaped_id = html.escape(self.configuration.configuration_id)
header_report = '''
<h3>Results for model analysis <b>"{}"</b></h3>
Expand Down Expand Up @@ -104,7 +104,7 @@ def _monkey_patch_analysis_results_repr_html(self: AnalysisResults):
'''.format(header_report, style, kpi_report, toc_report, individual_result_tables)


def _marker_count_report(analysis_result : AnalysisResult) -> str:
def _marker_count_report(analysis_result : schema.AnalysisResult) -> str:
marker_color = validation_color_scale.get(analysis_result.configuration_rule.severity.lower(), None)
marker_style_string = 'style="background-color:{}; color: bisque;"'.format(marker_color) if marker_color else ""
return '{} <span {}>{}</span> marker{}'.format(
Expand All @@ -114,7 +114,7 @@ def _marker_count_report(analysis_result : AnalysisResult) -> str:
"s" if 1 != len(analysis_result.matches) else ""
)

def _monkey_patch_analysis_result_repr_html(self : AnalysisResult, heading_lvl: str = 'h4', anchor : str = None):
def _monkey_patch_analysis_result_repr_html(self : schema.AnalysisResult, heading_lvl: str = 'h4', anchor : str = None):
anchor_tag = '<a name="{}"/>'.format(anchor) if anchor else ""
anchor_href = '<a href="#{}">#</a> '.format(anchor) if anchor else ""
subheader_report = '{}<span title="{}">{} via "{}" <i>(see hover for details)</i></span>'.format(
Expand Down Expand Up @@ -174,7 +174,7 @@ def _monkey_patch_analysis_result_repr_html(self : AnalysisResult, heading_lvl:


def _do_monkey_patching():
AnalysisResults._repr_html_ = _monkey_patch_analysis_results_repr_html
AnalysisResult._repr_html_ = _monkey_patch_analysis_result_repr_html
schema.AnalysisResults._repr_html_ = _monkey_patch_analysis_results_repr_html
schema.AnalysisResult._repr_html_ = _monkey_patch_analysis_result_repr_html

_do_monkey_patching()
64 changes: 27 additions & 37 deletions source/incqueryserver-jupyter/iqs_jupyter/core_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@
import html
from typing import Optional

from iqs_client.models import ElementInCompartmentDescriptor,\
TypedElementInCompartmentDescriptor,\
QueryExecutionResponse,\
ModelCompartment,\
IndexMessage,\
SimpleMessage,\
QueryFQNList, \
GenericValidationResults,\
GenericValidationRule, \
ValidationDiagnostics

from iqs_client import models as schema

import iqs_jupyter.tool_extension_point as ext_point
from iqs_jupyter.helpers import cell_to_html as _cell_to_html
Expand All @@ -46,12 +36,12 @@

def _recognize_element_in_compartment_descriptor(
dict_of_element : dict
) -> Optional[ElementInCompartmentDescriptor]:
) -> Optional[schema.ElementInCompartmentDescriptor]:
if "relativeElementID" in dict_of_element:
return ElementInCompartmentDescriptor(
return schema.ElementInCompartmentDescriptor(
**dict(
(py_name, dict_of_element[json_name])
for py_name, json_name in ElementInCompartmentDescriptor.attribute_map.items()
for py_name, json_name in schema.ElementInCompartmentDescriptor.attribute_map.items()
)
)
else:
Expand All @@ -62,16 +52,16 @@ def _recognize_element_in_compartment_descriptor(

def _recognize_typed_element_in_compartment_descriptor(
dict_of_element : dict
) -> Optional[TypedElementInCompartmentDescriptor]:
) -> Optional[schema.TypedElementInCompartmentDescriptor]:
if "element" in dict_of_element:
return TypedElementInCompartmentDescriptor(
return schema.TypedElementInCompartmentDescriptor(
**dict(
(
py_name,
_recognize_element_in_compartment_descriptor(dict_of_element[json_name])
if py_name == "element" else dict_of_element[json_name]
)
for py_name, json_name in TypedElementInCompartmentDescriptor.attribute_map.items()
for py_name, json_name in schema.TypedElementInCompartmentDescriptor.attribute_map.items()
)
)
else:
Expand All @@ -95,20 +85,20 @@ def _monkey_patch_element_in_compartment_descriptor_repr_html(self):


def _monkey_patch_element_in_compartment_descriptor_resolve_reference(self, target_element_relative_id):
return ElementInCompartmentDescriptor(
return schema.ElementInCompartmentDescriptor(
compartment_uri = self.compartment_uri,
relative_element_id = target_element_relative_id
)

def _monkey_patch_model_compartment_get_element_in_compartment_by_id(self, relative_element_id):
return ElementInCompartmentDescriptor(
return schema.ElementInCompartmentDescriptor(
compartment_uri=self.compartment_uri,
relative_element_id=relative_element_id
)

def _monkey_patch_model_compartment_is_loaded_by_server(self, iqs):
in_memory_compartments_response = iqs.in_memory_index.list_inmemory_model_compartments()
return self in in_memory_compartments_response.inmemory_model_compartments
return self.compartment_uri in map(lambda model: model.compartment_uri, in_memory_compartments_response.inmemory_model_compartments)


def _monkey_patch_query_execution_response_to_data_frame(self, url_provider=None):
Expand Down Expand Up @@ -302,27 +292,27 @@ def _monkey_patch_query_execution_response_to_html(self):


def _do_monkey_patching():
ElementInCompartmentDescriptor._repr_html_ = _monkey_patch_element_in_compartment_descriptor_repr_html
ElementInCompartmentDescriptor.resolve_reference = _monkey_patch_element_in_compartment_descriptor_resolve_reference
schema.ElementInCompartmentDescriptor._repr_html_ = _monkey_patch_element_in_compartment_descriptor_repr_html
schema.ElementInCompartmentDescriptor.resolve_reference = _monkey_patch_element_in_compartment_descriptor_resolve_reference

ModelCompartment.get_element_in_compartment_by_id = _monkey_patch_model_compartment_get_element_in_compartment_by_id
ModelCompartment.is_loaded_by_server = _monkey_patch_model_compartment_is_loaded_by_server
schema.ModelCompartment.get_element_in_compartment_by_id = _monkey_patch_model_compartment_get_element_in_compartment_by_id
schema.ModelCompartment.is_loaded_by_server = _monkey_patch_model_compartment_is_loaded_by_server

QueryExecutionResponse.to_list_of_matches = _monkey_patch_query_execution_response_to_list_of_matches
QueryExecutionResponse.to_data_frame = _monkey_patch_query_execution_response_to_data_frame
QueryExecutionResponse.to_data_frame = _monkey_patch_query_execution_response_to_data_frame
QueryExecutionResponse._repr_html_ = _monkey_patch_query_execution_response_to_html
IndexMessage._repr_html_ = _monkey_patch_generic_response_message_repr_html_
SimpleMessage._repr_html_ = _monkey_patch_generic_response_message_repr_html_
QueryFQNList._repr_html_ = _monkey_patch_query_fqn_list_repr_html_
schema.QueryExecutionResponse.to_list_of_matches = _monkey_patch_query_execution_response_to_list_of_matches
schema.QueryExecutionResponse.to_data_frame = _monkey_patch_query_execution_response_to_data_frame
schema.QueryExecutionResponse.to_data_frame = _monkey_patch_query_execution_response_to_data_frame
schema.QueryExecutionResponse._repr_html_ = _monkey_patch_query_execution_response_to_html
schema.IndexMessage._repr_html_ = _monkey_patch_generic_response_message_repr_html_
schema.SimpleMessage._repr_html_ = _monkey_patch_generic_response_message_repr_html_
schema.QueryFQNList._repr_html_ = _monkey_patch_query_fqn_list_repr_html_

# TODO TWC-specific version missing, as well as additional features
GenericValidationResults.to_list_of_diagnostic_items = _monkey_patch_generic_validation_results_to_list_of_diagnostic_items
GenericValidationResults.to_data_frame = _monkey_patch_generic_validation_results_to_data_frame
GenericValidationResults._repr_html_ = _monkey_patch_generic_validation_results_repr_html
GenericValidationRule._repr_html_ = _monkey_patch_generic_validation_rule_repr_html
ValidationDiagnostics._repr_html_ = _monkey_patch_validation_diagnostics_reps_html
TypedElementInCompartmentDescriptor._repr_html_ = _monkey_patch_typed_element_in_compartment_repr_html
schema.GenericValidationResults.to_list_of_diagnostic_items = _monkey_patch_generic_validation_results_to_list_of_diagnostic_items
schema.GenericValidationResults.to_data_frame = _monkey_patch_generic_validation_results_to_data_frame
schema.GenericValidationResults._repr_html_ = _monkey_patch_generic_validation_results_repr_html
schema.GenericValidationRule._repr_html_ = _monkey_patch_generic_validation_rule_repr_html
schema.ValidationDiagnostics._repr_html_ = _monkey_patch_validation_diagnostics_reps_html
schema.TypedElementInCompartmentDescriptor._repr_html_ = _monkey_patch_typed_element_in_compartment_repr_html

_do_monkey_patching()

Expand Down
18 changes: 9 additions & 9 deletions source/incqueryserver-jupyter/iqs_jupyter/mms_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import ipywidgets as widgets
from IPython.display import display

from iqs_client.models import MMSCommitDescriptor, ModelCompartment
from iqs_client import models as schema

import iqs_jupyter.config_defaults as defaults
import iqs_jupyter.tool_extension_point as ext_point
Expand Down Expand Up @@ -212,7 +212,7 @@ def value(self):
self.project_widget.index != 0 and
self.org_widget.index != 0
):
return MMSCommitDescriptor.from_fields(
return schema.MMSCommitDescriptor.from_fields(
name=self.commit_map[self.commit_widget.value]['name'],
commit_id=self.commit_widget.value,
ref_id=self.ref_widget.value,
Expand Down Expand Up @@ -244,7 +244,7 @@ def _monkey_patch_static_mms_commit_descriptor_from_compartment_uri_or_none(comp
):
return None

return MMSCommitDescriptor(
return schema.MMSCommitDescriptor(
org_id = segments[2],
project_id = segments[4],
ref_id = segments[6],
Expand All @@ -267,7 +267,7 @@ def _mms_compartment_uri(org_id, project_id, ref_id, commit_id):
commit_id
)
def _monkey_patch_static_mms_commit_descriptor_from_fields(org_id, project_id, ref_id, commit_id, name = None):
return MMSCommitDescriptor(
return schema.MMSCommitDescriptor(
name=name,
commit_id=commit_id,
ref_id=ref_id,
Expand All @@ -277,17 +277,17 @@ def _monkey_patch_static_mms_commit_descriptor_from_fields(org_id, project_id, r
)

def _monkey_patch_mms_commit_to_model_compartment(self):
return ModelCompartment(compartment_uri=self.to_compartment_uri())
return schema.ModelCompartment(compartment_uri=self.to_compartment_uri())


def _monkey_patch_jupytertools_mms_commit_selector_widget(self, **kwargs):
return MMCCommitSelectorWidget(iqs=self._iqs, **kwargs)

def _do_monkey_patching():
MMSCommitDescriptor.from_compartment_uri_or_none = staticmethod(_monkey_patch_static_mms_commit_descriptor_from_compartment_uri_or_none)
MMSCommitDescriptor.from_fields = staticmethod(_monkey_patch_static_mms_commit_descriptor_from_fields)
MMSCommitDescriptor.to_compartment_uri = _monkey_patch_mms_commit_to_compartment_uri
MMSCommitDescriptor.to_model_compartment = _monkey_patch_mms_commit_to_model_compartment
schema.MMSCommitDescriptor.from_compartment_uri_or_none = staticmethod(_monkey_patch_static_mms_commit_descriptor_from_compartment_uri_or_none)
schema.MMSCommitDescriptor.from_fields = staticmethod(_monkey_patch_static_mms_commit_descriptor_from_fields)
schema.MMSCommitDescriptor.to_compartment_uri = _monkey_patch_mms_commit_to_compartment_uri
schema.MMSCommitDescriptor.to_model_compartment = _monkey_patch_mms_commit_to_model_compartment

ext_point.IQSJupyterTools.mms_commit_selector_widget = _monkey_patch_jupytertools_mms_commit_selector_widget

Expand Down
38 changes: 19 additions & 19 deletions source/incqueryserver-jupyter/iqs_jupyter/twc_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import ipywidgets as widgets
from IPython.display import display

from iqs_client.models import RevisionDescriptor, ElementDescriptor, ListDependenciesResponse, ModelCompartment
from iqs_client import models as schema

import iqs_jupyter.config_defaults as defaults
import iqs_jupyter.tool_extension_point as ext_point
Expand Down Expand Up @@ -55,7 +55,7 @@ def _repr_html_(self):
self.display()

def value(self):
return RevisionDescriptor(
return schema.RevisionDescriptor(
revision_number = self.revision_widget.value,
branch_id = self.branch_widget.value,
resource_id = self.resource_widget.value,
Expand Down Expand Up @@ -237,7 +237,7 @@ def value(self):
self.resource_widget.index != 0 and
self.workspace_widget.index != 0
):
return RevisionDescriptor(
return schema.RevisionDescriptor(
revision_number = self.revision_widget.value,
branch_id = self.branch_widget.value,
resource_id = self.resource_widget.value,
Expand All @@ -250,12 +250,12 @@ def value(self):

# recognizing element descriptors in match results

def _recognize_element_descriptor(dict_of_element : dict) -> Optional[ElementDescriptor]:
def _recognize_element_descriptor(dict_of_element : dict) -> Optional[schema.ElementDescriptor]:
if "workspaceId" in dict_of_element:
return ElementDescriptor(
return schema.ElementDescriptor(
**dict(
(py_name, dict_of_element[json_name])
for py_name, json_name in ElementDescriptor.attribute_map.items()
for py_name, json_name in schema.ElementDescriptor.attribute_map.items()
)
)
else:
Expand Down Expand Up @@ -326,7 +326,7 @@ def _monkey_patch_list_dependencies_response_repr_html(self):
)

def _monkey_patch_element_descriptor_resolve_reference(self, target_element_id):
return ElementDescriptor(
return schema.ElementDescriptor(
revision_number = self.revision_number,
branch_id = self.branch_id,
resource_id = self.resource_id,
Expand All @@ -335,15 +335,15 @@ def _monkey_patch_element_descriptor_resolve_reference(self, target_element_id):
)

def _monkey_patch_element_descriptor_get_containing_revision(self):
return RevisionDescriptor(
return schema.RevisionDescriptor(
revision_number = self.revision_number,
branch_id = self.branch_id,
resource_id = self.resource_id,
workspace_id = self.workspace_id
)

def _monkey_patch_revision_descriptor_get_element_descriptor_by_id(self, element_id):
return ElementDescriptor(
return schema.ElementDescriptor(
revision_number = self.revision_number,
branch_id = self.branch_id,
resource_id = self.resource_id,
Expand All @@ -358,21 +358,21 @@ def _monkey_patch_revision_descriptor_to_compartment_uri(self):


def _monkey_patch_revision_descriptor_to_model_compartment(self):
return ModelCompartment(compartment_uri=self.to_compartment_uri())
return schema.ModelCompartment(compartment_uri=self.to_compartment_uri())

def _monkey_patch_jupytertools_twc_revision_selector_widget(self, **kwargs):
return TWCRevisionSelectorWidget(iqs=self._iqs, **kwargs)

def _do_monkey_patching():
ElementDescriptor.to_str = _monkey_patch_element_descriptor_to_str
ElementDescriptor.to_descriptor_str = _monkey_patch_element_descriptor_to_descriptor_str
ElementDescriptor._repr_html_ = _monkey_patch_element_descriptor_repr_html
ElementDescriptor.resolve_reference = _monkey_patch_element_descriptor_resolve_reference
ElementDescriptor.get_containing_revision = _monkey_patch_element_descriptor_get_containing_revision
RevisionDescriptor.get_element_descriptor_by_id = _monkey_patch_revision_descriptor_get_element_descriptor_by_id
RevisionDescriptor.to_compartment_uri = _monkey_patch_revision_descriptor_to_compartment_uri
RevisionDescriptor.to_model_compartment = _monkey_patch_revision_descriptor_to_model_compartment
ListDependenciesResponse._repr_html_ = _monkey_patch_list_dependencies_response_repr_html
schema.ElementDescriptor.to_str = _monkey_patch_element_descriptor_to_str
schema.ElementDescriptor.to_descriptor_str = _monkey_patch_element_descriptor_to_descriptor_str
schema.ElementDescriptor._repr_html_ = _monkey_patch_element_descriptor_repr_html
schema.ElementDescriptor.resolve_reference = _monkey_patch_element_descriptor_resolve_reference
schema.ElementDescriptor.get_containing_revision = _monkey_patch_element_descriptor_get_containing_revision
schema.RevisionDescriptor.get_element_descriptor_by_id = _monkey_patch_revision_descriptor_get_element_descriptor_by_id
schema.RevisionDescriptor.to_compartment_uri = _monkey_patch_revision_descriptor_to_compartment_uri
schema.RevisionDescriptor.to_model_compartment = _monkey_patch_revision_descriptor_to_model_compartment
schema.ListDependenciesResponse._repr_html_ = _monkey_patch_list_dependencies_response_repr_html

ext_point.IQSJupyterTools.twc_revision_selector_widget = _monkey_patch_jupytertools_twc_revision_selector_widget

Expand Down

0 comments on commit fb0e27b

Please sign in to comment.