Skip to content

Commit

Permalink
[IMP] Support debugging modules from nested doodba subprojects in VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
josep-tecnativa committed Mar 5, 2025
1 parent e7b6e73 commit 58c8302
Showing 1 changed file with 71 additions and 24 deletions.
95 changes: 71 additions & 24 deletions tasks_downstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _get_cwd_addon(file):
return None


@task
@task # noqa: C901
def write_code_workspace_file(c, cw_path=None):
"""Generate code-workspace file definition.
Expand Down Expand Up @@ -237,31 +237,78 @@ def write_code_workspace_file(c, cw_path=None):
cw_config["folders"].append(
{"path": str(subrepo.relative_to(PROJECT_ROOT))}
)
for addon in chain(subrepo.glob("*"), subrepo.glob("addons/*")):
if (addon / "__manifest__.py").is_file() or (
addon / "__openerp__.py"
).is_file():
if subrepo.name == "odoo":
# ruff: noqa: UP031
local_path = "${workspaceFolder:%s}/addons/%s/" % (

# Check if subrepo is itself a doodba-copier project
is_doodba_subproject = False
answers_file = subrepo / ".copier-answers.yml"
if answers_file.is_file():
with answers_file.open() as f:
answers = yaml.safe_load(f) or {}
if (
answers.get("_src_path")
== "https://github.com/Tecnativa/doodba-copier-template.git"
):
is_doodba_subproject = True

if is_doodba_subproject:
# Scan odoo/custom/src/private as "repo"
private_dir = subrepo / "odoo" / "custom" / "src" / "private"
if private_dir.is_dir():
for addon in private_dir.glob("*"):
if not addon.is_dir():
continue
if (addon / "__manifest__.py").is_file() or (
addon / "__openerp__.py"
).is_file():
local_path = (
"${workspaceFolder:"
+ subrepo.name
+ "}/odoo/custom/src/private/"
+ addon.name
)
debugpy_configuration["pathMappings"].append(
{
"localRoot": local_path,
"remoteRoot": f"/opt/odoo/auto/addons/{addon.name}/",
}
)
url = f"http://localhost:{ODOO_VERSION:.0f}069/{addon.name}/static/"
path = f"{local_path}/static/"
firefox_configuration["pathMappings"].append(
{"url": url, "path": path}
)
chrome_configuration["pathMapping"][url] = path
else:
# Default scanning approach (1-level + addons/*)
for addon in chain(subrepo.glob("*"), subrepo.glob("addons/*")):
if (addon / "__manifest__.py").is_file() or (
addon / "__openerp__.py"
).is_file():
if subrepo.name == "odoo":
local_path = "${workspaceFolder:%s}/addons/%s/" % ( # noqa: UP031
subrepo.name,
addon.name,
)
else:
local_path = "${workspaceFolder:%s}/%s" % ( # noqa: UP031
subrepo.name,
addon.name,
)
debugpy_configuration["pathMappings"].append(
{
"localRoot": local_path,
"remoteRoot": f"/opt/odoo/auto/addons/{addon.name}/",
}
)
url = f"http://localhost:{ODOO_VERSION:.0f}069/{addon.name}/static/"
path = "${workspaceFolder:%s}/%s/static/" % ( # noqa: UP031
subrepo.name,
addon.name,
addon.relative_to(subrepo),
)
else:
local_path = "${workspaceFolder:%s}/%s" % (subrepo.name, addon.name)
debugpy_configuration["pathMappings"].append(
{
"localRoot": local_path,
"remoteRoot": f"/opt/odoo/auto/addons/{addon.name}/",
}
)
url = f"http://localhost:{ODOO_VERSION:.0f}069/{addon.name}/static/"
path = "${workspaceFolder:%s}/%s/static/" % (
subrepo.name,
addon.relative_to(subrepo),
)
firefox_configuration["pathMappings"].append({"url": url, "path": path})
chrome_configuration["pathMapping"][url] = path
firefox_configuration["pathMappings"].append(
{"url": url, "path": path}
)
chrome_configuration["pathMapping"][url] = path
cw_config["tasks"] = {
"version": "2.0.0",
"tasks": [
Expand Down

0 comments on commit 58c8302

Please sign in to comment.