Skip to content

Commit

Permalink
Use dict.items() instead of repeatatly getting the value
Browse files Browse the repository at this point in the history
Faster and shorter
  • Loading branch information
Flamefire committed May 14, 2024
1 parent e4524c1 commit e501e39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions easybuild/framework/easyconfig/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ def check_deprecated(self, path):
if depr_msgs:
depr_msg = ', '.join(depr_msgs)

depr_maj_ver = int(str(VERSION).split('.')[0]) + 1
depr_maj_ver = int(str(VERSION).split('.', maxsplit=1)[0]) + 1
depr_ver = '%s.0' % depr_maj_ver

more_info_depr_ec = " (see also http://easybuild.readthedocs.org/en/latest/Deprecated-easyconfigs.html)"
Expand All @@ -864,8 +864,8 @@ def validate(self, check_osdeps=True):
- check license
"""
self.log.info("Validating easyconfig")
for attr in self.validations:
self._validate(attr, self.validations[attr])
for attr, valid_values in self.validations.items():
self._validate(attr, valid_values)

if check_osdeps:
self.log.info("Checking OS dependencies")
Expand Down Expand Up @@ -1229,8 +1229,8 @@ def dump(self, fp, always_overwrite=True, backup=False, explicit_toolchains=Fals
# templated values should be dumped unresolved
with self.disable_templating():
# build dict of default values
default_values = {key: DEFAULT_CONFIG[key][0] for key in DEFAULT_CONFIG}
default_values.update({key: self.extra_options[key][0] for key in self.extra_options})
default_values = {key: value[0] for key, value in DEFAULT_CONFIG.items()}
default_values.update({key: value[0] for key, value in self.extra_options.items()})

self.generate_template_values()
templ_const = {quote_py_str(const[1]): const[0] for const in TEMPLATE_CONSTANTS}
Expand Down
16 changes: 8 additions & 8 deletions test/framework/easyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2141,8 +2141,8 @@ def test_external_dependencies_templates(self):
'pyshortver': '3.6',
'pyver': '3.6.5',
}
for key in expected_template_values:
self.assertEqual(ec.template_values[key], expected_template_values[key])
for key, expected in expected_template_values.items():
self.assertEqual(ec.template_values[key], expected)

self.assertEqual(ec['versionsuffix'], '-Python-3.6.5-Perl-5.30')

Expand Down Expand Up @@ -2218,8 +2218,8 @@ def test_quote_str(self):
'foo\\bar': '"foo\\bar"',
}

for t in teststrings:
self.assertEqual(quote_str(t), teststrings[t])
for t, expected in teststrings.items():
self.assertEqual(quote_str(t), expected)

# test escape_newline
self.assertEqual(quote_str("foo\nbar", escape_newline=False), '"foo\nbar"')
Expand Down Expand Up @@ -4873,8 +4873,8 @@ def test_get_cuda_cc_template_value(self):
update_build_option('cuda_compute_capabilities', ['6.5', '7.0'])
ec = EasyConfig(self.eb_file)

for key in cuda_template_values:
self.assertEqual(ec.get_cuda_cc_template_value(key), cuda_template_values[key])
for key, expected in cuda_template_values.items():
self.assertEqual(ec.get_cuda_cc_template_value(key), expected)

update_build_option('cuda_compute_capabilities', None)
ec = EasyConfig(self.eb_file)
Expand All @@ -4886,8 +4886,8 @@ def test_get_cuda_cc_template_value(self):
self.prep()
ec = EasyConfig(self.eb_file)

for key in cuda_template_values:
self.assertEqual(ec.get_cuda_cc_template_value(key), cuda_template_values[key])
for key, expected in cuda_template_values.items():
self.assertEqual(ec.get_cuda_cc_template_value(key), expected)

def test_count_files(self):
"""Tests for EasyConfig.count_files method."""
Expand Down

0 comments on commit e501e39

Please sign in to comment.