Skip to content

Commit

Permalink
switch from docopt to docopt-ng (#927)
Browse files Browse the repository at this point in the history
* switch from docopt to docopt-ng

* remove unnecessary parentheses (trigger CI)
  • Loading branch information
n-gao authored Aug 26, 2024
1 parent 6b47feb commit 02b4e3d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions sacred/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import ast
import textwrap
import inspect
import re
from shlex import quote

from sacred.serializer import restore
Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion sacred/config/custom_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""The Experiment class, which is central to sacred."""

import inspect
import os.path
import sys
import warnings
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 (
Expand Down Expand Up @@ -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"])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 02b4e3d

Please sign in to comment.