Skip to content

Commit

Permalink
Merge branch 'master' into templates-update
Browse files Browse the repository at this point in the history
  • Loading branch information
vik378 committed Sep 19, 2024
2 parents e08dd96 + bc0601a commit 013325d
Show file tree
Hide file tree
Showing 37 changed files with 14,885 additions and 239 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ jobs:
matrix:
os: [ubuntu-latest]
python_version:
- "3.10"
- "3.11"
- "3.12"
include:
- os: windows-latest
python_version: "3.10"
python_version: "3.11"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{matrix.python_version}}
Expand Down Expand Up @@ -56,7 +55,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: |-
python -m pip install -U pip
Expand All @@ -68,10 +67,10 @@ jobs:
run: |-
python -m twine check dist/*
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Artifacts
path: 'dist/*'
path: "dist/*"
- name: Publish to PyPI (release only)
if: startsWith(github.ref, 'refs/tags/v')
run: python -m twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }} --non-interactive dist/*
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.10"
python-version: "3.11"
- name: Upgrade pip
run: |-
python -m pip install -U pip
Expand Down
62 changes: 32 additions & 30 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.1.0
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
Expand All @@ -43,24 +43,24 @@ repos:
rev: 6.3.0
hooks:
- id: pydocstyle
exclude: "^tests/"
exclude: '^tests/'
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:
- capellambse==0.5.70
- capellambse==0.5.72
- types-pyyaml==6.0.11
- repo: https://github.com/pylint-dev/pylint
rev: v3.1.0
rev: v3.2.7
hooks:
- id: pylint
require_serial: false
args: [-rn, -sn, -dfixme, -dduplicate-code]
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
rev: v1.5.5
hooks:
- id: insert-license
name: Insert license headers (shell-style comments)
Expand All @@ -71,7 +71,7 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- "#"
- '#'
- id: insert-license
name: Insert license headers (XML-style comments)
files: '\.(?:html|md|xml)$'
Expand All @@ -81,7 +81,7 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- "<!--| ~| -->"
- '<!--| ~| -->'
- id: insert-license
name: Insert license headers (C-style comments)
files: '\.(?:css|js|ts)$'
Expand All @@ -91,7 +91,7 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- "/*| *| */"
- '/*| *| */'
- id: insert-license
name: Insert license headers (reST comments)
files: '\.rst$'
Expand All @@ -101,7 +101,7 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- "..| |"
- '..| |'
- id: insert-license
name: Insert license headers (JSX files)
files: '\.jsx$'
Expand All @@ -111,37 +111,39 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- "//"
- '//'
- repo: https://github.com/fsfe/reuse-tool
rev: v3.0.1
rev: v4.0.3
hooks:
- id: reuse
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.11.0
rev: v9.17.0
hooks:
- id: commitlint
stages: [commit-msg]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
- repo: local
hooks:
- id: prettier
name: prettier
entry: prettier --write
language: node
types_or: [ts, css, html, markdown]
additional_dependencies:
- "prettier@^3.2.5"
- "prettier-plugin-tailwindcss@^0.5.14"
- "tailwind-scrollbar@^3.1.0"
- 'prettier@^3.3.3'
- 'prettier-plugin-tailwindcss@^0.6.6'
- 'tailwind-scrollbar@^3.1.0'
- repo: https://github.com/pre-commit/mirrors-eslint
rev: v9.2.0
rev: v9.10.0
hooks:
- id: eslint
additional_dependencies:
- "eslint@^8.57.0"
- "eslint-config-prettier@^9.1.0"
- "eslint-plugin-import@^2.29.1"
- "eslint-plugin-unused-imports@^3.1.0"
- "eslint-plugin-deprecation@^2.0.0"
- "eslint-plugin-tailwindcss@^3.15.1"
- "eslint-plugin-storybook@^0.8.0"
- "eslint-plugin-react@^7.34.1"
- "eslint-plugin-react-hooks@^4.6.2"
- "eslint-plugin-react-refresh@^0.4.5"
- 'eslint@^8.57.0'
- 'eslint-config-prettier@^9.1.0'
- 'eslint-plugin-import@^2.29.1'
- 'eslint-plugin-unused-imports@^3.1.0'
- 'eslint-plugin-deprecation@^2.0.0'
- 'eslint-plugin-tailwindcss@^3.15.1'
- 'eslint-plugin-storybook@^0.8.0'
- 'eslint-plugin-react@^7.34.1'
- 'eslint-plugin-react-hooks@^4.6.2'
- 'eslint-plugin-react-refresh@^0.4.5'
11 changes: 5 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ Thanks for your interest in our project. Contributions are always welcome!
We are committed to fostering a welcoming, respectful, and harassment-free
environment. Be kind!

If you have questions, ideas or want to report a bug, feel free to [open an
issue]. Or go ahead and [open a pull request] to contribute code. In order to
reduce the burden on our maintainers, please make sure that your code follows
our style guidelines outlined below.
If you have questions, ideas or want to report a bug, feel free to [open
an issue]. Or go ahead and [open a pull request] to contribute code. In order to
reduce the burden on our maintainers, please make sure that your code follows our
style guidelines outlined below.

<!-- prettier-ignore -->
[open an issue]: https://github.com/DSD-DBS/capella-model-explorer/issues
Expand Down Expand Up @@ -129,8 +129,7 @@ The key differences are:
etc.
- For classes that are not builtin (e.g. `Iterable`),
`import collections.abc as cabc` and then use them like `cabc.Iterable`.
- Use [PEP-604-style unions], e.g. `int | float` instead of
`t.Union[int, float]`.
- Use [PEP-604-style unions], e.g. `int | float` instead of `t.Union[int, float]`.
- Use `... | None` (with `None` always as the last union member) instead of
`t.Optional[...]` and always explicitly annotate where `None` is possible.

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Navigate to `Menu` > `Settings` > `Tools` > `Add a new tool` and fill in the
following configuration:

