Skip to content

Commit

Permalink
fix: handle non-PEP440 versions of apptainer/singulariy (#2337)
Browse files Browse the repository at this point in the history
### Description
Apptainer and singularity use non-PEP440 version numbers like
`1.1.8-1.el8` and `3.10.4-dirty`. packaging.version can not handle these
version numbers. To mitigate the issue, a character is stripped away at
the end of the string until it is parsable by packaging.version.

Should fix #2319  and #2334

### QC
<!-- Make sure that you can tick the boxes below. -->

* [x] The PR contains a test case for the changes or the changes are
already covered by an existing test case.
* [x] The documentation (`docs/`) is updated to reflect the changes or
this is not necessary (e.g. if the change does neither modify the
language nor the behavior or functionalities of Snakemake).

---------

Co-authored-by: Johannes Köster <johannes.koester@tu-dortmund.de>
Co-authored-by: Johannes Köster <johannes.koester@uni-due.de>
  • Loading branch information
3 people committed Jun 30, 2023
1 parent a876e0f commit dea6ba8
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions snakemake/deployment/singularity.py
Expand Up @@ -150,6 +150,26 @@ def version(self):
), "bug: singularity version accessed before check() has been called"
return self._version

def parseversion(self, raw_version):
import packaging

raw_version = raw_version.rsplit(" ", 1)[-1]
if raw_version.startswith("v"):
raw_version = raw_version[1:]

parsed_version = None
trimend = len(raw_version)
while parsed_version is None:
try:
parsed_version = packaging.version.Version(raw_version[:trimend])
except packaging.version.InvalidVersion:
trimend = trimend - 1
if trimend == 0:
raise WorkflowError(
f"Apptainer/Singularity version cannot be parsed: {raw_version}"
)
return parsed_version

def check(self):
from packaging.version import parse

Expand All @@ -169,14 +189,8 @@ def check(self):
f"Failed to get singularity version:\n{e.stderr.decode()}"
)
if v.startswith("apptainer"):
v = v.rsplit(" ", 1)[-1]
v = v.split("-")[0]
if parse(v) < parse("1.0.0"):
if self.parseversion(v) < parse("1.0.0"):
raise WorkflowError("Minimum apptainer version is 1.0.0.")
else:
v = v.rsplit(" ", 1)[-1]
if v.startswith("v"):
v = v[1:]
if parse(v) < parse("2.4.1"):
raise WorkflowError("Minimum singularity version is 2.4.1.")
elif self.parseversion(v) < parse("2.4.1"):
raise WorkflowError("Minimum singularity version is 2.4.1.")
self._version = v

0 comments on commit dea6ba8

Please sign in to comment.