Skip to content

Commit

Permalink
Merge branch 'main' into feat-requirement-types-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger authored Oct 26, 2023
2 parents 60b237e + 01c25cc commit ac7d58a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 23 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ 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
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.2
rev: v1.7.5
hooks:
- id: docformatter
additional_dependencies:
Expand All @@ -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:
Expand Down Expand Up @@ -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
12 changes: 8 additions & 4 deletions capella2polarion/elements/api_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions capella2polarion/elements/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
25 changes: 14 additions & 11 deletions capella2polarion/elements/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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


Expand All @@ -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


Expand Down

0 comments on commit ac7d58a

Please sign in to comment.