Address code review feedback and improve platform detection

Co-authored-by: jmiller-moko <230051081+jmiller-moko@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-01-04 21:16:47 +00:00
parent a14418e838
commit 4f88790215
3 changed files with 108 additions and 14 deletions

View File

@@ -123,7 +123,7 @@ def detect_dolibarr_manifest(src_dir: Union[str, Path]) -> Optional[Path]:
"""
src_path = Path(src_dir)
# Dolibarr module descriptors follow pattern: core/modules/modMyModule.class.php
# Dolibarr module descriptors follow pattern: core/modules/mod*.class.php
descriptor_patterns = [
"core/modules/mod*.class.php",
"*/modules/mod*.class.php",
@@ -218,8 +218,13 @@ def parse_dolibarr_descriptor(descriptor_path: Path) -> Optional[ExtensionInfo]:
try:
content = descriptor_path.read_text(encoding="utf-8")
# Extract module name from class name
# Extract module name from class name (try multiple patterns)
# Pattern 1: class ModMyModule
name_match = re.search(r'class\s+(Mod\w+)', content)
if not name_match:
# Pattern 2: class mod_mymodule (lowercase)
name_match = re.search(r'class\s+(mod_\w+)', content, re.IGNORECASE)
name = name_match.group(1) if name_match else "unknown"
# Extract version

View File

@@ -0,0 +1,98 @@
#!/usr/bin/env python3
"""
Detect extension platform and type.
Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
This file is part of a Moko Consulting project.
SPDX-License-Identifier: GPL-3.0-or-later
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program (./LICENSE.md).
FILE INFORMATION
DEFGROUP: Script.Release
INGROUP: Extension.Detection
REPO: https://github.com/mokoconsulting-tech/moko-cassiopeia
PATH: /scripts/release/detect_platform.py
VERSION: 01.00.00
BRIEF: Detect extension platform and type for build workflow
USAGE: ./scripts/release/detect_platform.py [src_dir]
"""
import argparse
import sys
from pathlib import Path
# Add lib directory to path
sys.path.insert(0, str(Path(__file__).parent.parent / "lib"))
try:
import extension_utils
except ImportError:
print("ERROR: Cannot import extension_utils library", file=sys.stderr)
sys.exit(1)
def main() -> int:
"""Main entry point."""
parser = argparse.ArgumentParser(
description="Detect extension platform and type",
formatter_class=argparse.RawDescriptionHelpFormatter
)
parser.add_argument(
"src_dir",
nargs="?",
default="src",
help="Source directory (default: src)"
)
parser.add_argument(
"--format",
choices=["pipe", "json"],
default="pipe",
help="Output format (default: pipe)"
)
args = parser.parse_args()
try:
ext_info = extension_utils.get_extension_info(args.src_dir)
if not ext_info:
print(f"ERROR: No extension detected in {args.src_dir}", file=sys.stderr)
return 1
if args.format == "pipe":
# Format: platform|ext_type
print(f"{ext_info.platform.value}|{ext_info.extension_type}")
elif args.format == "json":
import json
data = {
"platform": ext_info.platform.value,
"extension_type": ext_info.extension_type,
"name": ext_info.name,
"version": ext_info.version
}
print(json.dumps(data))
return 0
except Exception as e:
print(f"ERROR: {e}", file=sys.stderr)
return 1
if __name__ == "__main__":
sys.exit(main())