Skip to content
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

#68 fixing import directives #69

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions source/incqueryserver-jupyter/iqs_jupyter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,15 @@
from iqs_jupyter.core_extensions import *
from iqs_jupyter.authentication import *

if 'MmsRepositoryApi' in dir(iqs_client):
from iqs_jupyter.mms_extensions import *
from iqs_jupyter.mms_direct_extensions import *
#if 'MmsRepositoryApi' in dir(iqs_client):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that we no longer ship trimmed down versions of the core API, but is there any specific need to remove these conditionals? I would expect them to work just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it inconsistent, because the new generator creates a different architecture... If we want it to stay, we may change it, but I thought it was easier for now to omit these features. This is a work in progress.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we changed which openapi generator we use? Is there a specific reason why we instituted such a change? Does it otherwise generate better client code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the new version is generated using a gradle plugin, instead of a library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean OpenAPI (whether invoked from the CLI or via Gradle) has a selection of plugins called "generators". Are we still using the same one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bergmanngabor - We would like to upgrade OpenApi generator to 5.x project-wise in IQS, I think it is reasonable to use newer version, because later we might face issues caused by the outdated generator.

from iqs_jupyter.mms_extensions import *
from iqs_jupyter.mms_direct_extensions import *

if 'RepositoryApi' in dir(iqs_client):
from iqs_jupyter.twc_extensions import *
from iqs_jupyter.twc_osmc_extensions import *
#if 'RepositoryApi' in dir(iqs_client):
from iqs_jupyter.twc_extensions import *
from iqs_jupyter.twc_osmc_extensions import *

if 'AnalysisApi' in dir(iqs_client):
from iqs_jupyter.analysis_extensions import *

# namespace shortcut for API request/response classes
from iqs_client import models as schema
#if 'AnalysisApi' in dir(iqs_client):
from iqs_jupyter.analysis_extensions import *


13 changes: 7 additions & 6 deletions source/incqueryserver-jupyter/iqs_jupyter/analysis_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@

import html

import iqs_client
Sealdolphin marked this conversation as resolved.
Show resolved Hide resolved
from iqs_client.models import AnalysisResults, AnalysisResult

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


def _marker_count_report(analysis_result : iqs_client.AnalysisResult) -> str:
def _marker_count_report(analysis_result : 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 @@ -113,7 +114,7 @@ def _marker_count_report(analysis_result : iqs_client.AnalysisResult) -> str:
"s" if 1 != len(analysis_result.matches) else ""
)

