diff --git a/dev-requirements.txt b/dev-requirements.txt index c3d9c470..430dec99 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,6 +1,6 @@ pytest==7.1.2 # tests/test_utils.py depends on that pytest version is exactly 7.1.2 colorama -docopt +docopt-ng gitdb2 GitPython hashfs diff --git a/requirements.txt b/requirements.txt index a20916af..f53b9b0a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -docopt>=0.3, <1.0 +docopt-ng>=0.9, <1.0 jsonpickle>=2.2.0 munch>=2.5, <5.0 wrapt>=1.0, <2.0 diff --git a/sacred/arg_parser.py b/sacred/arg_parser.py index ba564fa1..2319bf44 100644 --- a/sacred/arg_parser.py +++ b/sacred/arg_parser.py @@ -9,6 +9,7 @@ import ast import textwrap import inspect +import re from shlex import quote from sacred.serializer import restore @@ -199,6 +200,12 @@ def format_usage(program_name, description, commands=None, options=()): return usage +def printable_usage(doc): + # in python < 2.7 you can't pass flags=re.IGNORECASE + usage_split = re.split(r"([Uu][Ss][Aa][Gg][Ee]:)", doc) + return re.split(r"\n\s*\n", "".join(usage_split[1:]))[0].strip() + + def _get_first_line_of_docstring(func): return textwrap.dedent(func.__doc__ or "").strip().split("\n")[0] diff --git a/sacred/config/custom_containers.py b/sacred/config/custom_containers.py index 6edd65c2..dd10a19e 100644 --- a/sacred/config/custom_containers.py +++ b/sacred/config/custom_containers.py @@ -100,7 +100,7 @@ def update(self, iterable=None, **kwargs): for key in iterable: self[key] = iterable[key] else: - for (key, value) in iterable: + for key, value in iterable: self[key] = value for key in kwargs: self[key] = kwargs[key] diff --git a/sacred/experiment.py b/sacred/experiment.py index a0b7e9dc..8f59e8d3 100755 --- a/sacred/experiment.py +++ b/sacred/experiment.py @@ -1,4 +1,5 @@ """The Experiment class, which is central to sacred.""" + import inspect import os.path import sys @@ -6,10 +7,10 @@ from collections import OrderedDict from typing import Sequence, Optional, List -from docopt import docopt, printable_usage +from docopt import docopt from sacred import SETTINGS -from sacred.arg_parser import format_usage, get_config_updates +from sacred.arg_parser import get_config_updates, format_usage, printable_usage from sacred import commandline_options from sacred.commandline_options import CLIOption from sacred.commands import ( @@ -294,7 +295,7 @@ def run_commandline(self, argv=None) -> Optional[Run]: """ argv = ensure_wellformed_argv(argv) short_usage, usage, internal_usage = self.get_usage() - args = docopt(internal_usage, [str(a) for a in argv[1:]], help=False) + args = docopt(internal_usage, [str(a) for a in argv[1:]], default_help=False) cmd_name = args.get("COMMAND") or self.default_command config_updates, named_configs = get_config_updates(args["UPDATE"]) diff --git a/tests/test_arg_parser.py b/tests/test_arg_parser.py index 2508ab98..d0cf0649 100644 --- a/tests/test_arg_parser.py +++ b/tests/test_arg_parser.py @@ -51,8 +51,8 @@ def test_parse_individual_arguments(argv, expected): options = gather_command_line_options() usage = format_usage("test.py", "", {}, options) argv = shlex.split(argv) - plain = docopt(usage, [], help=False) - args = docopt(usage, argv, help=False) + plain = docopt(usage, [], default_help=False) + args = docopt(usage, argv, default_help=False) plain.update(expected) assert args == plain