Skip to content

Commit

Permalink
ci: Please pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
ewuerger committed Mar 22, 2024
1 parent 7cf1c16 commit d47117c
Show file tree
Hide file tree
Showing 56 changed files with 293 additions and 16,487 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ cython_debug/
node_modules/

# Mac stuff
.DS_Store
.DS_Store
22 changes: 17 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ 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
hooks:
- id: mypy
additional_dependencies:
- types-pyyaml==6.0.11
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
Expand All @@ -62,7 +64,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 @@ -72,7 +74,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 @@ -82,7 +84,7 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- '/*| *| */'
- "/*| *| */"
- id: insert-license
name: Insert license headers (reST comments)
files: '\.rst$'
Expand All @@ -92,7 +94,17 @@ repos:
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- '..| |'
- "..| |"
- id: insert-license
name: Insert license headers (shell-style comments)
files: '(?:^|/)(?:.*\.(?:jsx)|Dockerfile|Makefile)$'
exclude: '(?:^|/)\..+|^docs/Makefile$'
args:
- --detect-license-in-X-top-lines=15
- --license-filepath
- LICENSES/.license_header.txt
- --comment-style
- "//"
- repo: https://github.com/fsfe/reuse-tool
rev: v3.0.1
hooks:
Expand Down
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

# Build frontend
FROM node:20 as build-frontend
WORKDIR /app
Expand Down Expand Up @@ -34,4 +40,4 @@ COPY --from=build-frontend /app/dist/ ./frontend/dist/
EXPOSE 8000

# Start the application
CMD ["python", "-m", "capella_model_explorer.backend", "/model", "/views"]
CMD ["python", "-m", "capella_model_explorer.backend", "/model", "/views"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
![image](https://github.com/DSD-DBS/capella-model-explorer/actions/workflows/build-test-publish.yml/badge.svg)
![image](https://github.com/DSD-DBS/capella-model-explorer/actions/workflows/lint.yml/badge.svg)

A webapp for exploring Capella models through simple "auto-generated" textual and graphical views.
A webapp for exploring Capella models through simple "auto-generated" textual and graphical views.

**Longer story**:

Expand Down
2 changes: 2 additions & 0 deletions capella_model_explorer/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0
28 changes: 21 additions & 7 deletions capella_model_explorer/backend/explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def __post_init__(self):
allow_headers=["*"],
)
self.env = Environment()
self.grouped_templates, self.templates = index_templates(self.templates_path)
self.grouped_templates, self.templates = index_templates(
self.templates_path
)
self.app.state.templates = templates = Jinja2Templates(
directory=PATH_TO_FRONTEND
)
Expand All @@ -59,7 +61,9 @@ def configure_routes(self):
@self.app.get("/api/views")
def read_templates():
# list all templates in the templates folder from .yaml
self.grouped_templates, self.templates = index_templates(self.templates_path)
self.grouped_templates, self.templates = index_templates(
self.templates_path
)
return self.grouped_templates

@self.app.get("/api/objects/{uuid}")
Expand Down Expand Up @@ -100,20 +104,28 @@ def render_template(template_name: str, object_id: str):
encoding="utf8"
)
except Exception as e:
error_message = f"<p style='color:red'>Template not found: {str(e)}</p>"
error_message = (
f"<p style='color:red'>Template not found: {str(e)}</p>"
)
return HTMLResponse(content=error_message)
try:
object = self.model.by_uuid(object_id)
except Exception as e:
error_message = f"<p style='color:red'>Requested object not found: {str(e)}</p>"
error_message = (
"<p style='color:red'>Requested object "
f"not found: {str(e)}</p>"
)
return HTMLResponse(content=error_message)
try:
# render the template with the object
template = self.env.from_string(content)
rendered = template.render(object=object)
return HTMLResponse(content=rendered, status_code=200)
except TemplateSyntaxError as e:
error_message = f"<p style='color:red'>Template syntax error: {e.message}, line {e.lineno}</p>"
error_message = (
"<p style='color:red'>Template syntax error: "
f"{e.message}, line {e.lineno}</p>"
)
return HTMLResponse(content=error_message)
except Exception as e:
error_message = (
Expand All @@ -130,7 +142,7 @@ def model_info():
hash=info.rev_hash,
capella_version=info.capella_version,
branch=info.branch,
badge=self.model.description_badge
badge=self.model.description_badge,
)

@self.app.get("/{rest_of_path:path}")
Expand All @@ -140,7 +152,9 @@ async def catch_all(request: Request, rest_of_path: str):
)


def index_templates(path: pathlib.Path) -> dict[str, t.Any]:
def index_templates(
path: pathlib.Path,
) -> tuple[dict[str, t.Any], dict[str, t.Any]]:
templates_grouped: dict[str, t.Any] = {"other": []}
templates: dict[str, t.Any] = {}
for template_file in path.glob("*.yaml"):
Expand Down
3 changes: 3 additions & 0 deletions frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

module.exports = {
root: true,
env: { browser: true, es2020: true },
Expand Down
6 changes: 6 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

# Logs
logs
*.log
Expand All @@ -22,3 +25,6 @@ dist-ssr
*.njsproj
*.sln
*.sw?

# Package
package-lock.json
3 changes: 3 additions & 0 deletions frontend/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

/** @type { import('@storybook/react-vite').StorybookConfig } */
const config = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
Expand Down
3 changes: 3 additions & 0 deletions frontend/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright DB InfraGO AG and contributors
// SPDX-License-Identifier: Apache-2.0

import '../src/index.css'

/** @type { import('@storybook/react').Preview } */
Expand Down
5 changes: 5 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
~ Copyright DB InfraGO AG and contributors
~ SPDX-License-Identifier: Apache-2.0
-->

# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Expand Down
5 changes: 5 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
~ Copyright DB InfraGO AG and contributors
~ SPDX-License-Identifier: Apache-2.0
-->

<!doctype html>
<html lang="en">
<head>
Expand Down
Loading

0 comments on commit d47117c

Please sign in to comment.