Skip to content

Commit

Permalink
runner: Slightly better prose list formatting in the description of -…
Browse files Browse the repository at this point in the history
…-env

Lists formatted as if they're for computers not humans are a pet peeve
of mine, so address it here.  This copy of prose_list() will also make
it quick to improve other lists in this codebase in the future.
  • Loading branch information
tsibley committed Jun 20, 2023
1 parent fa2633d commit 0cac6a0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
26 changes: 26 additions & 0 deletions LICENSE.id3c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
This license applies to the original copy of "prose_list" from the ID3C project
into this project, incorporated as part of "nextstrain/cli/util.py". Any
subsequent modifications this project's copy of "prose_list" are licensed under
the MIT license of this project, not of ID3C.

MIT License

Copyright (c) 2018 Brotman Baty Institute

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions nextstrain/cli/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..argparse import DirectoryPath, SKIP_AUTO_DEFAULT_IN_HELP
from ..errors import UserError
from ..types import Env, Options, RunnerModule
from ..util import runner_name, runner_module, runner_help, warn
from ..util import prose_list, runner_name, runner_module, runner_help, warn
from ..volume import NamedVolume


Expand Down Expand Up @@ -157,7 +157,7 @@ def register_arguments(parser: ArgumentParser, runners: List[RunnerModule], exec
"May be specified more than once. "
"Overrides any variables of the same name set via --envdir. "
"When this option or --envdir is given, the default behaviour of automatically passing thru several \"well-known\" variables is disabled. "
f"The \"well-known\" variables are: {' '.join(hostenv.forwarded_names)}. "
f"The \"well-known\" variables are {prose_list(hostenv.forwarded_names, 'and')}. "
"Pass those variables explicitly via --env or --envdir if you need them in combination with other variables. "
f"{SKIP_AUTO_DEFAULT_IN_HELP}",
action = "append",
Expand Down
20 changes: 19 additions & 1 deletion nextstrain/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import subprocess
import sys
from functools import partial
from typing import Any, Callable, Mapping, List, Optional, Sequence, Tuple, Union, overload
from typing import Any, Callable, Iterable, Mapping, List, Optional, Sequence, Tuple, Union, overload
from typing_extensions import Literal
from packaging.version import parse as parse_version
from pathlib import Path
Expand Down Expand Up @@ -610,3 +610,21 @@ def print_runner_tests(tests: RunnerTestResults):
remove_prefix(" ", indent(description, " "))

print(status.get(result, str(result)) + ":", formatted_description)


# Copied without modification from lib/id3c/api/utils/__init__.py in the ID3C
# project¹, which is licensed under the MIT license. See the LICENSE.id3c file
# distributed alongside this project's own LICENSE file.
#
# ¹ <https://github.com/seattleflu/id3c/blob/fdc3a17a6dd711caa760a6d533aae2be166127fd/lib/id3c/api/utils/__init__.py#L8-L18>
def prose_list(iterable: Iterable[str], conjunction: str = "or") -> str:
"""
Construct a nice natural language list of items from the *iterable*. The
default *conjunction* is "or".
"""
values = list(iterable)

if len(values) > 2:
return ", ".join([*values[:-1], f"{conjunction} " + values[-1]])
else:
return f" {conjunction} ".join(values)

0 comments on commit 0cac6a0

Please sign in to comment.