@@ -93,7 +93,7 @@ def get_argparser():
93
93
94
94
argparser .add_argument (
95
95
"--json-logs" ,
96
- default = False ,
96
+ default = None ,
97
97
action = "store_true" ,
98
98
help = "Emit JSON logs instead of human readable logs" ,
99
99
)
@@ -108,7 +108,7 @@ def get_argparser():
108
108
109
109
argparser .add_argument (
110
110
"--image-name" ,
111
- help = ( "Name of image to be built. If unspecified will be " " autogenerated") ,
111
+ help = "Name of image to be built. If unspecified will be autogenerated" ,
112
112
type = validate_image_name ,
113
113
)
114
114
@@ -126,9 +126,7 @@ def get_argparser():
126
126
"--no-build" ,
127
127
dest = "build" ,
128
128
action = "store_false" ,
129
- help = (
130
- "Do not actually build the image. Useful in conjunction " "with --debug."
131
- ),
129
+ help = "Do not actually build the image. Useful in conjunction with --debug." ,
132
130
)
133
131
134
132
argparser .add_argument (
@@ -164,13 +162,15 @@ def get_argparser():
164
162
"--publish-all" ,
165
163
"-P" ,
166
164
dest = "all_ports" ,
165
+ default = None ,
167
166
action = "store_true" ,
168
167
help = "Publish all exposed ports to random host ports." ,
169
168
)
170
169
171
170
argparser .add_argument (
172
171
"--no-clean" ,
173
172
dest = "clean" ,
173
+ default = None ,
174
174
action = "store_false" ,
175
175
help = "Don't clean up remote checkouts after we are done" ,
176
176
)
@@ -250,6 +250,7 @@ def get_argparser():
250
250
return argparser
251
251
252
252
253
+ # Note: only used by sphinx-autoprogram
253
254
argparser = get_argparser ()
254
255
255
256
@@ -274,12 +275,18 @@ def make_r2d(argv=None):
274
275
args , traitlet_args = argparser .parse_known_args (argv )
275
276
276
277
r2d = Repo2Docker ()
277
- r2d .parse_command_line (traitlet_args )
278
278
279
279
if args .debug :
280
280
r2d .log_level = logging .DEBUG
281
281
282
+ # load CLI after config file, for correct priority
282
283
r2d .load_config_file (args .config )
284
+ r2d .parse_command_line (traitlet_args )
285
+
286
+ if args .debug :
287
+ # re-apply debug in case log_level was also set via config
288
+ r2d .log_level = logging .DEBUG
289
+
283
290
if args .appendix :
284
291
r2d .appendix = args .appendix
285
292
@@ -317,7 +324,8 @@ def make_r2d(argv=None):
317
324
# we will pick a name after fetching the repository
318
325
r2d .output_image_spec = ""
319
326
320
- r2d .json_logs = args .json_logs
327
+ if args .json_logs is not None :
328
+ r2d .json_logs = args .json_logs
321
329
322
330
r2d .dry_run = not args .build
323
331
@@ -341,29 +349,33 @@ def make_r2d(argv=None):
341
349
src , dest = v .split (":" )
342
350
r2d .volumes [src ] = dest
343
351
344
- r2d .run_cmd = args .cmd
352
+ if args .cmd :
353
+ r2d .run_cmd = args .cmd
345
354
346
355
if args .all_ports and not r2d .run :
347
- print (
348
- "To publish user defined port mappings, the container must " "also be run"
349
- )
356
+ print ("To publish user-defined port mappings, the container must also be run" )
350
357
sys .exit (1 )
351
358
352
359
if args .ports and not r2d .run :
353
- print (
354
- "To publish user defined port mappings, the container must " "also be run"
355
- )
360
+ print ("To publish user-defined port mappings, the container must also be run" )
356
361
sys .exit (1 )
357
362
358
363
if args .ports and len (args .ports ) > 1 and not r2d .run_cmd :
359
364
print (
360
- "To publish user defined port mapping, user must specify "
361
- "the command to run in the container"
365
+ "To publish user- defined port mapping, "
366
+ "you must specify the command to run in the container"
362
367
)
363
368
sys .exit (1 )
364
369
365
- r2d .ports = validate_and_generate_port_mapping (args .ports )
366
- r2d .all_ports = args .all_ports
370
+ if args .ports :
371
+ # override or update, if also defined in config file?
372
+ if r2d .ports :
373
+ r2d .log .warning (
374
+ f"Ignoring port configuration from config (ports={ r2d .ports } ), overridden by CLI"
375
+ )
376
+ r2d .ports = validate_and_generate_port_mapping (args .ports )
377
+ if args .all_ports is not None :
378
+ r2d .all_ports = args .all_ports
367
379
368
380
if args .user_id :
369
381
r2d .user_id = args .user_id
@@ -401,13 +413,15 @@ def make_r2d(argv=None):
401
413
if args .engine :
402
414
r2d .engine = args .engine
403
415
404
- r2d .environment = args .environment
416
+ if args .environment :
417
+ # extend any environment config from a config file
418
+ r2d .environment .extend (args .environment )
405
419
406
420
# if the source exists locally we don't want to delete it at the end
407
421
# FIXME: Find a better way to figure out if repo is 'local'. Push this into ContentProvider?
408
422
if os .path .exists (args .repo ):
409
423
r2d .cleanup_checkout = False
410
- else :
424
+ elif args . clean is not None :
411
425
r2d .cleanup_checkout = args .clean
412
426
413
427
if args .target_repo_dir :
0 commit comments