Skip to content

Commit 02b4e3d

Browse files
authored
switch from docopt to docopt-ng (#927)
* switch from docopt to docopt-ng * remove unnecessary parentheses (trigger CI)
1 parent 6b47feb commit 02b4e3d

File tree

6 files changed

+16
-8
lines changed

6 files changed

+16
-8
lines changed

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pytest==7.1.2 # tests/test_utils.py depends on that pytest version is exactly 7.1.2
22
colorama
3-
docopt
3+
docopt-ng
44
gitdb2
55
GitPython
66
hashfs

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
docopt>=0.3, <1.0
1+
docopt-ng>=0.9, <1.0
22
jsonpickle>=2.2.0
33
munch>=2.5, <5.0
44
wrapt>=1.0, <2.0

sacred/arg_parser.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import ast
1010
import textwrap
1111
import inspect
12+
import re
1213
from shlex import quote
1314

1415
from sacred.serializer import restore
@@ -199,6 +200,12 @@ def format_usage(program_name, description, commands=None, options=()):
199200
return usage
200201

201202

203+
def printable_usage(doc):
204+
# in python < 2.7 you can't pass flags=re.IGNORECASE
205+
usage_split = re.split(r"([Uu][Ss][Aa][Gg][Ee]:)", doc)
206+
return re.split(r"\n\s*\n", "".join(usage_split[1:]))[0].strip()
207+
208+
202209
def _get_first_line_of_docstring(func):
203210
return textwrap.dedent(func.__doc__ or "").strip().split("\n")[0]
204211

sacred/config/custom_containers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def update(self, iterable=None, **kwargs):
100100
for key in iterable:
101101
self[key] = iterable[key]
102102
else:
103-
for (key, value) in iterable:
103+
for key, value in iterable:
104104
self[key] = value
105105
for key in kwargs:
106106
self[key] = kwargs[key]

sacred/experiment.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
"""The Experiment class, which is central to sacred."""
2+
23
import inspect
34
import os.path
45
import sys
56
import warnings
67
from collections import OrderedDict
78
from typing import Sequence, Optional, List
89

9-
from docopt import docopt, printable_usage
10+
from docopt import docopt
1011

1112
from sacred import SETTINGS
12-
from sacred.arg_parser import format_usage, get_config_updates
13+
from sacred.arg_parser import get_config_updates, format_usage, printable_usage
1314
from sacred import commandline_options
1415
from sacred.commandline_options import CLIOption
1516
from sacred.commands import (
@@ -294,7 +295,7 @@ def run_commandline(self, argv=None) -> Optional[Run]:
294295
"""
295296
argv = ensure_wellformed_argv(argv)
296297
short_usage, usage, internal_usage = self.get_usage()
297-
args = docopt(internal_usage, [str(a) for a in argv[1:]], help=False)
298+
args = docopt(internal_usage, [str(a) for a in argv[1:]], default_help=False)
298299

299300
cmd_name = args.get("COMMAND") or self.default_command
300301
config_updates, named_configs = get_config_updates(args["UPDATE"])

tests/test_arg_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def test_parse_individual_arguments(argv, expected):
5151
options = gather_command_line_options()
5252
usage = format_usage("test.py", "", {}, options)
5353
argv = shlex.split(argv)
54-
plain = docopt(usage, [], help=False)
55-
args = docopt(usage, argv, help=False)
54+
plain = docopt(usage, [], default_help=False)
55+
args = docopt(usage, argv, default_help=False)
5656
plain.update(expected)
5757
assert args == plain
5858

0 commit comments

Comments
 (0)