rusackas commented on code in PR #36805: URL: https://github.com/apache/superset/pull/36805#discussion_r2644064973
########## docs/scripts/generate-database-docs.mjs: ########## @@ -0,0 +1,730 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * This script generates database documentation data from the Python lib.py script. + * It outputs a JSON file that can be imported by React components for rendering. + * + * Usage: node scripts/generate-database-docs.mjs + * + * The script can run in two modes: + * 1. With Flask app (full diagnostics) - requires superset to be installed + * 2. Fallback mode (documentation only) - uses just the DATABASE_DOCS from lib.py + */ + +import { execSync, spawn } from 'child_process'; +import fs from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import yaml from 'js-yaml'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const ROOT_DIR = path.resolve(__dirname, '../..'); +const DOCS_DIR = path.resolve(__dirname, '..'); +const DATA_OUTPUT_DIR = path.join(DOCS_DIR, 'src/data'); +const DATA_OUTPUT_FILE = path.join(DATA_OUTPUT_DIR, 'databases.json'); +const MDX_OUTPUT_DIR = path.join(DOCS_DIR, 'docs/databases'); +const LIB_PY_PATH = path.join(ROOT_DIR, 'superset/db_engine_specs/lib.py'); + +/** + * Try to run the full lib.py script with Flask context + */ +function tryRunFullScript() { + try { + console.log('Attempting to run lib.py with Flask context...'); + const result = execSync( + `cd ${ROOT_DIR} && SUPERSET_SECRET_KEY='docs-build-key' python -c " +import sys +import json +sys.path.insert(0, '.') +from superset.app import create_app +from superset.db_engine_specs.lib import generate_yaml_docs +app = create_app() +with app.app_context(): + docs = generate_yaml_docs() + print(json.dumps(docs, default=str)) +"`, + { + encoding: 'utf-8', + timeout: 60000, + maxBuffer: 10 * 1024 * 1024, + } + ); + return JSON.parse(result); + } catch (error) { + console.log('Full script execution failed, using fallback mode...'); + console.log(' Reason:', error.message?.split('\n')[0] || 'Unknown error'); + return null; + } +} + +/** + * Extract DATABASE_DOCS from lib.py without running it + * This is a fallback when the full script can't run + */ +function extractDatabaseDocs() { + console.log('Extracting DATABASE_DOCS directly from lib.py...'); + + try { + const result = execSync( + `cd ${ROOT_DIR} && python3 -c " +import sys +import json +import ast + +# Read the lib.py file +with open('superset/db_engine_specs/lib.py', 'r') as f: + content = f.read() + +# Find DATABASE_DOCS assignment +tree = ast.parse(content) +database_docs = None + +for node in ast.walk(tree): + if isinstance(node, ast.Assign): + for target in node.targets: + if isinstance(target, ast.Name) and target.id == 'DATABASE_DOCS': + # Execute just the DATABASE_DOCS portion + exec(compile(ast.Expression(node.value), '<string>', 'eval')) + break + +# Re-execute to get the actual value +exec_globals = {} +exec(''' +DATABASE_DOCS = ${extractDatabaseDocsCode()} +''', exec_globals) + +print(json.dumps(exec_globals.get('DATABASE_DOCS', {}), default=str)) +"`, Review Comment: Fixed! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
