Skip to content

Commit

Permalink
allow "any" for minimum version to live dangerously..."
Browse files Browse the repository at this point in the history
Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Jun 21, 2023
1 parent c31d823 commit 7b2381f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
6 changes: 4 additions & 2 deletions snakemake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2676,16 +2676,18 @@ def main(argv=None):

# If a custom executor is provided, it must be known
if args.executor and args.executor not in executor_plugins:
logger.exit(
logger.error(
f"Executor {args.executor} not found. Did you install snakemake-executor-{args.executor}?"
)
exit(1)

# Custom argument parsing based on chosen executor
# We also only validate an executor plugin when it's selected
executor_args = None
if args.executor:
if not validate_executor_plugin(executor_plugins[args.executor]):
logger.exit("Executor {args.executor} is not valid.")
logger.error(f"Executor {args.executor} is not valid.")
exit(1)

# This is the dataclass prepared by the executor
executor_args = executor_plugins[args.executor].parse(args)
Expand Down
26 changes: 20 additions & 6 deletions snakemake/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pkgutil
import packaging.version
from snakemake.logging import logger
from snakemake import __version__

executor_plugin_prefix = "snakemake_executor_"

Expand Down Expand Up @@ -67,13 +66,13 @@ def validate_executor_plugin(module):
"""
for name in executor_plugin_attributes:
if not hasattr(module, name):
logger.warning(
logger.error(
f"Executor plugin {module} is missing expected attribute {name}"
)
return False

# If we get here, the version is the final check
return validate_snakemake_version(module.minimum_snakemake_version)
return validate_snakemake_version(module.snakemake_minimum_version)


def validate_snakemake_version(minimum_version):
Expand All @@ -83,16 +82,31 @@ def validate_snakemake_version(minimum_version):
If an unknown or unparseable version is provided, we cannot
determine and are more leniant and allow it.
"""
from snakemake import __version__

# If it's unknown, give a warning and allow it
if "unknown" in __version__:
logger.warning(
logger.error(
f"Snakemake version {__version__} cannot be determined for plugin compatibility."
)
return True

snakemake_version = packaging.version.parse(__version__)
# Living dangerously
if "any" in __version__:
return True

# Get rid of any commit or dirty tag
version = __version__.split("+", 1)[0]
snakemake_version = packaging.version.parse(version)
minimum_version = packaging.version.parse(minimum_version)
return snakemake_version >= minimum_version

# This is entirely done for usability and showing the user why it isn't valid
is_valid = snakemake_version >= minimum_version
if not is_valid:
logger.error(
f"Plugin expects Snakemake version {minimum_version} but found {version}"
)
return is_valid


def get_plugin_name_from_dataclass(dc):
Expand Down

0 comments on commit 7b2381f

Please sign in to comment.