Skip to content

Commit b32e257

Browse files
committed
Merge branch 'develop' into system-with-gcccore-dep
2 parents 044fecf + 825f842 commit b32e257

File tree

24 files changed

+130
-132
lines changed

24 files changed

+130
-132
lines changed

.github/workflows/linting.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: install Python packages
3030
run: |
3131
pip install --upgrade pip
32-
pip install --upgrade flake8
32+
pip install --upgrade flake8 flake8-comprehensions
3333
3434
- name: Run flake8 to verify PEP8-compliance of Python code
3535
run: |

easybuild/base/fancylogger.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def thread_name():
435435
"""
436436
returns the current threads name
437437
"""
438-
return threading.currentThread().getName()
438+
return threading.current_thread().name
439439

440440

441441
def getLogger(name=None, fname=False, clsname=False, fancyrecord=None):
@@ -577,8 +577,8 @@ def logToFile(filename, enable=True, filehandler=None, name=None, max_bytes=MAX_
577577
'mode': 'a',
578578
'maxBytes': max_bytes,
579579
'backupCount': backup_count,
580+
'encoding': 'utf-8',
580581
}
581-
handleropts['encoding'] = 'utf-8'
582582
# logging to a file is going to create the file later on, so let's try to be helpful and create the path if needed
583583
directory = os.path.dirname(filename)
584584
if not os.path.exists(directory):
@@ -783,7 +783,7 @@ def getAllExistingLoggers():
783783
"""
784784
# not-so-well documented manager (in 2.6 and later)
785785
# return list of (name,logger) tuple
786-
return [x for x in logging.Logger.manager.loggerDict.items()] + [(logging.root.name, logging.root)]
786+
return list(logging.Logger.manager.loggerDict.items()) + [(logging.root.name, logging.root)]
787787

788788

789789
def getAllNonFancyloggers():

easybuild/base/testing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@ def mocked_stdout_stderr(self, mock_stdout=True, mock_stderr=True):
224224
if mock_stderr:
225225
self.mock_stderr(False)
226226

227+
@contextmanager
228+
def saved_env(self):
229+
"""Context manager to reset environment to state when it was entered"""
230+
orig_env = os.environ.copy()
231+
try:
232+
yield
233+
finally:
234+
os.environ.clear()
235+
os.environ.update(orig_env)
236+
227237
def tearDown(self):
228238
"""Cleanup after running a test."""
229239
self.mock_stdout(False)

easybuild/base/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def proxy(self, *args): # pylint:disable=unused-argument
3939
# create proxies for wrapped object's double-underscore attributes
4040
type.__init__(cls, name, bases, dct)
4141
if cls.__wraps__:
42-
ignore = set("__%s__" % n for n in cls.__ignore__.split())
42+
ignore = {"__%s__" % n for n in cls.__ignore__.split()}
4343
for name in dir(cls.__wraps__):
4444
if name.startswith("__"):
4545
if name not in ignore and name not in dct:

easybuild/framework/easyconfig/easyconfig.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def det_subtoolchain_version(current_tc, subtoolchain_names, optional_toolchains
261261

262262
for subtoolchain_name in subtoolchain_names:
263263

264-
uniq_subtc_versions = set([subtc['version'] for subtc in cands if subtc['name'] == subtoolchain_name])
264+
uniq_subtc_versions = {subtc['version'] for subtc in cands if subtc['name'] == subtoolchain_name}
265265

266266
# system toolchain: bottom of the hierarchy
267267
if is_system_toolchain(subtoolchain_name):
@@ -318,8 +318,8 @@ def get_toolchain_hierarchy(parent_toolchain, incl_capabilities=False):
318318
# obtain list of all possible subtoolchains
319319
_, all_tc_classes = search_toolchain('')
320320
subtoolchains = {tc_class.NAME: getattr(tc_class, 'SUBTOOLCHAIN', None) for tc_class in all_tc_classes}
321-
optional_toolchains = set(tc_class.NAME for tc_class in all_tc_classes if getattr(tc_class, 'OPTIONAL', False))
322-
composite_toolchains = set(tc_class.NAME for tc_class in all_tc_classes if len(tc_class.__bases__) > 1)
321+
optional_toolchains = {tc_class.NAME for tc_class in all_tc_classes if getattr(tc_class, 'OPTIONAL', False)}
322+
composite_toolchains = {tc_class.NAME for tc_class in all_tc_classes if len(tc_class.__bases__) > 1}
323323

324324
# the parent toolchain is at the top of the hierarchy,
325325
# we need a copy so that adding capabilities (below) doesn't affect the original object
@@ -1219,14 +1219,16 @@ def dependencies(self, build_only=False, runtime_only=False):
12191219

12201220
return retained_deps
12211221

1222-
def dependency_names(self, build_only=False):
1222+
def dependency_names(self, build_only=False, runtime_only=False):
12231223
"""
12241224
Return a set of names of all (direct) dependencies after filtering.
12251225
Iterable builddependencies are flattened when not iterating.
12261226
12271227
:param build_only: only return build dependencies, discard others
1228+
:param runtime_only: only return runtime dependencies, discard others
12281229
"""
1229-
return {dep['name'] for dep in self.dependencies(build_only=build_only) if dep['name']}
1230+
return {dep['name'] for dep in self.dependencies(build_only=build_only, runtime_only=runtime_only)
1231+
if dep['name']}
12301232

12311233
def builddependencies(self):
12321234
"""

