Skip to content

Commit

Permalink
merge: Merge branch 'main' into improve-link-creation-logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Sep 6, 2024
2 parents a06c63f + 64b8c0f commit b88231c
Show file tree
Hide file tree
Showing 31 changed files with 1,476 additions and 499 deletions.
16 changes: 12 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default_install_hook_types: [commit-msg, pre-commit]
default_stages: [commit, merge-commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -26,7 +26,7 @@ repos:
- id: fix-byte-order-marker
- id: trailing-whitespace
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
Expand All @@ -47,12 +47,20 @@ repos:
additional_dependencies:
- pydocstyle[toml]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
- bidict
- cairosvg
- capellambse==0.5.69
- click
- jinja2
- polarion-rest-api-client==1.1.2
- pydantic
- types-requests
- types-PyYAML
exclude: tests
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
Expand Down Expand Up @@ -97,7 +105,7 @@ repos:
- --comment-style
- "..| |"
- repo: https://github.com/fsfe/reuse-tool
rev: v3.0.1
rev: v4.0.3
hooks:
- id: reuse
- repo: https://github.com/qoomon/git-conventional-commits
Expand Down
12 changes: 5 additions & 7 deletions capella2polarion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,15 @@ def render_documents(
renderer = document_renderer.DocumentRenderer(
polarion_worker.polarion_data_repo,
capella_to_polarion_cli.capella_model,
capella_to_polarion_cli.polarion_params.project_id,
overwrite_numbering,
overwrite_layouts,
)

new_documents, updated_documents, work_items = renderer.render_documents(
configs, documents
)

polarion_worker.post_documents(new_documents)
polarion_worker.update_documents(updated_documents)
polarion_worker.update_work_items(work_items)
projects_document_data = renderer.render_documents(configs, documents)
for project, project_data in projects_document_data.items():
polarion_worker.create_documents(project_data.new_docs, project)
polarion_worker.update_documents(project_data.updated_docs, project)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions capella2polarion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def setup_logger(self) -> None:
)
logging.getLogger("httpx").setLevel("WARNING")
logging.getLogger("httpcore").setLevel("WARNING")
logging.getLogger("capellambse").setLevel("WARNING")
logging.getLogger("capellambse_context_diagrams").setLevel("WARNING")

def load_synchronize_config(
self,
Expand Down
43 changes: 30 additions & 13 deletions capella2polarion/connectors/polarion_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import collections.abc as cabc

import bidict
import polarion_rest_api_client as polarion_api

from capella2polarion import data_models

Expand All @@ -27,11 +28,13 @@ def __init__(
):
if polarion_work_items is None:
polarion_work_items = []

check_work_items(polarion_work_items)
self._id_mapping = bidict.bidict(
{
work_item.uuid_capella: work_item.id
for work_item in polarion_work_items
},
}, # type: ignore[arg-type]
)
self._id_mapping.on_dup = bidict.OnDup(
key=bidict.DROP_OLD, val=bidict.DROP_OLD
Expand All @@ -49,12 +52,6 @@ def __sizeof__(self) -> int:
"""Return the amount of registered Capella UUIDs."""
return len(self._id_mapping)

def __getitem__(
self, item: str
) -> tuple[str, data_models.CapellaWorkItem]:
"""Return the polarion ID and work_item for a given Capella UUID."""
return self._id_mapping[item], self._work_items[item]

def __iter__(self) -> cabc.Iterator[str]:
"""Iterate all Capella UUIDs."""
return self._id_mapping.__iter__()
Expand Down Expand Up @@ -88,22 +85,20 @@ def get_work_item_by_polarion_id(
self.get_capella_uuid(work_item_id) # type: ignore
)

def update_work_items(
self,
work_items: list[data_models.CapellaWorkItem],
):
def update_work_items(self, work_items: list[data_models.CapellaWorkItem]):
"""Update all mappings for the given Work Items."""
for work_item in work_items:
assert work_item.id is not None
if uuid_capella := self._id_mapping.inverse.get(work_item.id):
del self._id_mapping[uuid_capella]
del self._work_items[uuid_capella]

check_work_items(work_items)
self._id_mapping.update(
{
work_item.uuid_capella: work_item.id
for work_item in work_items
if work_item.id is not None
}
} # type: ignore[arg-type]
)
self._work_items.update(
{work_item.uuid_capella: work_item for work_item in work_items}
Expand All @@ -114,3 +109,25 @@ def remove_work_items_by_capella_uuid(self, uuids: cabc.Iterable[str]):
for uuid in uuids:
del self._work_items[uuid]
del self._id_mapping[uuid]


DocumentRepository = dict[
tuple[str | None, str, str],
tuple[polarion_api.Document | None, list[polarion_api.WorkItem]],
]
"""A dict providing a mapping for documents and their text workitems.
It has (project, space, name) of the document as key and (document,
workitems) as value. The project can be None and the None value means
that the document is in the same project as the model sync work items.
"""


def check_work_items(work_items: cabc.Iterable[data_models.CapellaWorkItem]):
"""Raise a ``ValueError`` if any work item has no ID."""
if work_item_without_id := next(
(wi for wi in work_items if wi.id is None), None
):
raise ValueError(
f"Found Work Item without ID: {work_item_without_id.title!r}"
)
Loading

0 comments on commit b88231c

Please sign in to comment.