@@ -106,6 +106,70 @@ def _get_cwd_addon(file):
106
106
return None
107
107
108
108
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
+
109
173
@task
110
174
def write_code_workspace_file (c , cw_path = None ):
111
175
"""Generate code-workspace file definition.
@@ -126,7 +190,7 @@ def write_code_workspace_file(c, cw_path=None):
126
190
Example: `--cw-path doodba.my-custom-name.code-workspace`
127
191
"""
128
192
root_name = f"doodba.{ PROJECT_ROOT .name } "
129
- root_var = "${workspaceFolder:%s}" % root_name
193
+ root_var = "${workspaceFolder:%s}" % root_name # noqa: UP031
130
194
if not cw_path :
131
195
try :
132
196
cw_path = next (PROJECT_ROOT .glob ("doodba.*.code-workspace" ))
@@ -202,6 +266,7 @@ def write_code_workspace_file(c, cw_path=None):
202
266
}
203
267
if chrome_executable :
204
268
chrome_configuration ["runtimeExecutable" ] = chrome_executable
269
+
205
270
cw_config ["launch" ] = {
206
271
"compounds" : [
207
272
{
@@ -222,46 +287,21 @@ def write_code_workspace_file(c, cw_path=None):
222
287
chrome_configuration ,
223
288
],
224
289
}
225
- # Configure folders and debuggers
290
+ # Configure pathMappings for the main odoo folder
226
291
debugpy_configuration ["pathMappings" ].append (
227
292
{
228
293
"localRoot" : "${workspaceFolder:odoo}/" ,
229
294
"remoteRoot" : "/opt/odoo/custom/src/odoo" ,
230
295
}
231
296
)
232
297
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
+
265
305
cw_config ["tasks" ] = {
266
306
"version" : "2.0.0" ,
267
307
"tasks" : [
@@ -1038,7 +1078,7 @@ def restore_snapshot(
1038
1078
snapshot_name = max (db_list , key = lambda x : x [1 ])[0 ]
1039
1079
if not snapshot_name :
1040
1080
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
1042
1082
)
1043
1083
_logger .info ("Restoring snapshot %s to %s" , (snapshot_name , destination_db ))
1044
1084
_run = f"{ DOCKER_COMPOSE_CMD } run --rm -l traefik.enable=false odoo"
0 commit comments