easybuild/framework/easyconfig/templates.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@
5050
'nameletter': 'First letter of software name',
5151
'toolchain_name': 'Toolchain name',
5252
'toolchain_version': 'Toolchain version',
53+
'version_major_minor_patch': "Major.Minor.Patch version",
5354
'version_major_minor': "Major.Minor version",
5455
'version_major': 'Major version',
56+
'version_minor_patch': 'Minor.Patch version',
5557
'version_minor': 'Minor version',
58+
'version_patch': 'Patch version',
5659
}
5760
# derived from EasyConfig._config
5861
TEMPLATE_NAMES_CONFIG = [
@@ -204,9 +207,12 @@
204207
'r_short_ver': 'rshortver',
205208
'r_ver': 'rver',
206209
'toolchain_ver': 'toolchain_version',
210+
'ver_maj_min_patch': 'version_major_minor_patch',
207211
'ver_maj_min': 'version_major_minor',
208212
'ver_maj': 'version_major',
213+
'ver_min_patch': 'version_minor_patch',
209214
'ver_min': 'version_minor',
215+
'ver_patch': 'version_patch',
210216
'version_prefix': 'versionprefix',
211217
'version_suffix': 'versionsuffix',
212218
}
@@ -343,11 +349,16 @@ def template_constant_dict(config, ignore=None, toolchain=None):
343349
minor = version[1]
344350
template_values['version_minor'] = minor
345351
template_values['version_major_minor'] = '.'.join([major, minor])
352+
if len(version) > 2:
353+
patch = version[2]
354+
template_values['version_patch'] = patch
355+
template_values['version_minor_patch'] = '.'.join([minor, patch])
356+
template_values['version_major_minor_patch'] = '.'.join([major, minor, patch])
346357
except IndexError:
347358
# if there is no minor version, skip it
348359
pass
349360
# only go through this once
350-
ignore.extend(['version_major', 'version_minor', 'version_major_minor'])
361+
ignore.extend(name for name in TEMPLATE_NAMES_EASYCONFIG if name.startswith('version_'))
351362

352363
elif name.endswith('letter'):
353364
# parse first letters

easybuild/framework/easyconfig/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def _to_checksum(checksum, list_level=0, allow_dict=True):
541541
# When we already are in a tuple no further recursion is allowed -> set list_level very high
542542
return tuple(_to_checksum(x, list_level=99, allow_dict=allow_dict) for x in checksum)
543543
else:
544-
return list(_to_checksum(x, list_level=list_level+1, allow_dict=allow_dict) for x in checksum)
544+
return [_to_checksum(x, list_level=list_level+1, allow_dict=allow_dict) for x in checksum]
545545
elif isinstance(checksum, dict) and allow_dict:
546546
return {key: _to_checksum(value, allow_dict=False) for key, value in checksum.items()}
547547

