Skip to content

Commit

Permalink
update for py39
Browse files Browse the repository at this point in the history
  • Loading branch information
wdpypere committed Feb 19, 2024
1 parent 004a1aa commit 764b220
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion bin/run_lmod_cache.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Copyright 2016-2023 Ghent University
# Copyright 2016-2024 Ghent University
#
# This file is part of vsc-modules,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
Expand Down
2 changes: 1 addition & 1 deletion lib/vsc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2023 Ghent University
# Copyright 2015-2024 Ghent University
#
# This file is part of vsc-modules,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
Expand Down
2 changes: 1 addition & 1 deletion lib/vsc/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2023 Ghent University
# Copyright 2015-2024 Ghent University
#
# This file is part of vsc-modules,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
Expand Down
31 changes: 15 additions & 16 deletions lib/vsc/modules/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2019-2023 Ghent University
# Copyright 2019-2024 Ghent University
#
# This file is part of vsc-modules,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
Expand Down Expand Up @@ -73,7 +73,7 @@ def parse(self, vstring):

def _cmp(self, other):
try:
return super(SoftwareVersion, self)._cmp(other)
return super()._cmp(other)
except Exception as e:
logging.exception("Failed to compare %s (%s) with other %s (%s): %s",
self, self.version, other, other.version, e)
Expand Down Expand Up @@ -101,7 +101,7 @@ def get_lua_via_json(filename, tablenames):
if not os.path.isfile(filename):
log_and_raise("No valid file %s found", filename)

tabledata = ','.join(["['%s']=%s" % (x, x) for x in tablenames])
tabledata = ','.join([f"['{x}']={x}" for x in tablenames])
luatemplate = "json=require('json');dofile('%s');print(json.encode({%s}))"
luacmd = luatemplate % (filename, tabledata)
# default asyncloop.run is slow: if the output is very big, code reads in 1k chunks
Expand All @@ -110,7 +110,7 @@ def get_lua_via_json(filename, tablenames):
arun.readsize = 1024**2
ec, out = arun._run()
if ec:
log_and_raise("Lua export to json using \"%s\" failed: %s" % (luacmd, out))
log_and_raise(f"Lua export to json using \"{luacmd}\" failed: {out}")

safe_out = SIMPLE_UTF_FIX_REGEX.sub("_____", out)
data = json.loads(safe_out)
Expand Down Expand Up @@ -151,23 +151,22 @@ def cluster_map(mpathMapT):
clustername = parts[0].lstrip('.')
if len(parts) == 2:
partition = parts[1].lstrip('.')
cluster = "%s/%s" % (clustername, partition)
cluster = f"{clustername}/{partition}"
if clustername in clustermap:
log_and_raise("Found existing cluster module %s for same cluster/partition %s" %
(clustername, partition))
log_and_raise(f"Found existing cluster module {clustername} for cluster/partition {partition}")
else:
cluster = clustername
partitions = [x for x in clustermap.keys() if x.startswith(clustername + "/")]
if partitions:
log_and_raise("Found existing partitions %s for same cluster %s" %
(partitions, clustername))
log_and_raise(f"Found existing partitions {partitions} for same cluster {clustername}")

# recreate the cluster module to support env/software
clmod_cl = '/'.join(['cluster'] + parts)
tmpclmod = clustermap.setdefault(cluster, clmod_cl)
if tmpclmod != clmod_cl:
log_and_raise("Found 2 different cluster modules %s and %s for same cluster %s (clmod %s)" %
(tmpclmod, clmod_cl, cluster, clmod))
log_and_raise(
f"Found 2 different cluster modules {tmpclmod} and {clmod_cl}"
f" for same cluster {cluster} (clmod {clmod})")
mpclusters = modulepathmap.setdefault(mpath, [])
if cluster not in mpclusters:
mpclusters.append(cluster)
Expand Down Expand Up @@ -236,10 +235,10 @@ def software_map(spiderT, mpmap):
for fullname, fulldata in namedata['fileT'].items():
version = fulldata['Version']
# sanity check
txt = "for modulepath %s name %s fullname %s: %s" % (mpath, name, fullname, fulldata)
txt = f"for modulepath {mpath} name {name} fullname {fullname}: {fulldata}"
if version != fulldata['canonical']:
log_and_raise("Version != canonical " + txt)
if fullname != "%s/%s" % (name, version):
if fullname != f"{name}/{version}":
log_and_raise("fullname != name/version " + txt)

mpversions.append(version)
Expand All @@ -261,8 +260,8 @@ def software_map(spiderT, mpmap):
default = value

if default not in soft:
log_and_raise("Default value %s found for %s modulepath %s but not matching entry: %s" %
(default, name, mpath, defaultdata))
log_and_raise(f"Default value {default} found for {name} modulepath {mpmap} "
f"but not matching entry: {defaultdata}")
else:
# see https://easybuild.readthedocs.io/en/latest/Wrapping_dependencies.html
logging.debug("Default without value found for %s modulepath %s: %s", name, mpath, defaultdata)
Expand Down Expand Up @@ -307,7 +306,7 @@ def read_json(filename=None):
"""Read JSON and return cluster and software map"""
if filename is None:
filename = get_json_filename()
with open(filename) as outfile:
with open(filename, encoding='utf8') as outfile:
data = json.load(outfile)
logging.debug("Read %s", filename)

Expand Down
2 changes: 1 addition & 1 deletion test/00-import.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2012-2023 Ghent University
# Copyright 2012-2024 Ghent University
#
# This file is part of vsc-modules,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
Expand Down
2 changes: 1 addition & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2012-2023 Ghent University
# Copyright 2012-2024 Ghent University
#
# This file is part of vsc-modules,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
Expand Down
6 changes: 3 additions & 3 deletions test/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2019-2023 Ghent University
# Copyright 2019-2024 Ghent University
#
# This file is part of vsc-modules,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
Expand Down Expand Up @@ -47,7 +47,7 @@ class CacheTest(TestCase):
def setUp(self):
"""Prepare to run test"""

super(CacheTest, self).setUp()
super().setUp()

self.topdir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# monkeypatch
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_make_json(self):

clview = software_cluster_view(softmap=softmap)
# regular ordered
self.assertEqual(clview['joltik']['Autoconf'], ['2.69-GCCcore-8.3.0', u'2.69-GCCcore-8.2.0'])
self.assertEqual(clview['joltik']['Autoconf'], ['2.69-GCCcore-8.3.0', '2.69-GCCcore-8.2.0'])
# non-trivial (first) default, rest ordered
# this default was manually set in the spiderT.lua test data
self.assertEqual(clview['skitty']['Bazel'],
Expand Down
12 changes: 10 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
# DO NOT EDIT MANUALLY

[tox]
envlist = py36
envlist = py36,py39
skipsdist = true

[testenv]
[testenv:py36]
commands_pre =
pip install 'setuptools<42.0'
python -m easy_install -U vsc-install

[testenv:py39]
setenv = SETUPTOOLS_USE_DISTUTILS=local
commands_pre =
pip install 'setuptools<54.0' wheel
python -c "from setuptools import setup;setup(script_args=['-q', 'easy_install', '-v', '-U', 'vsc-install'])"

[testenv]
commands = python setup.py test
passenv = USER
4 changes: 1 addition & 3 deletions vsc-ci.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
[vsc-ci]
pip3_install_tox=1
py3_tests_must_pass=1
py3_only=1
py39_tests_must_pass=1

0 comments on commit 764b220

Please sign in to comment.