@@ -185,50 +185,48 @@ def compile( # pylint: disable=redefined-builtin
185
185
language_context = language_context ,
186
186
)
187
187
188
- lockfile = Locker (
188
+ with Locker (
189
189
root_namespace_name = root_namespace_name if root_namespace_name else "_support_" ,
190
190
output_directory = output_directory ,
191
- )
192
- if lockfile .create ():
193
- # Generate code
194
- assert isinstance (output_directory , pathlib .Path )
195
- code_generator = nunavut .jinja .DSDLCodeGenerator (
196
- namespace = root_ns ,
197
- generate_namespace_types = nunavut .YesNoDefault .YES ,
198
- followlinks = True ,
199
- )
200
- code_generator .generate_all ()
201
- _logger .info (
202
- "Generated %d types from the root namespace %r in %.1f seconds" ,
203
- len (composite_types ),
204
- root_namespace_name ,
205
- time .monotonic () - started_at ,
206
- )
207
-
208
- support_generator = nunavut .jinja .SupportGenerator (
209
- namespace = root_ns ,
210
- )
211
- support_generator .generate_all ()
212
-
213
- # A minor UX improvement; see https://github.com/OpenCyphal/pycyphal/issues/115
214
- for p in sys .path :
215
- if pathlib .Path (p ).resolve () == pathlib .Path (output_directory ):
216
- break
217
- else :
218
- if os .name == "nt" :
219
- quick_fix = f'Quick fix: `$env:PYTHONPATH += ";{ output_directory .resolve ()} "`'
220
- elif os .name == "posix" :
221
- quick_fix = f'Quick fix: `export PYTHONPATH="{ output_directory .resolve ()} "`'
222
- else :
223
- quick_fix = "Quick fix is not available for this OS."
191
+ ) as lockfile :
192
+ if lockfile :
193
+ # Generate code
194
+ assert isinstance (output_directory , pathlib .Path )
195
+ code_generator = nunavut .jinja .DSDLCodeGenerator (
196
+ namespace = root_ns ,
197
+ generate_namespace_types = nunavut .YesNoDefault .YES ,
198
+ followlinks = True ,
199
+ )
200
+ code_generator .generate_all ()
224
201
_logger .info (
225
- "Generated package is stored in %r, which is not in Python module search path list. "
226
- "The package will fail to import unless you add the destination directory to sys.path or PYTHONPATH. %s" ,
227
- str ( output_directory ) ,
228
- quick_fix ,
202
+ "Generated %d types from the root namespace %r in %.1f seconds" ,
203
+ len ( composite_types ) ,
204
+ root_namespace_name ,
205
+ time . monotonic () - started_at ,
229
206
)
230
207
231
- lockfile .remove ()
208
+ support_generator = nunavut .jinja .SupportGenerator (
209
+ namespace = root_ns ,
210
+ )
211
+ support_generator .generate_all ()
212
+
213
+ # A minor UX improvement; see https://github.com/OpenCyphal/pycyphal/issues/115
214
+ for p in sys .path :
215
+ if pathlib .Path (p ).resolve () == pathlib .Path (output_directory ):
216
+ break
217
+ else :
218
+ if os .name == "nt" :
219
+ quick_fix = f'Quick fix: `$env:PYTHONPATH += ";{ output_directory .resolve ()} "`'
220
+ elif os .name == "posix" :
221
+ quick_fix = f'Quick fix: `export PYTHONPATH="{ output_directory .resolve ()} "`'
222
+ else :
223
+ quick_fix = "Quick fix is not available for this OS."
224
+ _logger .info (
225
+ "Generated package is stored in %r, which is not in Python module search path list. "
226
+ "The package will fail to import unless you add the destination directory to sys.path or PYTHONPATH. %s" ,
227
+ str (output_directory ),
228
+ quick_fix ,
229
+ )
232
230
233
231
return GeneratedPackageInfo (
234
232
path = pathlib .Path (output_directory ) / pathlib .Path (root_namespace_name ),
0 commit comments