Skip to content

Commit 76e684d

Browse files
authored
Merge pull request #5043 from Flamefire/comprehensions
Enable flake8-comprehension code style check and fix issues
2 parents e1d03ae + 148267c commit 76e684d

File tree

18 files changed

+40
-44
lines changed

18 files changed

+40
-44
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/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: 3 additions & 3 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

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ def run_module(self, *args, **kwargs):
12891289
# keep track of current values of select env vars, so we can correct the adjusted values below
12901290
# Identical to `{key: os.environ.get(key, '').split(os.pathsep)[::-1] for key in LD_ENV_VAR_KEYS}`
12911291
# 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])
1292+
prev_ld_values = {key: os.environ.get(key, '').split(os.pathsep)[::-1] for key in LD_ENV_VAR_KEYS}
12931293

12941294
# Change the environment
12951295
try:

easybuild/tools/options.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,15 @@ def terminal_supports_colors(stream):
128128

129129
XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), ".config"))
130130
XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(os.pathsep)
131-
DEFAULT_SYS_CFGFILES = [[f for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))]
131+
DEFAULT_SYS_CFGFILES = [sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))
132132
for d in XDG_CONFIG_DIRS]
133133
DEFAULT_USER_CFGFILE = os.path.join(XDG_CONFIG_HOME, 'easybuild', 'config.cfg')
134134

135135
DEFAULT_LIST_PR_STATE = GITHUB_PR_STATE_OPEN
136136
DEFAULT_LIST_PR_ORDER = GITHUB_PR_ORDER_CREATED
137137
DEFAULT_LIST_PR_DIREC = GITHUB_PR_DIRECTION_DESC
138138

139-
RPATH_DEFAULT = False if get_os_type() == DARWIN else True
139+
RPATH_DEFAULT = get_os_type() != DARWIN
140140

141141
_log = fancylogger.getLogger('options', fname=False)
142142

@@ -1135,7 +1135,7 @@ def _postprocess_close_pr_reasons(self):
11351135
)
11361136

11371137
reasons = self.options.close_pr_reasons.split(',')
1138-
if any([reason not in VALID_CLOSE_PR_REASONS.keys() for reason in reasons]):
1138+
if any(reason not in VALID_CLOSE_PR_REASONS for reason in reasons):
11391139
raise EasyBuildError(
11401140
"Argument to --close-pr_reasons must be a comma separated list of valid reasons among %s",
11411141
VALID_CLOSE_PR_REASONS.keys(), exit_code=EasyBuildExit.OPTION_ERROR
@@ -1561,7 +1561,7 @@ def show_system_info(self):
15611561
"* software:",
15621562
" -> glibc version: %s" % system_info['glibc_version'],
15631563
" -> Python binary: %s" % sys.executable,
1564-
" -> Python version: %s" % sys.version.split(' ')[0],
1564+
" -> Python version: %s" % sys.version.split(' ', maxsplit=1)[0],
15651565
])
15661566

15671567
return '\n'.join(lines)
@@ -1749,7 +1749,7 @@ def check_included_multiple(included_easyblocks_from, source):
17491749
if options.include_easyblocks:
17501750
# check if you are including the same easyblock twice
17511751
included_paths = expand_glob_paths(options.include_easyblocks)
1752-
included_easyblocks = set([os.path.basename(eb) for eb in included_paths])
1752+
included_easyblocks = {os.path.basename(eb) for eb in included_paths}
17531753

17541754
if options.include_easyblocks_from_pr:
17551755
try:
@@ -1762,7 +1762,7 @@ def check_included_multiple(included_easyblocks_from, source):
17621762

17631763
for easyblock_pr in easyblock_prs:
17641764
easyblocks_from_pr = fetch_easyblocks_from_pr(easyblock_pr)
1765-
included_from_pr = set([os.path.basename(eb) for eb in easyblocks_from_pr])
1765+
included_from_pr = {os.path.basename(eb) for eb in easyblocks_from_pr}
17661766

17671767
if options.include_easyblocks:
17681768
check_included_multiple(included_from_pr, "PR #%s" % easyblock_pr)
@@ -1776,7 +1776,7 @@ def check_included_multiple(included_easyblocks_from, source):
17761776
easyblock_commit = options.include_easyblocks_from_commit
17771777
if easyblock_commit:
17781778
easyblocks_from_commit = fetch_easyblocks_from_commit(easyblock_commit)
1779-
included_from_commit = set([os.path.basename(eb) for eb in easyblocks_from_commit])
1779+
included_from_commit = {os.path.basename(eb) for eb in easyblocks_from_commit}
17801780

17811781
if options.include_easyblocks:
17821782
check_included_multiple(included_from_commit, "commit %s" % easyblock_commit)

easybuild/tools/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def create_test_report(msg, ecs_with_res, init_session_state, pr_nrs=None, gist_
277277
end_time = strftime(time_format, end_time)
278278
test_report.extend(["#### Time info", " * start: %s" % start_time, " * end: %s" % end_time, ""])
279279

280-
eb_config = [x for x in sorted(init_session_state['easybuild_configuration'])]
280+
eb_config = sorted(init_session_state['easybuild_configuration'])
281281
test_report.extend([
282282
"#### EasyBuild info",
283283
" * easybuild-framework version: %s" % FRAMEWORK_VERSION,

0 commit comments

Comments
 (0)