@codesys/mcp-toolkit 1.1.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/scripts/create_pou.py +46 -3
- package/package.json +1 -1
- package/src/scripts/create_pou.py +46 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.1.8] - 2025-05-06
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Enhanced create_pou script to automatically find the Application object when only "Application" is specified as the parent path
|
|
12
|
+
- Added better error messages with suggestions when Application isn't found
|
|
13
|
+
|
|
8
14
|
## [1.1.7] - 2025-05-06
|
|
9
15
|
|
|
10
16
|
### Fixed
|
|
@@ -35,9 +35,52 @@ try:
|
|
|
35
35
|
pou_type_enum = pou_type_map.get(POU_TYPE_STR)
|
|
36
36
|
if not pou_type_enum: raise ValueError("Invalid POU type string: %s. Use Program, FunctionBlock, or Function." % POU_TYPE_STR)
|
|
37
37
|
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
# For common case where user just specified "Application", automatically try to find it
|
|
39
|
+
if PARENT_PATH_REL == "Application":
|
|
40
|
+
# Get project name from file path to build the likely full path
|
|
41
|
+
project_name = os.path.splitext(os.path.basename(PROJECT_FILE_PATH))[0]
|
|
42
|
+
potential_paths = [
|
|
43
|
+
PARENT_PATH_REL, # Original "Application"
|
|
44
|
+
f"{project_name}.{PARENT_PATH_REL}", # "projectName.Application"
|
|
45
|
+
f"{project_name}/{PARENT_PATH_REL}", # "projectName/Application"
|
|
46
|
+
f"{project_name}" # Just the project name itself might work
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
print(f"DEBUG: Parent path is simply 'Application', trying several variants to find it")
|
|
50
|
+
|
|
51
|
+
# Try each potential path until one works
|
|
52
|
+
parent_object = None
|
|
53
|
+
for path in potential_paths:
|
|
54
|
+
print(f"DEBUG: Attempting to find parent with path: '{path}'")
|
|
55
|
+
parent_candidate = find_object_by_path_robust(primary_project, path, "parent container")
|
|
56
|
+
if parent_candidate:
|
|
57
|
+
parent_object = parent_candidate
|
|
58
|
+
print(f"DEBUG: Successfully found parent using path: '{path}'")
|
|
59
|
+
break
|
|
60
|
+
|
|
61
|
+
if not parent_object:
|
|
62
|
+
# For diagnostics, try to get the application object directly as a fallback
|
|
63
|
+
print("DEBUG: All path attempts failed. Trying to access application directly...")
|
|
64
|
+
try:
|
|
65
|
+
if hasattr(primary_project, 'active_application'):
|
|
66
|
+
app = primary_project.active_application
|
|
67
|
+
if app:
|
|
68
|
+
parent_object = app
|
|
69
|
+
print(f"DEBUG: Found application object directly: {app.get_name()}")
|
|
70
|
+
if not parent_object and hasattr(primary_project, 'find'):
|
|
71
|
+
apps = primary_project.find("Application", True)
|
|
72
|
+
if apps:
|
|
73
|
+
parent_object = apps[0]
|
|
74
|
+
print(f"DEBUG: Found application via search: {parent_object.get_name()}")
|
|
75
|
+
except Exception as e:
|
|
76
|
+
print(f"ERROR: Direct application access also failed: {e}")
|
|
77
|
+
else:
|
|
78
|
+
# Use the provided path normally
|
|
79
|
+
parent_object = find_object_by_path_robust(primary_project, PARENT_PATH_REL, "parent container")
|
|
80
|
+
|
|
81
|
+
# Final check if parent was found
|
|
82
|
+
if not parent_object:
|
|
83
|
+
raise ValueError("Parent object not found for path: %s. Try using the full path like 'ProjectName.Application' or run get_project_structure first to see the correct structure." % PARENT_PATH_REL)
|
|
41
84
|
|
|
42
85
|
parent_name = getattr(parent_object, 'get_name', lambda: str(parent_object))()
|
|
43
86
|
print("DEBUG: Using parent object: %s (Type: %s)" % (parent_name, type(parent_object).__name__))
|
package/package.json
CHANGED
|
@@ -35,9 +35,52 @@ try:
|
|
|
35
35
|
pou_type_enum = pou_type_map.get(POU_TYPE_STR)
|
|
36
36
|
if not pou_type_enum: raise ValueError("Invalid POU type string: %s. Use Program, FunctionBlock, or Function." % POU_TYPE_STR)
|
|
37
37
|
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
# For common case where user just specified "Application", automatically try to find it
|
|
39
|
+
if PARENT_PATH_REL == "Application":
|
|
40
|
+
# Get project name from file path to build the likely full path
|
|
41
|
+
project_name = os.path.splitext(os.path.basename(PROJECT_FILE_PATH))[0]
|
|
42
|
+
potential_paths = [
|
|
43
|
+
PARENT_PATH_REL, # Original "Application"
|
|
44
|
+
f"{project_name}.{PARENT_PATH_REL}", # "projectName.Application"
|
|
45
|
+
f"{project_name}/{PARENT_PATH_REL}", # "projectName/Application"
|
|
46
|
+
f"{project_name}" # Just the project name itself might work
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
print(f"DEBUG: Parent path is simply 'Application', trying several variants to find it")
|
|
50
|
+
|
|
51
|
+
# Try each potential path until one works
|
|
52
|
+
parent_object = None
|
|
53
|
+
for path in potential_paths:
|
|
54
|
+
print(f"DEBUG: Attempting to find parent with path: '{path}'")
|
|
55
|
+
parent_candidate = find_object_by_path_robust(primary_project, path, "parent container")
|
|
56
|
+
if parent_candidate:
|
|
57
|
+
parent_object = parent_candidate
|
|
58
|
+
print(f"DEBUG: Successfully found parent using path: '{path}'")
|
|
59
|
+
break
|
|
60
|
+
|
|
61
|
+
if not parent_object:
|
|
62
|
+
# For diagnostics, try to get the application object directly as a fallback
|
|
63
|
+
print("DEBUG: All path attempts failed. Trying to access application directly...")
|
|
64
|
+
try:
|
|
65
|
+
if hasattr(primary_project, 'active_application'):
|
|
66
|
+
app = primary_project.active_application
|
|
67
|
+
if app:
|
|
68
|
+
parent_object = app
|
|
69
|
+
print(f"DEBUG: Found application object directly: {app.get_name()}")
|
|
70
|
+
if not parent_object and hasattr(primary_project, 'find'):
|
|
71
|
+
apps = primary_project.find("Application", True)
|
|
72
|
+
if apps:
|
|
73
|
+
parent_object = apps[0]
|
|
74
|
+
print(f"DEBUG: Found application via search: {parent_object.get_name()}")
|
|
75
|
+
except Exception as e:
|
|
76
|
+
print(f"ERROR: Direct application access also failed: {e}")
|
|
77
|
+
else:
|
|
78
|
+
# Use the provided path normally
|
|
79
|
+
parent_object = find_object_by_path_robust(primary_project, PARENT_PATH_REL, "parent container")
|
|
80
|
+
|
|
81
|
+
# Final check if parent was found
|
|
82
|
+
if not parent_object:
|
|
83
|
+
raise ValueError("Parent object not found for path: %s. Try using the full path like 'ProjectName.Application' or run get_project_structure first to see the correct structure." % PARENT_PATH_REL)
|
|
41
84
|
|
|
42
85
|
parent_name = getattr(parent_object, 'get_name', lambda: str(parent_object))()
|
|
43
86
|
print("DEBUG: Using parent object: %s (Type: %s)" % (parent_name, type(parent_object).__name__))
|