diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5c8d02ae..06b612d5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,8 +25,8 @@ repos: - id: end-of-file-fixer - id: fix-byte-order-marker - id: trailing-whitespace - - repo: https://github.com/psf/black - rev: 23.3.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.9.1 hooks: - id: black - repo: https://github.com/PyCQA/isort @@ -34,7 +34,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/docformatter - rev: v1.7.2 + rev: v1.7.5 hooks: - id: docformatter additional_dependencies: @@ -47,7 +47,7 @@ repos: additional_dependencies: - pydocstyle[toml] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.3.0 + rev: v1.5.1 hooks: - id: mypy additional_dependencies: @@ -97,10 +97,10 @@ repos: - --comment-style - "..| |" - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 + rev: v2.1.0 hooks: - id: reuse - repo: https://github.com/qoomon/git-conventional-commits - rev: v2.6.4 + rev: v2.6.5 hooks: - id: conventional-commits diff --git a/capella2polarion/elements/api_helper.py b/capella2polarion/elements/api_helper.py index d72403f7..966c2fc9 100644 --- a/capella2polarion/elements/api_helper.py +++ b/capella2polarion/elements/api_helper.py @@ -29,12 +29,16 @@ def patch_work_item( ctx The context to execute the patch for. obj - The Capella object to update the WorkItem from + The Capella object to update the WorkItem from. receiver A function that receives the WorkItem from the created - instances. + instances. This function alters the WorkItem instances by adding + attributes, e.g.: `linked_work_items`. It can be useful to add + attributes which can only be computed after the work item and + its default attributes were instantiated. name - The name of the object, which should be displayed in log messages. + The name of the object, which should be displayed in log + messages. _type The type of element, which should be shown in log messages. """ @@ -46,7 +50,7 @@ def patch_work_item( log_args = (wid, _type, name) logger.info("Update work item %r for model %s %r...", *log_args) - if new.uuid_capella: + if "uuid_capella" in new.additional_attributes: del new.additional_attributes["uuid_capella"] old.linked_work_items = ctx["API"].get_all_work_item_links(old.id) diff --git a/capella2polarion/elements/element.py b/capella2polarion/elements/element.py index c64ef780..a3db417d 100644 --- a/capella2polarion/elements/element.py +++ b/capella2polarion/elements/element.py @@ -43,7 +43,7 @@ def create_work_items( _work_items.append(serialize.element(obj, ctx, serializer)) - _work_items = list(filter(None.__ne__, _work_items)) + _work_items = list(filter(None, _work_items)) valid_types = set(map(helpers.resolve_element_type, set(ctx["ELEMENTS"]))) work_items: list[polarion_api.CapellaWorkItem] = [] missing_types: set[str] = set() @@ -184,7 +184,7 @@ def _create( ) for id in new ] - return list(filter(None.__ne__, _new_links)) + return list(filter(None, _new_links)) def _handle_exchanges( diff --git a/capella2polarion/elements/serialize.py b/capella2polarion/elements/serialize.py index 51f73534..7a1ee35d 100644 --- a/capella2polarion/elements/serialize.py +++ b/capella2polarion/elements/serialize.py @@ -112,7 +112,7 @@ def _generic_work_item( ) -> CapellaWorkItem: xtype = ctx["POLARION_TYPE_MAP"].get(obj.uuid, type(obj).__name__) raw_description = getattr(obj, "description", markupsafe.Markup("")) - uuids, value = _sanitize_description(raw_description, ctx) + uuids, value = _sanitize_description(obj, raw_description, ctx) ctx.setdefault("DESCR_REFERENCES", {})[obj.uuid] = uuids requirement_types = _get_requirement_types_text(obj) return CapellaWorkItem( @@ -165,7 +165,7 @@ def _format(texts: list[str]) -> dict[str, str]: def _sanitize_description( - descr: markupsafe.Markup, ctx: dict[str, t.Any] + obj: common.GenericElement, descr: markupsafe.Markup, ctx: dict[str, t.Any] ) -> tuple[list[str], markupsafe.Markup]: referenced_uuids: list[str] = [] replaced_markup = RE_DESCR_LINK_PATTERN.sub( @@ -187,7 +187,11 @@ def repair_images(node: etree._Element) -> None: b64_img = base64.b64encode(img.read()).decode("utf8") node.attrib["src"] = f"data:{mime_type};base64,{b64_img}" except FileNotFoundError: - logger.error("Inline image can't be found from %r", file_path) + logger.error( + "Inline image can't be found from %r for %r", + file_path, + obj._short_repr_(), + ) repaired_markup = chelpers.process_html_fragments( replaced_markup, repair_images @@ -254,7 +258,7 @@ def get_linked_text( ) -> markupsafe.Markup: """Return sanitized markup of the given ``obj`` linked text.""" description = obj.specification["capella:linkedText"].striptags() - uuids, value = _sanitize_description(description, ctx) + uuids, value = _sanitize_description(obj, description, ctx) if uuids: ctx.setdefault("DESCR_REFERENCES", {})[obj.uuid] = uuids return value @@ -265,9 +269,8 @@ def constraint( ) -> CapellaWorkItem: """Return attributes for a ``Constraint``.""" work_item = _generic_work_item(obj, ctx) - work_item.description = ( # pylint: disable=attribute-defined-outside-init - get_linked_text(obj, ctx) - ) + # pylint: disable-next=attribute-defined-outside-init + work_item.description = get_linked_text(obj, ctx) return work_item @@ -285,9 +288,8 @@ def component_or_actor( xtype = RE_CAMEL_CASE_2ND_WORD_PATTERN.sub( r"\1Actor", type(obj).__name__ ) - work_item.type = helpers.resolve_element_type( # pylint: disable=attribute-defined-outside-init - xtype - ) + # pylint: disable-next=attribute-defined-outside-init + work_item.type = helpers.resolve_element_type(xtype) return work_item @@ -298,7 +300,8 @@ def physical_component( work_item = component_or_actor(obj, ctx) xtype = work_item.type if obj.nature is not None: - work_item.type = f"{xtype}{obj.nature.name.capitalize()}" # pylint: disable=attribute-defined-outside-init + # pylint: disable-next=attribute-defined-outside-init + work_item.type = f"{xtype}{obj.nature.name.capitalize()}" return work_item