diff --git a/run_af2/src/run_af2/run_singularity.py b/run_af2/src/run_af2/run_singularity.py index 434fe384bb85f3eda610dedcbd896d2d1e3f02f4..ecdc30d7165190f9d88f17c973f3724cf4503184 100644 --- a/run_af2/src/run_af2/run_singularity.py +++ b/run_af2/src/run_af2/run_singularity.py @@ -7,8 +7,6 @@ There are three modes: cluster (not supported, yet) """ -__version__ = "0.1" - from datetime import datetime, timedelta import argparse import os @@ -38,7 +36,7 @@ def _parse_cmdline(): parser.add_argument( "--version", action="version", - version="%(prog)s {}".format(__version__), + version="%(prog)s {}".format(_get_version()), help="Show the version number and exit.", ) parser.add_argument( @@ -70,6 +68,24 @@ def _parse_cmdline(): return opts +def _get_version(): + """Load the package version (import only upon request). + + Only delivers a versions string after packaging happened once (run + `python -m build` in the same directory as the setup.cfg file), since that + creates the version file. + + :returns: A version string or 'x.x.x' in case packaging did not happen.""" + # version is only needed to call the script with --version which is + # terminal. So we allow this wrong way to import it here. + # pylint: disable=import-outside-toplevel + try: + import version + except ImportError: + return "x.x.x" + return version.version + + def _prepare_singularity_bind_mount(path, already_bound): """Create a bind mount for path outside of $HOME. @@ -203,6 +219,8 @@ def _determine_af2_image(af2_image_dir): return af2_path +# This function gets a lot of default parameters which are seldomly changed, so +# we disable the PyLint check for having too many arguments. def run_af2_singularity_image( # pylint: disable=too-many-arguments fasta_files, output_dir, @@ -257,6 +275,9 @@ def run_af2_singularity_image( # pylint: disable=too-many-arguments :returns: Nothing. :raises: RuntimeError if the Singularity/ AF2 call fails.""" + # Since the number of arguments to this function is already high, we allow + # more local variables than defined by PEP8. + # pylint: disable=too-many-locals tmpdir = os.getenv(tmpdir_var) if tmpdir is None: raise ValueError(f"tmpdir_var {tmpdir_var} must not be empty.")