bluecore-airflow-common 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Blue Core
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: bluecore-airflow-common
3
+ Version: 0.1.0
4
+ Summary: Shared helpers, base templates and styles for Blue Core Airflow plugins
5
+ Author: Jeremy Nelson
6
+ Author-email: Jeremy Nelson <jpnelson@stanford.edu>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Dist: apache-airflow>=3.2,<4
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+
13
+ # bluecore-airflow-common
14
+
15
+ Shared helpers, base template and styles for Blue Core Airflow 3 plugins.
16
+
17
+ ## Install
18
+
19
+ ```sh
20
+ uv add "bluecore-airflow-common @ git+https://github.com/blue-core-lod/bluecore-airflow-common"
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```python
26
+ from fastapi import Depends, FastAPI, Request
27
+
28
+ import bluecore_airflow_common as common
29
+
30
+ URL_PREFIX = "/my-plugin"
31
+
32
+ app = FastAPI()
33
+ common.mount_static(app, "static")
34
+ templates = common.templates("templates")
35
+
36
+
37
+ @app.get("/", dependencies=[Depends(common.requires_login)])
38
+ def index(request: Request):
39
+ return templates.TemplateResponse(
40
+ request, "index.html", common.context(URL_PREFIX, title="My Plugin")
41
+ )
42
+ ```
43
+
44
+ Plugin pages extend the shared base template:
45
+
46
+ ```html
47
+ {% extends "bluecore/base.html" %}
48
+ {% block content %}<h1>{{ title }}</h1>{% endblock %}
49
+ ```
50
+
51
+ Shared assets are served at `{url_prefix}/static/bluecore/`, and a plugin's
52
+ own files at `{url_prefix}/static/`. In tests, switch off authentication with
53
+ `app.dependency_overrides[common.requires_login] = lambda: None`.
54
+
55
+ ## Development
56
+
57
+ ```sh
58
+ uv run ruff format && uv run ruff check
59
+ uv run mypy src tests
60
+ uv run pytest
61
+ ```
@@ -0,0 +1,49 @@
1
+ # bluecore-airflow-common
2
+
3
+ Shared helpers, base template and styles for Blue Core Airflow 3 plugins.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ uv add "bluecore-airflow-common @ git+https://github.com/blue-core-lod/bluecore-airflow-common"
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```python
14
+ from fastapi import Depends, FastAPI, Request
15
+
16
+ import bluecore_airflow_common as common
17
+
18
+ URL_PREFIX = "/my-plugin"
19
+
20
+ app = FastAPI()
21
+ common.mount_static(app, "static")
22
+ templates = common.templates("templates")
23
+
24
+
25
+ @app.get("/", dependencies=[Depends(common.requires_login)])
26
+ def index(request: Request):
27
+ return templates.TemplateResponse(
28
+ request, "index.html", common.context(URL_PREFIX, title="My Plugin")
29
+ )
30
+ ```
31
+
32
+ Plugin pages extend the shared base template:
33
+
34
+ ```html
35
+ {% extends "bluecore/base.html" %}
36
+ {% block content %}<h1>{{ title }}</h1>{% endblock %}
37
+ ```
38
+
39
+ Shared assets are served at `{url_prefix}/static/bluecore/`, and a plugin's
40
+ own files at `{url_prefix}/static/`. In tests, switch off authentication with
41
+ `app.dependency_overrides[common.requires_login] = lambda: None`.
42
+
43
+ ## Development
44
+
45
+ ```sh
46
+ uv run ruff format && uv run ruff check
47
+ uv run mypy src tests
48
+ uv run pytest
49
+ ```
@@ -0,0 +1,24 @@
1
+ [project]
2
+ name = "bluecore-airflow-common"
3
+ version = "0.1.0"
4
+ description = "Shared helpers, base templates and styles for Blue Core Airflow plugins"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ requires-python = ">=3.12"
9
+ dependencies = ["apache-airflow>=3.2,<4"]
10
+
11
+ [[project.authors]]
12
+ name = "Jeremy Nelson"
13
+ email = "jpnelson@stanford.edu"
14
+
15
+ [build-system]
16
+ requires = ["uv_build>=0.13.4,<0.14.0"]
17
+ build-backend = "uv_build"
18
+
19
+ [dependency-groups]
20
+ dev = [
21
+ "mypy>=1.16.1",
22
+ "pytest>=8.3.4",
23
+ "ruff>=0.9.7",
24
+ ]
@@ -0,0 +1,25 @@
1
+ [project]
2
+ name = "bluecore-airflow-common"
3
+ version = "0.1.0"
4
+ description = "Shared helpers, base templates and styles for Blue Core Airflow plugins"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Jeremy Nelson", email = "jpnelson@stanford.edu" }
8
+ ]
9
+ license = "MIT"
10
+ license-files = ["LICENSE"]
11
+ requires-python = ">=3.12"
12
+ dependencies = [
13
+ "apache-airflow>=3.2,<4"
14
+ ]
15
+
16
+ [build-system]
17
+ requires = ["uv_build>=0.13.4,<0.14.0"]
18
+ build-backend = "uv_build"
19
+
20
+ [dependency-groups]
21
+ dev = [
22
+ "mypy>=1.16.1",
23
+ "pytest>=8.3.4",
24
+ "ruff>=0.9.7",
25
+ ]
@@ -0,0 +1,110 @@
1
+ """Shared support for Blue Core Airflow plugins.
2
+
3
+ Airflow gives each plugin its own FastAPI app mounted at its own ``url_prefix``,
4
+ so there is no single origin the plugins can hang assets off. Every plugin
5
+ therefore serves this package's ``static`` directory under its own prefix, at
6
+ ``{url_prefix}/static/bluecore/``, next to its own ``{url_prefix}/static/``.
7
+
8
+ Templates are shared through the Jinja search path: a plugin's own templates
9
+ are searched first, then this package's. The common ones live under
10
+ ``bluecore/`` so a plugin's own ``base.html`` can't shadow them by accident::
11
+
12
+ {% extends "bluecore/base.html" %}
13
+ {% block content %}...{% endblock %}
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import functools
19
+ import os
20
+ import pathlib
21
+ from typing import Any
22
+ from urllib.parse import urlsplit
23
+
24
+ from airflow.api_fastapi.core_api.security import requires_authenticated
25
+ from airflow.configuration import conf
26
+ from fastapi import FastAPI
27
+ from fastapi.staticfiles import StaticFiles
28
+ from fastapi.templating import Jinja2Templates
29
+
30
+ __all__ = [
31
+ "airflow_root_path",
32
+ "context",
33
+ "mount_static",
34
+ "requires_login",
35
+ "static_url",
36
+ "templates",
37
+ ]
38
+
39
+ PACKAGE_DIR = pathlib.Path(__file__).parent
40
+ STATIC_DIR = PACKAGE_DIR / "static"
41
+ TEMPLATES_DIR = PACKAGE_DIR / "templates"
42
+
43
+ STATIC_ROUTE = "/static"
44
+ COMMON_STATIC_ROUTE = f"{STATIC_ROUTE}/bluecore"
45
+
46
+ # Authentication is delegated to Airflow: the iframe request carries Airflow's
47
+ # JWT cookie, which this resolves through the configured auth manager (Keycloak
48
+ # in a deployed Blue Core stack). It has to stay one module-level object, since
49
+ # tests switch it off with app.dependency_overrides[requires_login].
50
+ requires_login = requires_authenticated()
51
+
52
+
53
+ def airflow_root_path() -> str:
54
+ """Return the path Airflow is served under, without a trailing slash.
55
+
56
+ Airflow is at the root in local development, but the bluecore-stack proxies
57
+ it under ``/workflows``, so links into a plugin have to be prefixed with
58
+ whatever ``[api] base_url`` says.
59
+ """
60
+ return urlsplit(conf.get("api", "base_url", fallback="") or "/").path.rstrip("/")
61
+
62
+
63
+ def templates(
64
+ plugin_templates_dir: str | os.PathLike[str] | None = None,
65
+ ) -> Jinja2Templates:
66
+ """Return a template renderer that searches the plugin's templates first.
67
+
68
+ Falls back to this package's templates, so a plugin page can extend
69
+ ``bluecore/base.html`` without carrying its own copy.
70
+ """
71
+ directories: list[pathlib.Path] = [TEMPLATES_DIR]
72
+ if plugin_templates_dir is not None:
73
+ directories.insert(0, pathlib.Path(plugin_templates_dir))
74
+ return Jinja2Templates(directory=directories)
75
+
76
+
77
+ def mount_static(
78
+ app: FastAPI, plugin_static_dir: str | os.PathLike[str] | None = None
79
+ ) -> None:
80
+ """Serve the common static files, and optionally the plugin's own.
81
+
82
+ Left unauthenticated: these are decorative assets that the browser requests
83
+ as plain images and stylesheets.
84
+ """
85
+ # Starlette tries mounts in order and a "/static" mount would also claim
86
+ # "/static/bluecore/...", so the common directory has to be mounted first.
87
+ app.mount(
88
+ COMMON_STATIC_ROUTE, StaticFiles(directory=STATIC_DIR), name="bluecore_static"
89
+ )
90
+ if plugin_static_dir is not None:
91
+ app.mount(STATIC_ROUTE, StaticFiles(directory=plugin_static_dir), name="static")
92
+
93
+
94
+ def static_url(url_prefix: str, filename: str) -> str:
95
+ """Return the URL a browser should use to fetch a static file.
96
+
97
+ Common files are addressed as ``bluecore/<name>``; anything else comes from
98
+ the plugin's own static directory.
99
+ """
100
+ return f"{airflow_root_path()}{url_prefix}{STATIC_ROUTE}/{filename}"
101
+
102
+
103
+ def context(url_prefix: str, **extra: Any) -> dict[str, Any]:
104
+ """Build a template context, adding what every plugin page needs.
105
+
106
+ Templates get a ``static_url`` function rather than a fixed path, so they
107
+ keep working for pages nested under a plugin's prefix, where a relative URL
108
+ would resolve against the wrong directory.
109
+ """
110
+ return {"static_url": functools.partial(static_url, url_prefix), **extra}
@@ -0,0 +1,90 @@
1
+ /*
2
+ * Shared styles for Blue Core Airflow plugin pages.
3
+ *
4
+ * These pages render in an iframe, which is a separate document, so none of
5
+ * Airflow's own styling cascades in and there is no stylesheet to link either:
6
+ * Airflow ships a single JS bundle that injects its Chakra styles at runtime.
7
+ * The look is matched by hand instead --- a transparent canvas so Airflow's own
8
+ * background shows through in either color mode, Airflow's font stack, and a
9
+ * text color that follows the light/dark mode that bluecore.js picks up.
10
+ */
11
+
12
+ :root {
13
+ color-scheme: light;
14
+ --bluecore-fg: #24242b;
15
+ --bluecore-fg-muted: #5f6672;
16
+ }
17
+
18
+ @media (prefers-color-scheme: dark) {
19
+ :root {
20
+ color-scheme: dark;
21
+ --bluecore-fg: #ededf0;
22
+ --bluecore-fg-muted: #9ba2af;
23
+ }
24
+ }
25
+
26
+ /* Set by bluecore.js from Airflow's own toggle, so it has to win over the
27
+ media query above, which only knows the operating system preference. */
28
+ :root[data-theme="light"] {
29
+ color-scheme: light;
30
+ --bluecore-fg: #24242b;
31
+ --bluecore-fg-muted: #5f6672;
32
+ }
33
+
34
+ :root[data-theme="dark"] {
35
+ color-scheme: dark;
36
+ --bluecore-fg: #ededf0;
37
+ --bluecore-fg-muted: #9ba2af;
38
+ }
39
+
40
+ html,
41
+ body {
42
+ height: 100%;
43
+ /* Let Airflow's background show through rather than guessing its color. */
44
+ background: transparent;
45
+ }
46
+
47
+ body {
48
+ box-sizing: border-box;
49
+ margin: 0;
50
+ padding: 2rem;
51
+ color: var(--bluecore-fg);
52
+ /* Airflow's own body font stack. */
53
+ font-family:
54
+ Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
55
+ "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
56
+ "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
57
+ line-height: 1.5;
58
+ -webkit-font-smoothing: antialiased;
59
+ }
60
+
61
+ h1 {
62
+ font-weight: 600;
63
+ margin: 0;
64
+ }
65
+
66
+ p {
67
+ margin: 0;
68
+ }
69
+
70
+ /*
71
+ * For placeholder pages that are nothing but a short message. A page with real
72
+ * content should leave this off and lay itself out from the top instead.
73
+ */
74
+ body.centered {
75
+ display: flex;
76
+ flex-direction: column;
77
+ align-items: center;
78
+ justify-content: center;
79
+ gap: 1rem;
80
+ text-align: center;
81
+ }
82
+
83
+ body.centered h1 {
84
+ font-size: 2.5rem;
85
+ }
86
+
87
+ body.centered p {
88
+ font-size: 1.5rem;
89
+ color: var(--bluecore-fg-muted);
90
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Follow Airflow's light/dark mode.
3
+ *
4
+ * Plugin pages render in an iframe that Airflow sandboxes with
5
+ * "allow-same-origin", and they are served by the same API server as the UI, so
6
+ * this can read the parent document. Airflow tracks its color mode with
7
+ * next-themes, which resolves it to a data-theme attribute on <html>. Copying
8
+ * that onto our own <html> lets bluecore.css react to it.
9
+ *
10
+ * Without this the page falls back to the prefers-color-scheme media query,
11
+ * which only knows the operating system preference and so disagrees with
12
+ * Airflow whenever someone uses its toggle.
13
+ */
14
+ (function () {
15
+ "use strict";
16
+
17
+ var parentRoot;
18
+ try {
19
+ parentRoot = window.parent.document.documentElement;
20
+ } catch (error) {
21
+ return;
22
+ }
23
+
24
+ if (!parentRoot || parentRoot === document.documentElement) {
25
+ return;
26
+ }
27
+
28
+ function sync() {
29
+ var theme = parentRoot.getAttribute("data-theme");
30
+ if (theme) {
31
+ document.documentElement.setAttribute("data-theme", theme);
32
+ }
33
+ }
34
+
35
+ sync();
36
+ new MutationObserver(sync).observe(parentRoot, {
37
+ attributeFilter: ["data-theme"],
38
+ });
39
+ })();
@@ -0,0 +1,23 @@
1
+ {#
2
+ Template shared by every Blue Core plugin page. A plugin template extends
3
+ this and fills in the content block:
4
+
5
+ {% extends "bluecore/base.html" %}
6
+ {% block content %}...{% endblock %}
7
+
8
+ `static_url` comes from bluecore_airflow_common.context.
9
+ #}
10
+ <!doctype html>
11
+ <html lang="en">
12
+ <head>
13
+ <meta charset="utf-8" />
14
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
15
+ <title>{{ title }}</title>
16
+ <link rel="stylesheet" href="{{ static_url('bluecore/bluecore.css') }}" />
17
+ <script src="{{ static_url('bluecore/bluecore.js') }}"></script>
18
+ {% block head %}{% endblock %}
19
+ </head>
20
+ <body class="{% block body_class %}{% endblock %}">
21
+ {% block content %}{% endblock %}
22
+ </body>
23
+ </html>