fix: Clean up imports and formatting in hatch_build.py and markdown_view_plugin.py
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
# hatch_build.py
|
||||
import subprocess
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||
|
||||
|
||||
class MarkdownBuildHook(BuildHookInterface):
|
||||
def initialize(self, version, build_data):
|
||||
# 1. Compile the UI exactly once per build
|
||||
@@ -15,9 +17,7 @@ class MarkdownBuildHook(BuildHookInterface):
|
||||
shutil.rmtree(dist_dir)
|
||||
|
||||
# Install dependencies and build the UI
|
||||
subprocess.run([
|
||||
"pnpm", "install", "--frozen-lockfile"
|
||||
], cwd=ui_dir, check=True)
|
||||
subprocess.run(["pnpm", "install", "--frozen-lockfile"], cwd=ui_dir, check=True)
|
||||
subprocess.run(["pnpm", "run", "build"], cwd=ui_dir, check=True)
|
||||
|
||||
# 2. Force-include the compiled assets in the wheel
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from markdown_view_plugin.markdown_view_plugin import MarkdownViewPlugin
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
# Python backend for the Markdown View Plugin using FastAPI
|
||||
|
||||
import importlib.resources as resources
|
||||
|
||||
import anyio # For asynchronous file operations
|
||||
from airflow.plugins_manager import AirflowPlugin
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from airflow.plugins_manager import AirflowPlugin
|
||||
import importlib.resources as resources
|
||||
|
||||
# Use importlib.resources to locate static files and view.md
|
||||
static_files_dir_ref = resources.files("markdown_view_plugin") / "ui" / "dist"
|
||||
@@ -27,6 +28,7 @@ with resources.as_file(static_files_dir_ref) as static_files_dir:
|
||||
name="markdown_view_plugin_static",
|
||||
)
|
||||
|
||||
|
||||
# API endpoint to get markdown content
|
||||
@markdown_fastapi_app.get("/markdown_view/api/view")
|
||||
async def get_markdown_content_api():
|
||||
@@ -41,6 +43,7 @@ async def get_markdown_content_api():
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
|
||||
# Endpoint to serve the main index.html of the React app
|
||||
@markdown_fastapi_app.get("/markdown_view")
|
||||
async def serve_markdown_ui():
|
||||
@@ -53,6 +56,7 @@ async def serve_markdown_ui():
|
||||
)
|
||||
return FileResponse(str(index_html_path))
|
||||
|
||||
|
||||
# Define the Airflow plugin
|
||||
class MarkdownViewPlugin(AirflowPlugin):
|
||||
"""
|
||||
@@ -74,11 +78,12 @@ class MarkdownViewPlugin(AirflowPlugin):
|
||||
menu_links = [
|
||||
{
|
||||
"name": "Markdown Viewer",
|
||||
"href": "/markdown_view_plugin_mount/markdown_view", # This should match the app_mount + @markdown_fastapi_app.get path for the UI
|
||||
"href": "/markdown_view_plugin_mount/markdown_view", # This should match the app_mount + @markdown_fastapi_app.get path for the UI
|
||||
"category": "Plugins",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
# For Airflow to pick up the plugin, the class name must match the filename (snake_case to PascalCase)
|
||||
# or be explicitly defined in an __init__.py in the plugin\'s root directory.
|
||||
# Assuming filename is markdown_view_plugin.py, class MarkdownViewPlugin is correct.
|
||||
|
||||
Reference in New Issue
Block a user