easybuild/tools/docs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ def gen_easyblock_doc_section_md(eb_class, path_to_examples, common_params, doc_
14681468

14691469
table_titles = ['easyconfig parameter', 'description']
14701470
table_values = [
1471-
[opt for opt in common_params[classname]],
1471+
common_params[classname],
14721472
[DEFAULT_CONFIG[opt][1] for opt in common_params[classname]],
14731473
]
14741474

@@ -1556,7 +1556,7 @@ def gen_easyblock_doc_section_rst(eb_class, path_to_examples, common_params, doc
15561556

15571557
table_titles = ['easyconfig parameter', 'description']
15581558
table_values = [
1559-
[opt for opt in common_params[classname]],
1559+
common_params[classname],
15601560
[DEFAULT_CONFIG[opt][1] for opt in common_params[classname]],
15611561
]
15621562

easybuild/tools/filetools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ def parse_http_header_fields_urlpat(arg, urlpat=None, header=None, urlpat_header
786786
if urlpat in urlpat_headers.keys():
787787
urlpat_headers[urlpat].append(argline) # add headers to the list
788788
else:
789-
urlpat_headers[urlpat] = list([argline]) # new list headers for this urlpat
789+
urlpat_headers[urlpat] = [argline] # new list headers for this urlpat
790790
else:
791791
_log.warning("Non-empty argument to http-header-fields-urlpat ignored (missing URL pattern)")
792792

@@ -838,7 +838,7 @@ def download_file(filename, url, path, forced=False, trace=True, max_attempts=No
838838
# parse option HTTP header fields for URLs containing a pattern
839839
http_header_fields_urlpat = build_option('http_header_fields_urlpat')
840840
# compile a dict full of {urlpat: [header, list]}
841-
urlpat_headers = dict()
841+
urlpat_headers = {}
842842
if http_header_fields_urlpat is not None:
843843
# there may be multiple options given, parse them all, while updating urlpat_headers
844844
for arg in http_header_fields_urlpat:
@@ -2368,7 +2368,7 @@ def encode_string(name):
23682368
"""
23692369

23702370
# do the character remapping, return same char by default
2371-
result = ''.join(map(lambda x: STRING_ENCODING_CHARMAP.get(x, x), name))
2371+
result = ''.join(STRING_ENCODING_CHARMAP.get(x, x) for x in name)
23722372
return result
23732373

23742374

easybuild/tools/modules.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,8 @@ def load(self, modules, mod_paths=None, purge=False, init_env=None, allow_reload
10951095
:param init_env: original environment to restore after running 'module purge'
10961096
:param allow_reload: allow reloading an already loaded module
10971097
"""
1098+
if not any((modules, mod_paths, purge)):
1099+
return # Avoid costly module paths if nothing to do
10981100
if mod_paths is None:
10991101
mod_paths = []
11001102

@@ -1123,10 +1125,10 @@ def load(self, modules, mod_paths=None, purge=False, init_env=None, allow_reload
11231125
if os.path.exists(full_mod_path):
11241126
self.prepend_module_path(full_mod_path, priority=priority)
11251127

1126-
loaded_modules = self.loaded_modules()
1128+
if not allow_reload:
1129+
modules = set(modules) - set(self.loaded_modules())
11271130
for mod in modules:
1128-
if allow_reload or mod not in loaded_modules:
1129-
self.run_module('load', mod)
1131+
self.run_module('load', mod)
11301132

11311133
def unload(self, modules, log_changes=True):
11321134
"""
@@ -1289,7 +1291,7 @@ def run_module(self, *args, **kwargs):
12891291
# keep track of current values of select env vars, so we can correct the adjusted values below
12901292
# Identical to `{key: os.environ.get(key, '').split(os.pathsep)[::-1] for key in LD_ENV_VAR_KEYS}`
12911293
# but Python 2 treats that as a local function and refused the `exec` below
1292-
prev_ld_values = dict([(key, os.environ.get(key, '').split(os.pathsep)[::-1]) for key in LD_ENV_VAR_KEYS])
1294+
prev_ld_values = {key: os.environ.get(key, '').split(os.pathsep)[::-1] for key in LD_ENV_VAR_KEYS}
12931295

12941296
# Change the environment
12951297
try:

0 commit comments

Comments
 (0)