Skip to content

Commit bc80deb

Browse files
[IMP] Support debugging modules from nested doodba subprojects in VSCode
1 parent e7b6e73 commit bc80deb

File tree

1 file changed

+75
-35
lines changed

1 file changed

+75
-35
lines changed

tasks_downstream.py

+75-35
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,70 @@ def _get_cwd_addon(file):
106106
return None
107107

108108

109+
def _scan_subrepos_and_add_path_mappings(
110+
cw_config,
111+
debugpy_configuration,
112+
firefox_configuration,
113+
chrome_configuration,
114+
):
115+
"""Scan subrepos in SRC_PATH, configure folders & pathMappings."""
116+
for subrepo in SRC_PATH.glob("*"):
117+
if not subrepo.is_dir():
118+
continue
119+
if (subrepo / ".git").exists() and subrepo.name != "odoo":
120+
cw_config["folders"].append(
121+
{"path": str(subrepo.relative_to(PROJECT_ROOT))}
122+
)
123+
124+
# Check if subrepo is itself a doodba-copier project
125+
is_doodba_subproject = False
126+
answers_file = subrepo / ".copier-answers.yml"
127+
if answers_file.is_file():
128+
with answers_file.open() as f:
129+
answers = yaml.safe_load(f) or {}
130+
if "Tecnativa/doodba-copier-template" in answers.get("_src_path", ""):
131+
is_doodba_subproject = True
132+
133+
private_dir = subrepo / "odoo" / "custom" / "src" / "private"
134+
# Default scanning approach (1-level + addons/* + private/*)
135+
for addon in chain(
136+
subrepo.glob("*"),
137+
subrepo.glob("addons/*"),
138+
private_dir.glob("*"),
139+
):
140+
if (addon / "__manifest__.py").is_file() or (
141+
addon / "__openerp__.py"
142+
).is_file():
143+
if is_doodba_subproject:
144+
local_path = "${workspaceFolder:%s}/odoo/custom/src/private/%s" % ( # noqa: UP031
145+
subrepo.name,
146+
addon.name,
147+
)
148+
elif subrepo.name == "odoo":
149+
local_path = "${workspaceFolder:%s}/addons/%s/" % ( # noqa: UP031
150+
subrepo.name,
151+
addon.name,
152+
)
153+
else:
154+
local_path = "${workspaceFolder:%s}/%s" % ( # noqa: UP031
155+
subrepo.name,
156+
addon.name,
157+
)
158+
debugpy_configuration["pathMappings"].append(
159+
{
160+
"localRoot": local_path,
161+
"remoteRoot": f"/opt/odoo/auto/addons/{addon.name}/",
162+
}
163+
)
164+
url = f"http://localhost:{ODOO_VERSION:.0f}069/{addon.name}/static/"
165+
path = "${workspaceFolder:%s}/%s/static/" % ( # noqa: UP031
166+
subrepo.name,
167+
addon.relative_to(subrepo),
168+
)
169+
firefox_configuration["pathMappings"].append({"url": url, "path": path})
170+
chrome_configuration["pathMapping"][url] = path
171+
172+
109173
@task
110174
def write_code_workspace_file(c, cw_path=None):
111175
"""Generate code-workspace file definition.
@@ -126,7 +190,7 @@ def write_code_workspace_file(c, cw_path=None):
126190
Example: `--cw-path doodba.my-custom-name.code-workspace`
127191
"""
128192
root_name = f"doodba.{PROJECT_ROOT.name}"
129-
root_var = "${workspaceFolder:%s}" % root_name
193+
root_var = "${workspaceFolder:%s}" % root_name # noqa: UP031
130194
if not cw_path:
131195
try:
132196
cw_path = next(PROJECT_ROOT.glob("doodba.*.code-workspace"))
@@ -202,6 +266,7 @@ def write_code_workspace_file(c, cw_path=None):
202266
}
203267
if chrome_executable:
204268
chrome_configuration["runtimeExecutable"] = chrome_executable
269+
205270
cw_config["launch"] = {
206271
"compounds": [
207272
{
@@ -222,46 +287,21 @@ def write_code_workspace_file(c, cw_path=None):
222287
chrome_configuration,
223288
],
224289
}
225-
# Configure folders and debuggers
290+
# Configure pathMappings for the main odoo folder
226291
debugpy_configuration["pathMappings"].append(
227292
{
228293
"localRoot": "${workspaceFolder:odoo}/",
229294
"remoteRoot": "/opt/odoo/custom/src/odoo",
230295
}
231296
)
232297
cw_config["folders"] = []
233-
for subrepo in SRC_PATH.glob("*"):
234-
if not subrepo.is_dir():
235-
continue
236-
if (subrepo / ".git").exists() and subrepo.name != "odoo":
237-
cw_config["folders"].append(
238-
{"path": str(subrepo.relative_to(PROJECT_ROOT))}
239-
)
240-
for addon in chain(subrepo.glob("*"), subrepo.glob("addons/*")):
241-
if (addon / "__manifest__.py").is_file() or (
242-
addon / "__openerp__.py"
243-
).is_file():
244-
if subrepo.name == "odoo":
245-
# ruff: noqa: UP031
246-
local_path = "${workspaceFolder:%s}/addons/%s/" % (
247-
subrepo.name,
248-
addon.name,
249-
)
250-
else:
251-
local_path = "${workspaceFolder:%s}/%s" % (subrepo.name, addon.name)
252-
debugpy_configuration["pathMappings"].append(
253-
{
254-
"localRoot": local_path,
255-
"remoteRoot": f"/opt/odoo/auto/addons/{addon.name}/",
256-
}
257-
)
258-
url = f"http://localhost:{ODOO_VERSION:.0f}069/{addon.name}/static/"
259-
path = "${workspaceFolder:%s}/%s/static/" % (
260-
subrepo.name,
261-
addon.relative_to(subrepo),
262-
)
263-
firefox_configuration["pathMappings"].append({"url": url, "path": path})
264-
chrome_configuration["pathMapping"][url] = path
298+
_scan_subrepos_and_add_path_mappings(
299+
cw_config,
300+
debugpy_configuration,
301+
firefox_configuration,
302+
chrome_configuration,
303+
)
304+
265305
cw_config["tasks"] = {
266306
"version": "2.0.0",
267307
"tasks": [
@@ -1038,7 +1078,7 @@ def restore_snapshot(
10381078
snapshot_name = max(db_list, key=lambda x: x[1])[0]
10391079
if not snapshot_name:
10401080
raise exceptions.PlatformError(
1041-
"No snapshot found for destination_db %s" % destination_db
1081+
"No snapshot found for destination_db %s" % destination_db # noqa: UP031
10421082
)
10431083
_logger.info("Restoring snapshot %s to %s", (snapshot_name, destination_db))
10441084
_run = f"{DOCKER_COMPOSE_CMD} run --rm -l traefik.enable=false odoo"

0 commit comments

Comments
 (0)