```yaml
name: 'Capella model explorer'
name: "Capella model explorer"
integrations:
t4c: false
pure_variants: false
Expand All @@ -119,8 +119,8 @@ config:
environment:
MODEL_ENTRYPOINT:
stage: before
value: '{CAPELLACOLLAB_SESSION_PROVISIONING[0][path]}'
ROUTE_PREFIX: '{CAPELLACOLLAB_SESSIONS_BASE_PATH}'
value: "{CAPELLACOLLAB_SESSION_PROVISIONING[0][path]}"
ROUTE_PREFIX: "{CAPELLACOLLAB_SESSIONS_BASE_PATH}"
connection:
methods:
- id: f51872a8-1a4f-4a4d-b4f4-b39cbd31a75b
Expand All @@ -131,7 +131,7 @@ config:
ports:
metrics: 8000
http: 8000
redirect_url: '{CAPELLACOLLAB_SESSIONS_SCHEME}://{CAPELLACOLLAB_SESSIONS_HOST}:{CAPELLACOLLAB_SESSIONS_PORT}{CAPELLACOLLAB_SESSIONS_BASE_PATH}/'
redirect_url: "{CAPELLACOLLAB_SESSIONS_SCHEME}://{CAPELLACOLLAB_SESSIONS_HOST}:{CAPELLACOLLAB_SESSIONS_PORT}{CAPELLACOLLAB_SESSIONS_BASE_PATH}/"
monitoring:
prometheus:
path: /metrics
Expand All @@ -149,7 +149,7 @@ Since the Capella Model Explorer can load different Capella versions, we can
use one generic version:
```yaml
name: 'Generic'
name: "Generic"
config:
is_recommended: true
is_deprecated: false
Expand Down
7 changes: 6 additions & 1 deletion capella_model_explorer/backend/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@
default=PATH_TO_TEMPLATES,
)
def run(model: capellambse.MelodyModel, templates: Path):
backend = explorer.CapellaModelExplorerBackend(Path(templates), model)

backend = explorer.CapellaModelExplorerBackend(
Path(templates),
model,
)

uvicorn.run(backend.app, host=HOST, port=int(PORT))


Expand Down
75 changes: 73 additions & 2 deletions capella_model_explorer/backend/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import markupsafe
import prometheus_client
import yaml
from fastapi import APIRouter, FastAPI, Request
from fastapi import APIRouter, FastAPI, HTTPException, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
Expand All @@ -27,7 +27,9 @@
TemplateSyntaxError,
is_undefined,
)
from pydantic import BaseModel

from capella_model_explorer.backend import model_diff
from capella_model_explorer.backend import templates as tl

from . import __version__
Expand All @@ -39,6 +41,15 @@
LOGGER = logging.getLogger(__name__)


class CommitRange(BaseModel):
head: str
prev: str


class ObjectDiffID(BaseModel):
uuid: str


@dataclasses.dataclass
class CapellaModelExplorerBackend:
app: FastAPI = dataclasses.field(init=False)
Expand Down Expand Up @@ -80,6 +91,8 @@ def __post_init__(self):
self.templates_index = self.templates_loader.index_path(
self.templates_path
)
self.diff = {}
self.object_diff = {}

@self.app.middleware("http")
async def update_last_interaction_time(request: Request, call_next):
Expand Down Expand Up @@ -139,7 +152,12 @@ def render_instance_page(self, template_text, base, object=None):
try:
# render the template with the object
template = self.env.from_string(template_text)
rendered = template.render(object=object, model=self.model)
rendered = template.render(
object=object,
model=self.model,
diff_data=self.diff,
object_diff=self.object_diff,
)
return HTMLResponse(content=rendered, status_code=200)
except TemplateSyntaxError as e:
error_message = markupsafe.Markup(
Expand Down Expand Up @@ -276,6 +294,38 @@ async def catch_all(request: Request, rest_of_path: str):
async def version():
return {"version": self.app.version}

@self.app.post("/api/compare")
async def post_compare(commit_range: CommitRange):
try:
self.diff = model_diff.get_diff_data(
self.model, commit_range.head, commit_range.prev
)
self.diff["lookup"] = create_diff_lookup(self.diff["objects"])
return {"success": True}
except Exception as e:
return {"success": False, "error": str(e)}

@self.app.post("/api/object-diff")
async def post_object_diff(object_id: ObjectDiffID):
if object_id.uuid not in self.diff["lookup"]:
raise HTTPException(status_code=404, detail="Object not found")

self.object_diff = self.diff["lookup"][object_id.uuid]
return {"success": True}

@self.app.get("/api/commits")
async def get_commits():
result = model_diff.populate_commits(self.model)
return result

@self.app.get("/api/diff")
async def get_diff():
if self.diff:
return self.diff
return {
"error": "No data available. Please compare two commits first."
}


def index_template(template, templates, templates_grouped, filename=None):
idx = filename if filename else template["idx"]
Expand Down Expand Up @@ -306,3 +356,24 @@ def index_templates(
template, templates, templates_grouped, filename=idx
)
return templates_grouped, templates


def create_diff_lookup(data, lookup=None):
if lookup is None:
lookup = {}
try:
if isinstance(data, dict):
for _, obj in data.items():
if "uuid" in obj:
lookup[obj["uuid"]] = {
"uuid": obj["uuid"],
"display_name": obj["display_name"],
"change": obj["change"],
"attributes": obj["attributes"],
}
if "children" in obj:
if obj["children"]:
create_diff_lookup(obj["children"], lookup)
except Exception:
pass
return lookup
Loading

0 comments on commit 013325d

Please sign in to comment.