def _monkey_patch_analysis_result_repr_html(self : iqs_client.AnalysisResult, heading_lvl: str = 'h4', anchor : str = None):
def _monkey_patch_analysis_result_repr_html(self : 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 @@ -173,7 +174,7 @@ def _monkey_patch_analysis_result_repr_html(self : iqs_client.AnalysisResult, he


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

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

import iqs_client
from iqs_client.models import ElementInCompartmentDescriptor,\
TypedElementInCompartmentDescriptor,\
QueryExecutionResponse,\
ModelCompartment,\
IndexMessage,\
SimpleMessage,\
QueryFQNList, \
GenericValidationResults,\
GenericValidationRule, \
ValidationDiagnostics
Sealdolphin marked this conversation as resolved.
Show resolved Hide resolved


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

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

def _recognize_typed_element_in_compartment_descriptor(
dict_of_element : dict
) -> Optional[iqs_client.TypedElementInCompartmentDescriptor]:
) -> Optional[TypedElementInCompartmentDescriptor]:
if "element" in dict_of_element:
return iqs_client.TypedElementInCompartmentDescriptor(
return 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 iqs_client.TypedElementInCompartmentDescriptor.attribute_map.items()
for py_name, json_name in TypedElementInCompartmentDescriptor.attribute_map.items()
)
)
else:
Expand All @@ -85,13 +95,13 @@ 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 iqs_client.ElementInCompartmentDescriptor(
return 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 iqs_client.ElementInCompartmentDescriptor(
return ElementInCompartmentDescriptor(
compartment_uri=self.compartment_uri,
relative_element_id=relative_element_id
)
Expand Down Expand Up @@ -292,27 +302,27 @@ def _monkey_patch_query_execution_response_to_html(self):


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

iqs_client.ModelCompartment.get_element_in_compartment_by_id = _monkey_patch_model_compartment_get_element_in_compartment_by_id
iqs_client.ModelCompartment.is_loaded_by_server = _monkey_patch_model_compartment_is_loaded_by_server
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

iqs_client.QueryExecutionResponse.to_list_of_matches = _monkey_patch_query_execution_response_to_list_of_matches
iqs_client.QueryExecutionResponse.to_data_frame = _monkey_patch_query_execution_response_to_data_frame
iqs_client.QueryExecutionResponse.to_data_frame = _monkey_patch_query_execution_response_to_data_frame
iqs_client.QueryExecutionResponse._repr_html_ = _monkey_patch_query_execution_response_to_html
iqs_client.IndexMessage._repr_html_ = _monkey_patch_generic_response_message_repr_html_
iqs_client.SimpleMessage._repr_html_ = _monkey_patch_generic_response_message_repr_html_
iqs_client.QueryFQNList._repr_html_ = _monkey_patch_query_fqn_list_repr_html_
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_

# TODO TWC-specific version missing, as well as additional features
iqs_client.GenericValidationResults.to_list_of_diagnostic_items = _monkey_patch_generic_validation_results_to_list_of_diagnostic_items
iqs_client.GenericValidationResults.to_data_frame = _monkey_patch_generic_validation_results_to_data_frame
iqs_client.GenericValidationResults._repr_html_ = _monkey_patch_generic_validation_results_repr_html
iqs_client.GenericValidationRule._repr_html_ = _monkey_patch_generic_validation_rule_repr_html
iqs_client.ValidationDiagnostics._repr_html_ = _monkey_patch_validation_diagnostics_reps_html
iqs_client.TypedElementInCompartmentDescriptor._repr_html_ = _monkey_patch_typed_element_in_compartment_repr_html
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

_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

import iqs_client
from iqs_client.models import MMSCommitDescriptor, ModelCompartment

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 iqs_client.MMSCommitDescriptor.from_fields(
return 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 iqs_client.MMSCommitDescriptor(
return 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 iqs_client.MMSCommitDescriptor(
return 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 iqs_client.ModelCompartment(compartment_uri=self.to_compartment_uri())
return 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():
iqs_client.MMSCommitDescriptor.from_compartment_uri_or_none = staticmethod(_monkey_patch_static_mms_commit_descriptor_from_compartment_uri_or_none)
iqs_client.MMSCommitDescriptor.from_fields = staticmethod(_monkey_patch_static_mms_commit_descriptor_from_fields)
iqs_client.MMSCommitDescriptor.to_compartment_uri = _monkey_patch_mms_commit_to_compartment_uri
iqs_client.MMSCommitDescriptor.to_model_compartment = _monkey_patch_mms_commit_to_model_compartment
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

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

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

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 iqs_client.RevisionDescriptor(
return 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 iqs_client.RevisionDescriptor(
return 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[iqs_client.ElementDescriptor]:
def _recognize_element_descriptor(dict_of_element : dict) -> Optional[ElementDescriptor]:
if "workspaceId" in dict_of_element:
return iqs_client.ElementDescriptor(
return ElementDescriptor(
**dict(
(py_name, dict_of_element[json_name])
for py_name, json_name in iqs_client.ElementDescriptor.attribute_map.items()
for py_name, json_name in 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 iqs_client.ElementDescriptor(
return 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 iqs_client.RevisionDescriptor(
return 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 iqs_client.ElementDescriptor(
return 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 iqs_client.ModelCompartment(compartment_uri=self.to_compartment_uri())
return 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():
iqs_client.ElementDescriptor.to_str = _monkey_patch_element_descriptor_to_str
iqs_client.ElementDescriptor.to_descriptor_str = _monkey_patch_element_descriptor_to_descriptor_str
iqs_client.ElementDescriptor._repr_html_ = _monkey_patch_element_descriptor_repr_html
iqs_client.ElementDescriptor.resolve_reference = _monkey_patch_element_descriptor_resolve_reference
iqs_client.ElementDescriptor.get_containing_revision = _monkey_patch_element_descriptor_get_containing_revision
iqs_client.RevisionDescriptor.get_element_descriptor_by_id = _monkey_patch_revision_descriptor_get_element_descriptor_by_id
iqs_client.RevisionDescriptor.to_compartment_uri = _monkey_patch_revision_descriptor_to_compartment_uri
iqs_client.RevisionDescriptor.to_model_compartment = _monkey_patch_revision_descriptor_to_model_compartment
iqs_client.ListDependenciesResponse._repr_html_ = _monkey_patch_list_dependencies_response_repr_html
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

ext_point.IQSJupyterTools.twc_revision_selector_widget = _monkey_patch_jupytertools_twc_revision_selector_widget

Expand Down