Skip to content

Commit 3b51367

Browse files
authored
Merge pull request #3 from wpoely86/update
Sync with upstream
2 parents f03c36c + eb6fd1e commit 3b51367

27 files changed

+457
-176
lines changed

.github/workflows/unittest.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@ jobs:
66
runs-on: ubuntu-20.04
77
steps:
88
- name: Checkout code
9-
uses: actions/checkout@v3
9+
uses: actions/checkout@v4
1010
- name: Setup Python
11-
uses: actions/setup-python@v4
11+
uses: actions/setup-python@v5
1212
with:
1313
python-version: ${{ matrix.python }}
1414
- name: install tox
1515
run: pip install 'virtualenv<20.22.0' 'tox<4.5.0'
1616
- name: add mandatory git remote
17-
run: git remote add hpcugent https://github.com/hpcugent/vsc-utils.git
17+
run: git remote add hpcugent https://github.com/vub-hpc/vsc-utils.git
1818
- name: Run tox
19-
run: tox -e py
19+
run: tox -e py$(echo ${{ matrix.python }} | sed 's/\.//g')
2020
strategy:
2121
matrix:
2222
python:

lib/vsc/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2015-2023 Ghent University
2+
# Copyright 2015-2025 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
@@ -24,7 +24,9 @@
2424
# along with vsc-utils. If not, see <http://www.gnu.org/licenses/>.
2525
#
2626
"""
27-
Allow other packages to extend this namespace, zip safe setuptools style
27+
Initialize vsc package.
28+
The vsc namespace is used in different folders along the system
29+
so explicitly declare this is also the vsc namespace.
2830
"""
2931
import pkg_resources
3032
pkg_resources.declare_namespace(__name__)

lib/vsc/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2015-2023 Ghent University
2+
# Copyright 2015-2025 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/availability.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2023 Ghent University
2+
# Copyright 2012-2025 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),

lib/vsc/utils/cache.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2023 Ghent University
2+
# Copyright 2012-2025 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
@@ -29,14 +29,15 @@
2929
@author: Andy Georges (Ghent University)
3030
"""
3131
import gzip
32-
import jsonpickle
3332
import os
3433
import time
3534
import pickle
35+
import jsonpickle
36+
3637

3738
from vsc.utils import fancylogger
3839

39-
class FileCache(object):
40+
class FileCache:
4041
"""File cache with a timestamp safety.
4142
4243
Stores data (something that can be pickled) into a dictionary
@@ -81,19 +82,19 @@ def __init__(self, filename, retain_old=True, raise_unpickable=False):
8182
try:
8283
g = gzip.GzipFile(mode='rb', fileobj=f) # no context manager available in python 26 yet
8384
s = g.read()
84-
except (IOError) as err:
85+
except (OSError) as _:
8586
self.log.error("Cannot load data from cache file %s as gzipped json", self.filename)
8687
try:
8788
f.seek(0)
8889
self.shelf = pickle.load(f)
8990
except pickle.UnpicklingError as err:
90-
msg = "Problem loading pickle data from %s (corrupt data)" % (self.filename,)
91+
msg = f"Problem loading pickle data from {self.filename} (corrupt data)"
9192
if raise_unpickable:
9293
self.log.raiseException(msg)
9394
else:
9495
self.log.error("%s. Continue with empty shelf: %s", msg, err)
9596
self.shelf = {}
96-
except (OSError, IOError):
97+
except OSError:
9798
self.log.raiseException("Could not load pickle data from %s", self.filename)
9899
else:
99100
try:
@@ -105,7 +106,7 @@ def __init__(self, filename, retain_old=True, raise_unpickable=False):
105106
finally:
106107
g.close()
107108

108-
except (OSError, IOError, ValueError, FileNotFoundError) as err:
109+
except (OSError, ValueError, FileNotFoundError) as err:
109110
self.log.warning("Could not access the file cache at %s [%s]", self.filename, err)
110111
self.shelf = {}
111112
self.log.info("Cache in %s starts with an empty shelf", (self.filename,))
@@ -142,7 +143,13 @@ def load(self, key):
142143
143144
@returns: (timestamp, data) if there is data for the given key, None otherwise.
144145
"""
145-
return self.new_shelf.get(key, None) or self.shelf.get(key, None)
146+
result = None
147+
if self.new_shelf is not None:
148+
result = self.new_shelf.get(key, None)
149+
if result is None and self.shelf is not None:
150+
return self.shelf.get(key, None)
151+
152+
return result
146153

147154
def retain(self):
148155
"""Retain non-updated data on close."""
@@ -162,6 +169,8 @@ def close(self):
162169
self.log.error('cannot open the file cache at %s for writing', self.filename)
163170
else:
164171
if self.retain_old:
172+
if self.shelf is None:
173+
self.shelf = {}
165174
self.shelf.update(self.new_shelf)
166175
self.new_shelf = self.shelf
167176

lib/vsc/utils/fs_store.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2012-2023 Ghent University
2+
# Copyright 2012-2025 Ghent University
33
#
44
# This file is part of vsc-utils,
55
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
@@ -96,7 +96,3 @@ def store_on_gpfs(user_name, path, key, information, gpfs, login_mount_point, gp
9696
gpfs.ignorerealpathmismatch = False
9797

9898
logger.info("Stored user %s %s information at %s", user_name, key, filename)
99-
100-
101-
102-

0 commit comments

Comments
 (0)