Merge pull request #1123 from yuvipanda/commandline-args

Allow passing in traitlets via commandline
pull/1130/head
Simon Li 2022-01-27 16:50:47 +00:00 zatwierdzone przez GitHub
commit 8c21b96401
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 29 dodań i 9 usunięć

Wyświetl plik

@ -66,6 +66,20 @@ def get_argparser():
description="Fetch a repository and build a container image"
)
argparser.add_argument(
"--help-all",
dest="help_all",
action="store_true",
help="Display all configurable options and exit.",
)
argparser.add_argument(
"--version",
dest="version",
action="store_true",
help="Print the repo2docker version and exit.",
)
argparser.add_argument(
"--config",
default="repo2docker_config.py",
@ -222,13 +236,6 @@ def get_argparser():
argparser.add_argument("--subdir", type=str, help=Repo2Docker.subdir.help)
argparser.add_argument(
"--version",
dest="version",
action="store_true",
help="Print the repo2docker version and exit.",
)
argparser.add_argument(
"--cache-from", action="append", default=[], help=Repo2Docker.cache_from.help
)
@ -245,15 +252,24 @@ def make_r2d(argv=None):
if argv is None:
argv = sys.argv[1:]
argparser = get_argparser()
# version must be checked before parse, as repo/cmd are required and
# will spit out an error if allowed to be parsed first.
if "--version" in argv:
print(__version__)
sys.exit(0)
args = get_argparser().parse_args(argv)
if "--help-all" in argv:
argparser.print_help()
print("\nAll configurable options:\n")
Repo2Docker().print_help(classes=True)
sys.exit(0)
args, traitlet_args = argparser.parse_known_args(argv)
r2d = Repo2Docker()
r2d.parse_command_line(traitlet_args)
if args.debug:
r2d.log_level = logging.DEBUG

Wyświetl plik

@ -47,6 +47,10 @@ class Repo2Docker(Application):
name = "jupyter-repo2docker"
version = __version__
description = __doc__
# disable aliases/flags because we don't use the traitlets for CLI parsing
# other than --Class.trait=value
aliases = {}
flags = {}
@default("log_level")
def _default_log_level(self):
@ -490,7 +494,7 @@ class Repo2Docker(Application):
extra=dict(phase="failed"),
)
def initialize(self):
def initialize(self, *args, **kwargs):
"""Init repo2docker configuration before start"""
# FIXME: Remove this function, move it to setters / traitlet reactors
if self.json_logs: