Skip to content

Commit

Permalink
Merge branch 'trs/build/error-if-volumes-unsupported'
Browse files Browse the repository at this point in the history
  • Loading branch information
tsibley committed Feb 1, 2024
2 parents ec3ff3c + 6b8262a commit 041847a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ development source code and as such may not be routinely kept up to date.

# __NEXT__

## Improvements

* `nextstrain build` now errors if a [development overlay option][] such as
`--augur` or `--auspice` is given when using a runtime without support for
those (anything but Docker or Singularity). Previously, it would silently
ignore those options when unsupported by the runtime. The new behaviour
matches the behaviour of `nextstrain shell` since 5.0.0.
([#354](https://github.com/nextstrain/cli/pull/354))

[development overlay option]: https://docs.nextstrain.org/projects/cli/en/__NEXT__/commands/build/#development-options-for-docker


# 8.0.1 (29 January 2024)

Expand Down
4 changes: 4 additions & 0 deletions devel/release
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ update-changelog() {
# preserving the __NEXT__ heading itself.
perl -pi -e "s/(?<=^# __NEXT__$)/\n\n\n# $new_version ($today)/" "$changes_file"

# Replace any occurrences of __NEXT__ under the new version heading, e.g.
# for use in doc URLs that should point to the released version.
perl -pi -e "s/__NEXT__/$new_version/g if /^# \\Q$new_version/ ... /^# /" "$changes_file"

# Remove the __NEXT__ heading and the sentence «The "__NEXT__" heading
# below…» for the next commit, but leave the working tree untouched.
perl -0p -e '
Expand Down
18 changes: 17 additions & 1 deletion nextstrain/cli/command/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
from .. import runner
from ..argparse import add_extended_help_flags, AppendOverwriteDefault, SKIP_AUTO_DEFAULT_IN_HELP
from ..errors import UsageError, UserError
from ..util import byte_quantity, warn
from ..runner import docker, singularity
from ..util import byte_quantity, runner_name, warn
from ..volume import store_volume


Expand Down Expand Up @@ -146,6 +147,8 @@ def register_parser(subparser):


def run(opts):
assert_overlay_volumes_support(opts)

# We must check this before the conditions under which opts.build is
# optional because otherwise we could pass a missing build dir to a runner
# which ignores opts.attach.
Expand Down Expand Up @@ -233,6 +236,19 @@ def run(opts):
return runner.run(opts, working_volume = opts.build, cpus = opts.cpus, memory = opts.memory)


def assert_overlay_volumes_support(opts):
"""
Check that runtime overlays are supported, if given.
"""
overlay_volumes = [v for v in opts.volumes if v is not opts.build]

if overlay_volumes and opts.__runner__ not in {docker, singularity}:
raise UserError(f"""
The {runner_name(opts.__runner__)} runtime does not support overlays (e.g. of {overlay_volumes[0].name}).
Use the Docker or Singularity runtimes (via --docker or --singularity) if overlays are necessary.
""")


def parse_snakemake_args(args):
"""
Inspects a tiny subset of Snakemake's CLI arguments in order to determine
Expand Down
12 changes: 3 additions & 9 deletions nextstrain/cli/command/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from .. import resources
from .. import runner
from ..argparse import add_extended_help_flags
from ..errors import UserError
from ..paths import SHELL_HISTORY
from ..runner import docker, conda, singularity
from ..util import colored, remove_prefix, runner_name, warn
from ..volume import store_volume, NamedVolume
from .build import assert_overlay_volumes_support


def register_parser(subparser):
Expand Down Expand Up @@ -43,6 +43,8 @@ def register_parser(subparser):


def run(opts):
assert_overlay_volumes_support(opts)

# Ensure our build dir exists
if not opts.build.src.is_dir():
warn("Error: Build path \"%s\" does not exist or is not a directory." % opts.build.src)
Expand All @@ -53,14 +55,6 @@ def run(opts):

return 1

overlay_volumes = [v for v in opts.volumes if v is not opts.build]

if overlay_volumes and opts.__runner__ not in {docker, singularity}:
raise UserError(f"""
The {runner_name(opts.__runner__)} runtime does not support overlays (e.g. of {overlay_volumes[0].name}).
Use the Docker or Singularity runtimes (via --docker or --singularity) if overlays are necessary.
""")

print(colored("bold", f"Entering the Nextstrain runtime ({runner_name(opts.__runner__)})"))
print()

Expand Down
2 changes: 1 addition & 1 deletion nextstrain/cli/runner/aws_batch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def register_arguments(parser) -> None:


def run(opts, argv, working_volume = None, extra_env: Env = {}, cpus: int = None, memory: int = None) -> int:
# Unlike other runners, the AWS Bach runner currently *requires* a working
# Unlike other runners, the AWS Batch runner currently *requires* a working
# dir in most usages. This is ok as we only provide the AWS Batch runner
# for commands which also require a working dir (e.g. build), whereas other
# runners also work with commands that don't.
Expand Down

0 comments on commit 041847a

Please sign in to comment.