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
|
# hatch_build.py
|
||||||
import subprocess
|
|
||||||
import pathlib
|
import pathlib
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
|
||||||
|
|
||||||
|
|
||||||
class MarkdownBuildHook(BuildHookInterface):
|
class MarkdownBuildHook(BuildHookInterface):
|
||||||
def initialize(self, version, build_data):
|
def initialize(self, version, build_data):
|
||||||
# 1. Compile the UI exactly once per build
|
# 1. Compile the UI exactly once per build
|
||||||
@@ -15,9 +17,7 @@ class MarkdownBuildHook(BuildHookInterface):
|
|||||||
shutil.rmtree(dist_dir)
|
shutil.rmtree(dist_dir)
|
||||||
|
|
||||||
# Install dependencies and build the UI
|
# Install dependencies and build the UI
|
||||||
subprocess.run([
|
subprocess.run(["pnpm", "install", "--frozen-lockfile"], cwd=ui_dir, check=True)
|
||||||
"pnpm", "install", "--frozen-lockfile"
|
|
||||||
], cwd=ui_dir, check=True)
|
|
||||||
subprocess.run(["pnpm", "run", "build"], cwd=ui_dir, check=True)
|
subprocess.run(["pnpm", "run", "build"], cwd=ui_dir, check=True)
|
||||||
|
|
||||||
# 2. Force-include the compiled assets in the wheel
|
# 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
|
# Python backend for the Markdown View Plugin using FastAPI
|
||||||
|
|
||||||
|
import importlib.resources as resources
|
||||||
|
|
||||||
import anyio # For asynchronous file operations
|
import anyio # For asynchronous file operations
|
||||||
|
from airflow.plugins_manager import AirflowPlugin
|
||||||
from fastapi import FastAPI, HTTPException
|
from fastapi import FastAPI, HTTPException
|
||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from fastapi.staticfiles import StaticFiles
|
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
|
# Use importlib.resources to locate static files and view.md
|
||||||
static_files_dir_ref = resources.files("markdown_view_plugin") / "ui" / "dist"
|
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",
|
name="markdown_view_plugin_static",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# API endpoint to get markdown content
|
# API endpoint to get markdown content
|
||||||
@markdown_fastapi_app.get("/markdown_view/api/view")
|
@markdown_fastapi_app.get("/markdown_view/api/view")
|
||||||
async def get_markdown_content_api():
|
async def get_markdown_content_api():
|
||||||
@@ -41,6 +43,7 @@ async def get_markdown_content_api():
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
# Endpoint to serve the main index.html of the React app
|
# Endpoint to serve the main index.html of the React app
|
||||||
@markdown_fastapi_app.get("/markdown_view")
|
@markdown_fastapi_app.get("/markdown_view")
|
||||||
async def serve_markdown_ui():
|
async def serve_markdown_ui():
|
||||||
@@ -53,6 +56,7 @@ async def serve_markdown_ui():
|
|||||||
)
|
)
|
||||||
return FileResponse(str(index_html_path))
|
return FileResponse(str(index_html_path))
|
||||||
|
|
||||||
|
|
||||||
# Define the Airflow plugin
|
# Define the Airflow plugin
|
||||||
class MarkdownViewPlugin(AirflowPlugin):
|
class MarkdownViewPlugin(AirflowPlugin):
|
||||||
"""
|
"""
|
||||||
@@ -79,6 +83,7 @@ class MarkdownViewPlugin(AirflowPlugin):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# For Airflow to pick up the plugin, the class name must match the filename (snake_case to PascalCase)
|
# 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.
|
# 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.
|
# Assuming filename is markdown_view_plugin.py, class MarkdownViewPlugin is correct.
|
||||||
|
|||||||
Reference in New Issue
Block a user