@@ -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,12 +108,13 @@ 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
115
115
argparser .add_argument (
116
116
"--ref" ,
117
+ default = None ,
117
118
help = (
118
119
"Reference to build instead of default reference. For example"
119
120
" branch name or commit for a Git repository."
@@ -126,10 +127,16 @@ def get_argparser():
126
127
"--no-build" ,
127
128
dest = "build" ,
128
129
action = "store_false" ,
129
- help = (
130
- "Do not actually build the image. Useful in conjunction " "with --debug."
131
- ),
130
+ help = "Do not actually build the image. Useful in conjunction with --debug." ,
131
+ )
132
+
133
+ argparser .add_argument (
134
+ "--build" ,
135
+ dest = "build" ,
136
+ action = "store_true" ,
137
+ help = "Build the image (default)" ,
132
138
)
139
+ argparser .set_defaults (build = None )
133
140
134
141
argparser .add_argument (
135
142
"--build-memory-limit" ,
@@ -149,6 +156,14 @@ def get_argparser():
149
156
help = "Do not run container after it has been built" ,
150
157
)
151
158
159
+ argparser .add_argument (
160
+ "--run" ,
161
+ dest = "run" ,
162
+ action = "store_true" ,
163
+ help = "Run container after it has been built (default)." ,
164
+ )
165
+ argparser .set_defaults (run = None )
166
+
152
167
argparser .add_argument (
153
168
"--publish" ,
154
169
"-p" ,
@@ -164,6 +179,7 @@ def get_argparser():
164
179
"--publish-all" ,
165
180
"-P" ,
166
181
dest = "all_ports" ,
182
+ default = None ,
167
183
action = "store_true" ,
168
184
help = "Publish all exposed ports to random host ports." ,
169
185
)
@@ -174,13 +190,27 @@ def get_argparser():
174
190
action = "store_false" ,
175
191
help = "Don't clean up remote checkouts after we are done" ,
176
192
)
193
+ argparser .add_argument (
194
+ "--clean" ,
195
+ dest = "clean" ,
196
+ action = "store_true" ,
197
+ help = "Clean up remote checkouts after we are done (default)." ,
198
+ )
199
+ argparser .set_defaults (clean = None )
177
200
178
201
argparser .add_argument (
179
202
"--push" ,
180
203
dest = "push" ,
181
204
action = "store_true" ,
182
205
help = "Push docker image to repository" ,
183
206
)
207
+ argparser .add_argument (
208
+ "--no-push" ,
209
+ dest = "push" ,
210
+ action = "store_false" ,
211
+ help = "Don't push docker image to repository (default)." ,
212
+ )
213
+ argparser .set_defaults (push = None )
184
214
185
215
argparser .add_argument (
186
216
"--volume" ,
@@ -250,6 +280,7 @@ def get_argparser():
250
280
return argparser
251
281
252
282
283
+ # Note: only used by sphinx-autoprogram
253
284
argparser = get_argparser ()
254
285
255
286
@@ -274,12 +305,18 @@ def make_r2d(argv=None):
274
305
args , traitlet_args = argparser .parse_known_args (argv )
275
306
276
307
r2d = Repo2Docker ()
277
- r2d .parse_command_line (traitlet_args )
278
308
279
309
if args .debug :
280
310
r2d .log_level = logging .DEBUG
281
311
312
+ # load CLI after config file, for correct priority
282
313
r2d .load_config_file (args .config )
314
+ r2d .parse_command_line (traitlet_args )
315
+
316
+ if args .debug :
317
+ # re-apply debug in case log_level was also set via config
318
+ r2d .log_level = logging .DEBUG
319
+
283
320
if args .appendix :
284
321
r2d .appendix = args .appendix
285
322
@@ -291,8 +328,14 @@ def make_r2d(argv=None):
291
328
key , _ , val = a .partition ("=" )
292
329
r2d .extra_build_args [key ] = val
293
330
331
+ # repo is a required arg, and should never come from config:
332
+ if "repo" in r2d .config .Repo2Docker :
333
+ r2d .log .warning (
334
+ f"Ignoring Repo2Docker.repo={ r2d .repo !r} configuration, using { args .repo !r} from CLI."
335
+ )
294
336
r2d .repo = args .repo
295
- r2d .ref = args .ref
337
+ if args .ref is not None :
338
+ r2d .ref = args .ref
296
339
297
340
# user wants to mount a local directory into the container for
298
341
# editing
@@ -313,21 +356,22 @@ def make_r2d(argv=None):
313
356
314
357
if args .image_name :
315
358
r2d .output_image_spec = args .image_name
316
- else :
317
- # we will pick a name after fetching the repository
318
- r2d .output_image_spec = ""
319
359
320
- r2d .json_logs = args .json_logs
360
+ if args .json_logs is not None :
361
+ r2d .json_logs = args .json_logs
321
362
322
- r2d .dry_run = not args .build
363
+ if args .build is not None :
364
+ r2d .dry_run = not args .build
323
365
324
366
if r2d .dry_run :
325
367
# Can't push nor run if we aren't building
326
368
args .run = False
327
369
args .push = False
328
370
329
- r2d .run = args .run
330
- r2d .push = args .push
371
+ if args .run is not None :
372
+ r2d .run = args .run
373
+ if args .push is not None :
374
+ r2d .push = args .push
331
375
332
376
# check against r2d.run and not args.run as r2d.run is false on
333
377
# --no-build. Also r2d.volumes and not args.volumes since --editable
@@ -341,29 +385,33 @@ def make_r2d(argv=None):
341
385
src , dest = v .split (":" )
342
386
r2d .volumes [src ] = dest
343
387
344
- r2d .run_cmd = args .cmd
388
+ if args .cmd :
389
+ r2d .run_cmd = args .cmd
345
390
346
391
if args .all_ports and not r2d .run :
347
- print (
348
- "To publish user defined port mappings, the container must " "also be run"
349
- )
392
+ print ("To publish user-defined port mappings, the container must also be run" )
350
393
sys .exit (1 )
351
394
352
395
if args .ports and not r2d .run :
353
- print (
354
- "To publish user defined port mappings, the container must " "also be run"
355
- )
396
+ print ("To publish user-defined port mappings, the container must also be run" )
356
397
sys .exit (1 )
357
398
358
399
if args .ports and len (args .ports ) > 1 and not r2d .run_cmd :
359
400
print (
360
- "To publish user defined port mapping, user must specify "
361
- "the command to run in the container"
401
+ "To publish user- defined port mapping, "
402
+ "you must specify the command to run in the container"
362
403
)
363
404
sys .exit (1 )
364
405
365
- r2d .ports = validate_and_generate_port_mapping (args .ports )
366
- r2d .all_ports = args .all_ports
406
+ if args .ports :
407
+ # override or update, if also defined in config file?
408
+ if r2d .ports :
409
+ r2d .log .warning (
410
+ f"Ignoring port configuration from config (ports={ r2d .ports } ), overridden by CLI"
411
+ )
412
+ r2d .ports = validate_and_generate_port_mapping (args .ports )
413
+ if args .all_ports is not None :
414
+ r2d .all_ports = args .all_ports
367
415
368
416
if args .user_id :
369
417
r2d .user_id = args .user_id
@@ -401,13 +449,11 @@ def make_r2d(argv=None):
401
449
if args .engine :
402
450
r2d .engine = args .engine
403
451
404
- r2d .environment = args .environment
452
+ if args .environment :
453
+ # extend any environment config from a config file
454
+ r2d .environment .extend (args .environment )
405
455
406
- # if the source exists locally we don't want to delete it at the end
407
- # FIXME: Find a better way to figure out if repo is 'local'. Push this into ContentProvider?
408
- if os .path .exists (args .repo ):
409
- r2d .cleanup_checkout = False
410
- else :
456
+ elif args .clean is not None :
411
457
r2d .cleanup_checkout = args .clean
412
458
413
459
if args .target_repo_dir :
0 commit comments