mirror of
https://github.com/apache/superset.git
synced 2026-04-26 19:44:58 +00:00
refactor: Enable G logging rules and comprehensive ruff improvements (#35081)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
e1a2e4843a
commit
088ecdd0bf
@@ -40,7 +40,9 @@ def discover_and_load_extensions(
|
||||
LoadedExtension instances for each valid .supx file found
|
||||
"""
|
||||
if not extensions_path or not os.path.exists(extensions_path):
|
||||
logger.warning(f"Extensions path does not exist or is empty: {extensions_path}")
|
||||
logger.warning(
|
||||
"Extensions path does not exist or is empty: %s", extensions_path
|
||||
)
|
||||
return
|
||||
|
||||
extensions_dir = Path(extensions_path)
|
||||
@@ -50,7 +52,8 @@ def discover_and_load_extensions(
|
||||
for supx_file in extensions_dir.glob("*.supx"):
|
||||
if not is_zipfile(supx_file):
|
||||
logger.warning(
|
||||
f"File has .supx extension but is not a valid zip file: {supx_file}"
|
||||
"File has .supx extension but is not a valid zip file: %s",
|
||||
supx_file,
|
||||
)
|
||||
continue
|
||||
|
||||
@@ -59,11 +62,13 @@ def discover_and_load_extensions(
|
||||
files = get_bundle_files_from_zip(zip_file)
|
||||
extension = get_loaded_extension(files)
|
||||
extension_id = extension.manifest["id"]
|
||||
logger.info(f"Loaded extension '{extension_id}' from {supx_file}")
|
||||
logger.info(
|
||||
"Loaded extension '%s' from %s", extension_id, supx_file
|
||||
)
|
||||
yield extension
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to load extension from {supx_file}: {e}")
|
||||
logger.error("Failed to load extension from %s: %s", supx_file, e)
|
||||
continue
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error discovering extensions in {extensions_path}: {e}")
|
||||
logger.error("Error discovering extensions in %s: %s", extensions_path, e)
|
||||
|
||||
@@ -40,11 +40,11 @@ class LocalExtensionFileHandler(FileSystemEventHandler):
|
||||
if event.is_directory:
|
||||
return
|
||||
|
||||
logger.info(f"File change detected in LOCAL_EXTENSIONS: {event.src_path}")
|
||||
logger.info("File change detected in LOCAL_EXTENSIONS: %s", event.src_path)
|
||||
|
||||
# Touch superset/__init__.py to trigger Flask's file watcher
|
||||
superset_init = Path("superset/__init__.py")
|
||||
logger.info(f"Triggering restart by touching {superset_init}")
|
||||
logger.info("Triggering restart by touching %s", superset_init)
|
||||
os.utime(superset_init, (time.time(), time.time()))
|
||||
|
||||
|
||||
@@ -70,12 +70,12 @@ def setup_local_extensions_watcher(app: Flask) -> None: # noqa: C901
|
||||
|
||||
ext_path = Path(ext_path).resolve()
|
||||
if not ext_path.exists():
|
||||
logger.warning(f"LOCAL_EXTENSIONS path does not exist: {ext_path}")
|
||||
logger.warning("LOCAL_EXTENSIONS path does not exist: %s", ext_path)
|
||||
continue
|
||||
|
||||
dist_path = ext_path / "dist"
|
||||
watch_dirs.append(str(dist_path))
|
||||
logger.info(f"Watching LOCAL_EXTENSIONS dist directory: {dist_path}")
|
||||
logger.info("Watching LOCAL_EXTENSIONS dist directory: %s", dist_path)
|
||||
|
||||
if not watch_dirs:
|
||||
return
|
||||
@@ -89,18 +89,19 @@ def setup_local_extensions_watcher(app: Flask) -> None: # noqa: C901
|
||||
try:
|
||||
observer.schedule(event_handler, watch_dir, recursive=True)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to watch directory {watch_dir}: {e}")
|
||||
logger.warning("Failed to watch directory %s: %s", watch_dir, e)
|
||||
continue
|
||||
|
||||
observer.daemon = True
|
||||
observer.start()
|
||||
|
||||
logger.info(
|
||||
f"LOCAL_EXTENSIONS file watcher started for {len(watch_dirs)} directories" # noqa: E501
|
||||
"LOCAL_EXTENSIONS file watcher started for %s directories", # noqa: E501
|
||||
len(watch_dirs),
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to start LOCAL_EXTENSIONS file watcher: {e}")
|
||||
logger.error("Failed to start LOCAL_EXTENSIONS file watcher: %s", e)
|
||||
|
||||
|
||||
def start_local_extensions_watcher_thread(app: Flask) -> None:
|
||||
|
||||
@@ -109,7 +109,7 @@ def get_bundle_files_from_path(base_path: str) -> Generator[BundleFile, None, No
|
||||
dist_path = os.path.join(base_path, "dist")
|
||||
|
||||
if not os.path.isdir(dist_path):
|
||||
raise Exception(f"Expected directory {dist_path} does not exist.")
|
||||
raise Exception("Expected directory %s does not exist." % dist_path)
|
||||
|
||||
for root, _, files in os.walk(dist_path):
|
||||
for file in files:
|
||||
@@ -137,7 +137,7 @@ def get_loaded_extension(files: Iterable[BundleFile]) -> LoadedExtension:
|
||||
if "name" not in manifest:
|
||||
raise Exception("Missing 'name' in manifest")
|
||||
except Exception as e:
|
||||
raise Exception(f"Invalid manifest.json: {e}") from e
|
||||
raise Exception("Invalid manifest.json: %s" % e) from e
|
||||
|
||||
elif (match := FRONTEND_REGEX.match(filename)) is not None:
|
||||
frontend[match.group(1)] = content
|
||||
@@ -146,7 +146,7 @@ def get_loaded_extension(files: Iterable[BundleFile]) -> LoadedExtension:
|
||||
backend[match.group(1)] = content
|
||||
|
||||
else:
|
||||
raise Exception(f"Unexpected file in bundle: {filename}")
|
||||
raise Exception("Unexpected file in bundle: %s" % filename)
|
||||
|
||||
id_ = manifest["id"]
|
||||
name = manifest["name"]
|
||||
@@ -176,7 +176,8 @@ def build_extension_data(extension: LoadedExtension) -> dict[str, Any]:
|
||||
remote_entry = frontend["remoteEntry"]
|
||||
extension_data.update(
|
||||
{
|
||||
"remoteEntry": f"/api/v1/extensions/{manifest['id']}/{remote_entry}", # noqa: E501
|
||||
"remoteEntry": "/api/v1/extensions/%s/%s"
|
||||
% (manifest["id"], remote_entry), # noqa: E501
|
||||
"exposedModules": module_federation.get("exposes", []),
|
||||
"contributions": frontend.get("contributions", {}),
|
||||
}
|
||||
@@ -194,8 +195,9 @@ def get_extensions() -> dict[str, LoadedExtension]:
|
||||
extension_id = extension.manifest["id"]
|
||||
extensions[extension_id] = extension
|
||||
logger.info(
|
||||
f"Loading extension {extension.name} (ID: {extension_id}) "
|
||||
"from local filesystem"
|
||||
"Loading extension %s (ID: %s) from local filesystem",
|
||||
extension.name,
|
||||
extension_id,
|
||||
)
|
||||
|
||||
# Load extensions from discovery path (.supx files)
|
||||
@@ -207,13 +209,16 @@ def get_extensions() -> dict[str, LoadedExtension]:
|
||||
if extension_id not in extensions: # Don't override LOCAL_EXTENSIONS
|
||||
extensions[extension_id] = extension
|
||||
logger.info(
|
||||
f"Loading extension {extension.name} (ID: {extension_id}) "
|
||||
"from discovery path"
|
||||
"Loading extension %s (ID: %s) from discovery path",
|
||||
extension.name,
|
||||
extension_id,
|
||||
)
|
||||
else:
|
||||
logger.info(
|
||||
f"Extension {extension.name} (ID: {extension_id}) already "
|
||||
"loaded from LOCAL_EXTENSIONS, skipping discovery version"
|
||||
"Extension %s (ID: %s) already loaded from LOCAL_EXTENSIONS, "
|
||||
"skipping discovery version",
|
||||
extension.name,
|
||||
extension_id,
|
||||
)
|
||||
|
||||
return extensions
|
||||
|
||||
Reference in New Issue
Block a user