Skip to content

Commit 8f274ab

Browse files
committed
fix --list-software=detailed when using Python 3 by leveraging sort_looseversions function from py2vs3 module (fixes #3112)
1 parent 1587f24 commit 8f274ab

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

easybuild/tools/docs.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
from easybuild.tools.config import build_option
5858
from easybuild.tools.filetools import read_file
5959
from easybuild.tools.modules import modules_tool
60-
from easybuild.tools.py2vs3 import OrderedDict, ascii_lowercase
60+
from easybuild.tools.py2vs3 import OrderedDict, ascii_lowercase, sort_looseversions
6161
from easybuild.tools.toolchain.toolchain import DUMMY_TOOLCHAIN_NAME, SYSTEM_TOOLCHAIN_NAME, is_system_toolchain
6262
from easybuild.tools.toolchain.utilities import search_toolchain
6363
from easybuild.tools.utilities import INDENT_2SPACES, INDENT_4SPACES
@@ -635,14 +635,22 @@ def key_to_ref(name):
635635
table_titles = ['version', 'toolchain']
636636
table_values = [[], []]
637637

638+
# first determine unique pairs of version/versionsuffix
639+
# we can't use LooseVersion yet here, since nub uses set and LooseVersion instances are not hashable
638640
pairs = nub((x['version'], x['versionsuffix']) for x in software[key])
639641

642+
# check whether any non-empty versionsuffixes are in play
640643
with_vsuff = any(vs for (_, vs) in pairs)
641644
if with_vsuff:
642645
table_titles.insert(1, 'versionsuffix')
643646
table_values.insert(1, [])
644647

645-
for ver, vsuff in sorted((LooseVersion(v), vs) for (v, vs) in pairs):
648+
# sort pairs by version (and then by versionsuffix);
649+
# we sort by LooseVersion to obtain chronological version ordering,
650+
# but we also need to retain original string version for filtering-by-version done below
651+
sorted_pairs = sort_looseversions((LooseVersion(v), vs, v) for v, vs in pairs)
652+
653+
for _, vsuff, ver in sorted_pairs:
646654
table_values[0].append('``%s``' % ver)
647655
if with_vsuff:
648656
if vsuff:
@@ -690,8 +698,17 @@ def list_software_txt(software, detailed=False):
690698
"homepage: %s" % software[key][-1]['homepage'],
691699
'',
692700
])
701+
702+
# first determine unique pairs of version/versionsuffix
703+
# we can't use LooseVersion yet here, since nub uses set and LooseVersion instances are not hashable
693704
pairs = nub((x['version'], x['versionsuffix']) for x in software[key])
694-
for ver, vsuff in sorted((LooseVersion(v), vs) for (v, vs) in pairs):
705+
706+
# sort pairs by version (and then by versionsuffix);
707+
# we sort by LooseVersion to obtain chronological version ordering,
708+
# but we also need to retain original string version for filtering-by-version done below
709+
sorted_pairs = sort_looseversions((LooseVersion(v), vs, v) for v, vs in pairs)
710+
711+
for _, vsuff, ver in sorted_pairs:
695712
tcs = [x['toolchain'] for x in software[key] if x['version'] == ver and x['versionsuffix'] == vsuff]
696713

697714
line = " * %s v%s" % (key, ver)

0 commit comments

Comments
 (0)