chore(extensions): simplify backend package structure by removing superset_extensions namespace (#38476)

This commit is contained in:
Michael S. Molina
2026-03-06 14:49:49 -03:00
committed by GitHub
parent 5fb9e17721
commit a6c0d6321f
12 changed files with 70 additions and 169 deletions

View File

@@ -133,14 +133,7 @@ def extension_setup_for_bundling():
(frontend_dir / "main.js").write_text("// main js")
# Create some backend files - updated path structure
backend_dir = (
dist_dir
/ "backend"
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_extension"
)
backend_dir = dist_dir / "backend" / "src" / "test_org" / "test_extension"
backend_dir.mkdir(parents=True)
(backend_dir / "__init__.py").write_text("# init")

View File

@@ -56,13 +56,7 @@ def extension_with_build_structure():
backend_dir.mkdir()
# Create conventional backend structure
backend_src_dir = (
backend_dir
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_extension"
)
backend_src_dir = backend_dir / "src" / "test_org" / "test_extension"
backend_src_dir.mkdir(parents=True)
# Create conventional entry point file
@@ -70,10 +64,7 @@ def extension_with_build_structure():
(backend_src_dir / "__init__.py").write_text("")
# Create parent __init__.py files for namespace packages
(backend_dir / "src" / "superset_extensions" / "__init__.py").write_text("")
(
backend_dir / "src" / "superset_extensions" / "test_org" / "__init__.py"
).write_text("")
(backend_dir / "src" / "test_org" / "__init__.py").write_text("")
# Create pyproject.toml matching the template structure
pyproject_content = """[project]
@@ -84,7 +75,7 @@ license = "Apache-2.0"
[tool.apache_superset_extensions.build]
# Files to include in the extension build/bundle
include = [
"src/superset_extensions/test_org/test_extension/**/*.py",
"src/test_org/test_extension/**/*.py",
]
exclude = []
"""
@@ -133,11 +124,7 @@ def test_build_command_success_flow(
"project": {"name": "test"},
"tool": {
"apache_superset_extensions": {
"build": {
"include": [
"src/superset_extensions/test_org/test_extension/**/*.py"
]
}
"build": {"include": ["src/test_org/test_extension/**/*.py"]}
}
},
}
@@ -178,11 +165,7 @@ def test_build_command_handles_frontend_build_failure(
"project": {"name": "test"},
"tool": {
"apache_superset_extensions": {
"build": {
"include": [
"src/superset_extensions/test_org/test_extension/**/*.py"
]
}
"build": {"include": ["src/test_org/test_extension/**/*.py"]}
}
},
}
@@ -322,10 +305,7 @@ def test_build_manifest_creates_correct_manifest_structure(
# Verify backend section and conventional entrypoint
assert manifest.backend is not None
assert (
manifest.backend.entrypoint
== "superset_extensions.test_org.test_extension.entrypoint"
)
assert manifest.backend.entrypoint == "test_org.test_extension.entrypoint"
@pytest.mark.unit
@@ -477,7 +457,7 @@ def test_copy_backend_files_skips_non_files(isolated_filesystem):
"""Test copy_backend_files skips directories and non-files."""
# Create backend structure with directory
backend_dir = isolated_filesystem / "backend"
backend_src = backend_dir / "src" / "superset_extensions" / "test_org" / "test_ext"
backend_src = backend_dir / "src" / "test_org" / "test_ext"
backend_src.mkdir(parents=True)
(backend_src / "__init__.py").write_text("# init")
@@ -493,7 +473,7 @@ license = "Apache-2.0"
[tool.apache_superset_extensions.build]
include = [
"src/superset_extensions/test_org/test_ext/**/*",
"src/test_org/test_ext/**/*",
]
exclude = []
"""
@@ -517,25 +497,11 @@ exclude = []
# Verify only files were copied, not directories
dist_dir = isolated_filesystem / "dist"
assert_file_exists(
dist_dir
/ "backend"
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_ext"
/ "__init__.py"
dist_dir / "backend" / "src" / "test_org" / "test_ext" / "__init__.py"
)
# Directory should not be copied as a file
copied_subdir = (
dist_dir
/ "backend"
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_ext"
/ "subdir"
)
copied_subdir = dist_dir / "backend" / "src" / "test_org" / "test_ext" / "subdir"
# The directory might exist but should be empty since we skip non-files
if copied_subdir.exists():
assert list(copied_subdir.iterdir()) == []
@@ -546,7 +512,7 @@ def test_copy_backend_files_copies_matched_files(isolated_filesystem):
"""Test copy_backend_files copies files matching patterns from pyproject.toml."""
# Create backend source files
backend_dir = isolated_filesystem / "backend"
backend_src = backend_dir / "src" / "superset_extensions" / "test_org" / "test_ext"
backend_src = backend_dir / "src" / "test_org" / "test_ext"
backend_src.mkdir(parents=True)
(backend_src / "__init__.py").write_text("# init")
(backend_src / "main.py").write_text("# main")
@@ -559,7 +525,7 @@ license = "Apache-2.0"
[tool.apache_superset_extensions.build]
include = [
"src/superset_extensions/test_org/test_ext/**/*.py",
"src/test_org/test_ext/**/*.py",
]
exclude = []
"""
@@ -583,22 +549,10 @@ exclude = []
# Verify files were copied
dist_dir = isolated_filesystem / "dist"
assert_file_exists(
dist_dir
/ "backend"
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_ext"
/ "__init__.py"
dist_dir / "backend" / "src" / "test_org" / "test_ext" / "__init__.py"
)
assert_file_exists(
dist_dir
/ "backend"
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_ext"
/ "main.py"
dist_dir / "backend" / "src" / "test_org" / "test_ext" / "main.py"
)
@@ -607,7 +561,7 @@ def test_copy_backend_files_handles_various_glob_patterns(isolated_filesystem):
"""Test copy_backend_files correctly handles different glob pattern formats."""
# Create backend structure with files in different locations
backend_dir = isolated_filesystem / "backend"
backend_src = backend_dir / "src" / "superset_extensions" / "test_org" / "test_ext"
backend_src = backend_dir / "src" / "test_org" / "test_ext"
backend_src.mkdir(parents=True)
# Create files that should match different pattern types
@@ -628,9 +582,9 @@ license = "Apache-2.0"
[tool.apache_superset_extensions.build]
include = [
"config.py", # No '/' - would break old logic
"**/*.py", # Starts with '**' - would break old logic
"src/superset_extensions/test_org/test_ext/main.py", # Specific file
"config.py", # No '/' - would break old logic
"**/*.py", # Starts with '**' - would break old logic
"src/test_org/test_ext/main.py", # Specific file
]
exclude = []
"""
@@ -659,34 +613,15 @@ exclude = []
# All .py files should be included (pattern: "**/*.py")
assert_file_exists(
dist_dir
/ "backend"
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_ext"
/ "__init__.py"
dist_dir / "backend" / "src" / "test_org" / "test_ext" / "__init__.py"
)
assert_file_exists(
dist_dir
/ "backend"
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_ext"
/ "utils"
/ "helper.py"
dist_dir / "backend" / "src" / "test_org" / "test_ext" / "utils" / "helper.py"
)
# Specific file (pattern: "src/superset_extensions/test_org/test_ext/main.py")
# Specific file (pattern: "src/test_org/test_ext/main.py")
assert_file_exists(
dist_dir
/ "backend"
/ "src"
/ "superset_extensions"
/ "test_org"
/ "test_ext"
/ "main.py"
dist_dir / "backend" / "src" / "test_org" / "test_ext" / "main.py"
)

View File

@@ -55,10 +55,7 @@ def test_bundle_command_creates_zip_with_default_name(
assert "manifest.json" in file_list
assert "frontend/dist/remoteEntry.abc123.js" in file_list
assert "frontend/dist/main.js" in file_list
assert (
"backend/src/superset_extensions/test_org/test_extension/__init__.py"
in file_list
)
assert "backend/src/test_org/test_extension/__init__.py" in file_list
@pytest.mark.cli

View File

@@ -376,13 +376,10 @@ def test_generate_extension_names_complete_flow(
assert (
names["backend_package"] == f"{publisher.replace('-', '_')}-{expected_snake}"
) # Collision-safe
assert (
names["backend_path"]
== f"superset_extensions.{publisher.replace('-', '_')}.{expected_snake}"
)
assert names["backend_path"] == f"{publisher.replace('-', '_')}.{expected_snake}"
assert (
names["backend_entry"]
== f"superset_extensions.{publisher.replace('-', '_')}.{expected_snake}.entrypoint"
== f"{publisher.replace('-', '_')}.{expected_snake}.entrypoint"
)
@@ -476,8 +473,8 @@ def test_manual_technical_name_override():
assert names["id"] == "acme.chart-builder" # Composite ID
assert names["mf_name"] == "acme_chartBuilder" # Module Federation format
assert names["backend_package"] == "acme-chart_builder" # Collision-safe
assert names["backend_path"] == "superset_extensions.acme.chart_builder"
assert names["backend_entry"] == "superset_extensions.acme.chart_builder.entrypoint"
assert names["backend_path"] == "acme.chart_builder"
assert names["backend_entry"] == "acme.chart_builder.entrypoint"
def test_generate_names_uses_suggested_technical_names():

View File

@@ -49,8 +49,8 @@ def template_context():
"npm_name": "@test-org/test-extension",
"mf_name": "testOrg_testExtension",
"backend_package": "test_org-test_extension",
"backend_path": "superset_extensions.test_org.test_extension",
"backend_entry": "superset_extensions.test_org.test_extension.entrypoint",
"backend_path": "test_org.test_extension",
"backend_entry": "test_org.test_extension.entrypoint",
"version": "0.1.0",
"license": "Apache-2.0",
"include_frontend": True,
@@ -197,8 +197,8 @@ def test_template_rendering_with_different_ids(
"npm_name": f"@{publisher}/{technical_name}",
"mf_name": get_module_federation_name(publisher, technical_name),
"backend_package": f"{publisher_snake}-{name_snake}",
"backend_path": f"superset_extensions.{publisher_snake}.{name_snake}",
"backend_entry": f"superset_extensions.{publisher_snake}.{name_snake}.entrypoint",
"backend_path": f"{publisher_snake}.{name_snake}",
"backend_entry": f"{publisher_snake}.{name_snake}.entrypoint",
"version": "1.0.0",
"license": "MIT",
"include_frontend": True,
@@ -274,8 +274,8 @@ def test_template_rendering_with_different_licenses(jinja_env, license_type):
"npm_name": "@test-pub/test-ext",
"mf_name": "testPub_testExt",
"backend_package": "test_pub-test_ext",
"backend_path": "superset_extensions.test_pub.test_ext",
"backend_entry": "superset_extensions.test_pub.test_ext.entrypoint",
"backend_path": "test_pub.test_ext",
"backend_entry": "test_pub.test_ext.entrypoint",
"version": "1.0.0",
"license": license_type,
"include_frontend": True,
@@ -347,8 +347,8 @@ def test_template_context_edge_cases(jinja_env):
"npm_name": "@min/minimal",
"mf_name": "min_minimal",
"backend_package": "min-minimal",
"backend_path": "superset_extensions.min.minimal",
"backend_entry": "superset_extensions.min.minimal.entrypoint",
"backend_path": "min.minimal",
"backend_entry": "min.minimal.entrypoint",
"version": "1.0.0",
"license": "MIT",
"include_frontend": False,