Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#5118)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/pre-commit/pre-commit-hooks: v2.5.0 → v4.0.1](pre-commit/pre-commit-hooks@v2.5.0...v4.0.1)
- https://github.com/ikamensh/flynt/: 0.55 → 0.66
  • Loading branch information
pre-commit-ci[bot] authored Sep 8, 2021
1 parent 75e7024 commit 706e48b
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ci:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.5.0
rev: v4.0.1
hooks:
- id: double-quote-string-fixer
- id: end-of-file-fixer
Expand All @@ -21,7 +21,7 @@ repos:


- repo: https://github.com/ikamensh/flynt/
rev: '0.55'
rev: '0.66'
hooks:
- id: flynt
args: [
Expand Down
7 changes: 3 additions & 4 deletions aiida/backends/djsite/db/migrations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ def _deserialize_attribute(mainitem, subitems, sep, original_class=None, origina

if mainitem['datatype'] in ['none', 'bool', 'int', 'float', 'txt']:
if subitems:
raise DeserializationException("'{}' is of a base type, " 'but has subitems!'.format(mainitem.key))
raise DeserializationException(f"'{mainitem.key}' is of a base type, but has subitems!")
return _deserialize_basic_type(mainitem)

if mainitem['datatype'] == 'date':
if subitems:
raise DeserializationException("'{}' is of a base type, " 'but has subitems!'.format(mainitem.key))
raise DeserializationException(f"'{mainitem.key}' is of a base type, but has subitems!")
if is_naive(mainitem['dval']):
return make_aware(mainitem['dval'], get_current_timezone())
return mainitem['dval']
Expand Down Expand Up @@ -396,8 +396,7 @@ def validate_key(key):
raise ValidationError('The key cannot be an empty string.')
if AIIDA_ATTRIBUTE_SEP in key:
raise ValidationError(
"The separator symbol '{}' cannot be present "
'in the key of attributes, extras, etc.'.format(AIIDA_ATTRIBUTE_SEP)
f"The separator symbol '{AIIDA_ATTRIBUTE_SEP}' cannot be present in the key of attributes, extras, etc."
)

def get_value_for_node(self, dbnode, key):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def set_new_uuid(connection):
uuids.add(get_new_uuid())

# Create the key/value pairs
key_values = ','.join("({}, '{}')".format(curr_id, curr_uuid) for curr_id, curr_uuid in zip(ids, uuids))
key_values = ','.join(f"({curr_id}, '{curr_uuid}')" for curr_id, curr_uuid in zip(ids, uuids))

update_stm = f"""
UPDATE db_dblog as t SET
Expand Down
4 changes: 2 additions & 2 deletions aiida/cmdline/commands/cmd_computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def computer_test(user, print_traceback, computer):

if print_traceback:
message += '\n Full traceback:\n'
message += '\n'.join([' {}'.format(l) for l in traceback.format_exc().splitlines()])
message += '\n'.join([f' {l}' for l in traceback.format_exc().splitlines()])
else:
message += '\n Use the `--print-traceback` option to see the full traceback.'

Expand Down Expand Up @@ -512,7 +512,7 @@ def computer_test(user, print_traceback, computer):

if print_traceback:
message += '\n Full traceback:\n'
message += '\n'.join([' {}'.format(l) for l in traceback.format_exc().splitlines()])
message += '\n'.join([f' {l}' for l in traceback.format_exc().splitlines()])
else:
message += '\n Use the `--print-traceback` option to see the full traceback.'

Expand Down
20 changes: 4 additions & 16 deletions aiida/cmdline/commands/cmd_data/cmd_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ def _show_jmol(exec_name, trajectory_list, **kwargs):
echo.echo_error(f'the call to {exec_name} ended with an error.')
except OSError as err:
if err.errno == 2:
echo.echo_critical(
"No executable '{}' found. Add to the path, "
'or try with an absolute path.'.format(exec_name)
)
echo.echo_critical(f"No executable '{exec_name}' found. Add to the path, or try with an absolute path.")
else:
raise

Expand Down Expand Up @@ -100,10 +97,7 @@ def _show_xcrysden(exec_name, object_list, **kwargs):
echo.echo_error(f'the call to {exec_name} ended with an error.')
except OSError as err:
if err.errno == 2:
echo.echo_critical(
"No executable '{}' found. Add to the path, "
'or try with an absolute path.'.format(exec_name)
)
echo.echo_critical(f"No executable '{exec_name}' found. Add to the path, or try with an absolute path.")
else:
raise

Expand Down Expand Up @@ -162,10 +156,7 @@ def _show_vesta(exec_name, structure_list):
echo.echo_error(f'the call to {exec_name} ended with an error.')
except OSError as err:
if err.errno == 2:
echo.echo_critical(
"No executable '{}' found. Add to the path, "
'or try with an absolute path.'.format(exec_name)
)
echo.echo_critical(f"No executable '{exec_name}' found. Add to the path, or try with an absolute path.")
else:
raise

Expand Down Expand Up @@ -193,10 +184,7 @@ def _show_vmd(exec_name, structure_list):
echo.echo_error(f'the call to {exec_name} ended with an error.')
except OSError as err:
if err.errno == 2:
echo.echo_critical(
"No executable '{}' found. Add to the path, "
'or try with an absolute path.'.format(exec_name)
)
echo.echo_critical(f"No executable '{exec_name}' found. Add to the path, or try with an absolute path.")
else:
raise

Expand Down
2 changes: 1 addition & 1 deletion aiida/cmdline/commands/cmd_verdi.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def fail_with_suggestions(self, ctx, cmd_name):
matches = [c for c in sorted(self.list_commands(ctx)) if c.startswith(cmd_name)][:3]

if matches:
formatted = '\n'.join('\t{}'.format(m) for m in sorted(matches))
formatted = '\n'.join(f'\t{m}' for m in sorted(matches))
ctx.fail(f'`{cmd_name}` is not a {self.name} command.\n\nThe most similar commands are:\n{formatted}')
else:
ctx.fail(f'`{cmd_name}` is not a {self.name} command.\n\nNo similar commands found.')
Expand Down
10 changes: 2 additions & 8 deletions aiida/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,9 @@ def are_dir_trees_equal(dir1, dir2):
# If the directories contain the same files, compare the common files
(_, mismatch, errors) = filecmp.cmpfiles(dir1, dir2, dirs_cmp.common_files, shallow=False)
if mismatch:
return (
False, 'The following files in the directories {} and {} '
"don't match: {}".format(dir1, dir2, mismatch)
)
return (False, f"The following files in the directories {dir1} and {dir2} don't match: {mismatch}")
if errors:
return (
False, 'The following files in the directories {} and {} '
"aren't regular: {}".format(dir1, dir2, errors)
)
return (False, f"The following files in the directories {dir1} and {dir2} aren't regular: {errors}")

for common_dir in dirs_cmp.common_dirs:
new_dir1 = os.path.join(dir1, common_dir)
Expand Down
4 changes: 2 additions & 2 deletions aiida/orm/nodes/data/array/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def prepare_header_comment(uuid, plot_info, comment_char='#'):
for label in plot_info['raw_labels']:
filetext.append(f'\t{label[1]}\t{label[0]:.8f}')

return '\n'.join('{} {}'.format(comment_char, line) for line in filetext)
return '\n'.join(f'{comment_char} {line}' for line in filetext)


def find_bandgap(bandsdata, number_electrons=None, fermi_energy=None):
Expand Down Expand Up @@ -1024,7 +1024,7 @@ def _prepare_gnuplot(
# first prepare the xy coordinates of the sets
raw_data, _ = self._prepare_dat_blocks(plot_info, comments=comments)

xtics_string = ', '.join('"{}" {}'.format(label, pos) for pos, label in plot_info['labels'])
xtics_string = ', '.join(f'"{label}" {pos}' for pos, label in plot_info['labels'])

script = []
# Start with some useful comments
Expand Down
2 changes: 1 addition & 1 deletion aiida/orm/nodes/data/array/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def _prepare_xsf(self, index=None, main_file_name=''): # pylint: disable=unused
for idx in indices:
return_string += f'PRIMVEC {idx + 1}\n'
for cell_vector in cells[idx]:
return_string += ' '.join(['{:18.5f}'.format(i) for i in cell_vector])
return_string += ' '.join([f'{i:18.5f}' for i in cell_vector])
return_string += '\n'
return_string += f'PRIMCOORD {idx + 1}\n'
return_string += f'{nat} 1\n'
Expand Down
3 changes: 1 addition & 2 deletions aiida/orm/nodes/data/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@ def _validate(self):
)
if self.get_local_executable() not in self.list_object_names():
raise exceptions.ValidationError(
"The local executable '{}' is not in the list of "
'files of this code'.format(self.get_local_executable())
f"The local executable '{self.get_local_executable()}' is not in the list of files of this code"
)
else:
if self.list_object_names():
Expand Down
10 changes: 3 additions & 7 deletions aiida/orm/nodes/data/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,7 @@ def _validate(self):
counts = Counter([k.name for k in kinds])
for count in counts:
if counts[count] != 1:
raise ValidationError(
"Kind with name '{}' appears {} times "
'instead of only one'.format(count, counts[count])
)
raise ValidationError(f"Kind with name '{count}' appears {counts[count]} times instead of only one")

try:
# This will try to create the sites objects
Expand Down Expand Up @@ -987,7 +984,7 @@ def _prepare_xsf(self, main_file_name=''): # pylint: disable=unused-argument

return_string = 'CRYSTAL\nPRIMVEC 1\n'
for cell_vector in self.cell:
return_string += ' '.join(['%18.10f' % i for i in cell_vector])
return_string += ' '.join([f'{i:18.10f}' for i in cell_vector])
return_string += '\n'
return_string += 'PRIMCOORD 1\n'
return_string += f'{int(len(sites))} 1\n'
Expand Down Expand Up @@ -1373,8 +1370,7 @@ def append_site(self, site):

if site.kind_name not in [kind.name for kind in self.kinds]:
raise ValueError(
"No kind with name '{}', available kinds are: "
'{}'.format(site.kind_name, [kind.name for kind in self.kinds])
f"No kind with name '{site.kind_name}', available kinds are: {[kind.name for kind in self.kinds]}"
)

# If here, no exceptions have been raised, so I add the site.
Expand Down
15 changes: 3 additions & 12 deletions aiida/schedulers/plugins/direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ def _parse_joblist_output(self, retval, stdout, stderr):

filtered_stderr = '\n'.join(l for l in stderr.split('\n'))
if filtered_stderr.strip():
self.logger.warning(
'Warning in _parse_joblist_output, non-empty '
"(filtered) stderr='{}'".format(filtered_stderr)
)
self.logger.warning(f"Warning in _parse_joblist_output, non-empty (filtered) stderr='{filtered_stderr}'")
if retval != 0:
raise SchedulerError('Error during direct execution parsing (_parse_joblist_output function)')

Expand All @@ -243,10 +240,7 @@ def _parse_joblist_output(self, retval, stdout, stderr):
this_job.job_id = job[0]

if len(job) < 3:
raise SchedulerError(
'Unexpected output from the scheduler, '
"not enough fields in line '{}'".format(line)
)
raise SchedulerError(f"Unexpected output from the scheduler, not enough fields in line '{line}'")

try:
job_state_string = job[1][0] # I just check the first character
Expand All @@ -258,10 +252,7 @@ def _parse_joblist_output(self, retval, stdout, stderr):
this_job.job_state = \
_MAP_STATUS_PS[job_state_string]
except KeyError:
self.logger.warning(
"Unrecognized job_state '{}' for job "
'id {}'.format(job_state_string, this_job.job_id)
)
self.logger.warning(f"Unrecognized job_state '{job_state_string}' for job id {this_job.job_id}")
this_job.job_state = JobState.UNDETERMINED

try:
Expand Down
5 changes: 1 addition & 4 deletions aiida/schedulers/plugins/lsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,7 @@ def _parse_joblist_output(self, retval, stdout, stderr):
try:
job_state_string = _MAP_STATUS_LSF[job_state_raw]
except KeyError:
self.logger.warning(
"Unrecognized job_state '{}' for job "
'id {}'.format(job_state_raw, this_job.job_id)
)
self.logger.warning(f"Unrecognized job_state '{job_state_raw}' for job id {this_job.job_id}")
job_state_string = JobState.UNDETERMINED

this_job.job_state = job_state_string
Expand Down
15 changes: 4 additions & 11 deletions aiida/schedulers/plugins/sge.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ def _parse_joblist_output(self, retval, stdout, stderr):
self.logger.error(f'Error in sge._parse_joblist_output:no job id is given, stdout={stdout}')
raise SchedulerError('Error in sge._parse_joblist_output: no job id is given')
except IndexError:
self.logger.error("No 'job_number' given for job index {} in "
'job list, stdout={}'.format(jobs.index(job) \
, stdout))
self.logger.error(f"No 'job_number' given for job index {jobs.index(job)} in job list, stdout={stdout}")
raise IndexError('Error in sge._parse_joblist_output: no job id is given')

try:
Expand All @@ -378,13 +376,10 @@ def _parse_joblist_output(self, retval, stdout, stderr):
try:
this_job.job_state = _MAP_STATUS_SGE[job_state_string]
except KeyError:
self.logger.warning(
"Unrecognized job_state '{}' for job "
'id {}'.format(job_state_string, this_job.job_id)
)
self.logger.warning(f"Unrecognized job_state '{job_state_string}' for job id {this_job.job_id}")
this_job.job_state = JobState.UNDETERMINED
except IndexError:
self.logger.warning("No 'job_state' field for job id {} in" 'stdout={}'.format(this_job.job_id, stdout))
self.logger.warning(f"No 'job_state' field for job id {this_job.job_id} instdout={stdout}")
this_job.job_state = JobState.UNDETERMINED

try:
Expand Down Expand Up @@ -432,9 +427,7 @@ def _parse_joblist_output(self, retval, stdout, stderr):
)
except IndexError:
self.logger.warning(
"No 'JB_submission_time' and no "
"'JAT_start_time' field for job "
'id {}'.format(this_job.job_id)
f"No 'JB_submission_time' and no 'JAT_start_time' field for job id {this_job.job_id}"
)

# There is also cpu_usage, mem_usage, io_usage information available:
Expand Down
5 changes: 1 addition & 4 deletions aiida/schedulers/plugins/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,7 @@ def _parse_joblist_output(self, retval, stdout, stderr):
try:
job_state_string = _MAP_STATUS_SLURM[job_state_raw]
except KeyError:
self.logger.warning(
"Unrecognized job_state '{}' for job "
'id {}'.format(job_state_raw, this_job.job_id)
)
self.logger.warning(f"Unrecognized job_state '{job_state_raw}' for job id {this_job.job_id}")
job_state_string = JobState.UNDETERMINED
# QUEUED_HELD states are not specific states in SLURM;
# they are instead set with state QUEUED, and then the
Expand Down
2 changes: 1 addition & 1 deletion aiida/tools/dbimporters/plugins/cod.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _double_clause(self, key, alias, values, precision):
for value in values:
if not isinstance(value, int) and not isinstance(value, float):
raise ValueError(f"incorrect value for keyword '{alias}' only integers and floats are accepted")
return ' OR '.join('{} BETWEEN {} AND {}'.format(key, d - precision, d + precision) for d in values)
return ' OR '.join(f'{key} BETWEEN {d - precision} AND {d + precision}' for d in values)

length_precision = 0.001
angle_precision = 0.001
Expand Down
4 changes: 2 additions & 2 deletions aiida/tools/dbimporters/plugins/icsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def _str_fuzzy_clause(self, key, alias, values):
for value in values:
if not isinstance(value, int) and not isinstance(value, str):
raise ValueError("incorrect value for keyword '" + alias + ' only integers and strings are accepted')
return ' OR '.join("{} LIKE '%{}%'".format(key, s) for s in values)
return ' OR '.join(f"{key} LIKE '%{s}%'" for s in values)

def _composition_clause(self, key, alias, values): # pylint: disable=unused-argument
"""
Expand All @@ -152,7 +152,7 @@ def _double_clause(self, key, alias, values, precision):
for value in values:
if not isinstance(value, int) and not isinstance(value, float):
raise ValueError("incorrect value for keyword '" + alias + ' only integers and floats are accepted')
return ' OR '.join('{} BETWEEN {} AND {}'.format(key, d - precision, d + precision) for d in values)
return ' OR '.join(f'{key} BETWEEN {d - precision} AND {d + precision}' for d in values)

def _crystal_system_clause(self, key, alias, values):
"""
Expand Down
5 changes: 1 addition & 4 deletions aiida/tools/dbimporters/plugins/nninc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ def _str_clause(self, key, alias, values):
Returns part of HTTP GET query for querying string fields.
"""
if not isinstance(values, str):
raise ValueError(
"incorrect value for keyword '{}' -- only "
'strings and integers are accepted'.format(alias)
)
raise ValueError(f"incorrect value for keyword '{alias}' -- only strings and integers are accepted")
return f'{key}={values}'

_keywords = {
Expand Down
2 changes: 1 addition & 1 deletion aiida/tools/importexport/dbimport/backends/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def import_data_dj(
raise exceptions.DanglingLinkError(
'The import file refers to {} nodes with unknown UUID, therefore it cannot be imported. Either first '
'import the unknown nodes, or export also the parents when exporting. The unknown UUIDs are:\n'
''.format(len(unknown_nodes)) + '\n'.join('* {}'.format(uuid) for uuid in unknown_nodes)
''.format(len(unknown_nodes)) + '\n'.join(f'* {uuid}' for uuid in unknown_nodes)
)

###################################
Expand Down
2 changes: 1 addition & 1 deletion aiida/tools/importexport/dbimport/backends/sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def import_data_sqla(
raise exceptions.DanglingLinkError(
'The import file refers to {} nodes with unknown UUID, therefore it cannot be imported. Either first '
'import the unknown nodes, or export also the parents when exporting. The unknown UUIDs are:\n'
''.format(len(unknown_nodes)) + '\n'.join('* {}'.format(uuid) for uuid in unknown_nodes)
''.format(len(unknown_nodes)) + '\n'.join(f'* {uuid}' for uuid in unknown_nodes)
)

###################################
Expand Down
3 changes: 1 addition & 2 deletions aiida/tools/importexport/dbimport/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ def merge_comment(incoming_comment, comment_mode):
# Invalid comment_mode
else:
raise exceptions.ImportValidationError(
'Unknown comment_mode value: {}. Should be '
"either 'newest' or 'overwrite'".format(comment_mode)
f"Unknown comment_mode value: {comment_mode}. Should be either 'newest' or 'overwrite'"
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ def validate_key(cls, key):
raise ValidationError('The key cannot be an empty string.')
if AIIDA_ATTRIBUTE_SEP in key:
raise ValidationError(
"The separator symbol '{}' cannot be present "
'in the key of attributes, extras, etc.'.format(AIIDA_ATTRIBUTE_SEP)
f"The separator symbol '{AIIDA_ATTRIBUTE_SEP}' cannot be present in the key of attributes, extras, etc."
)

@classmethod
Expand Down
Loading

0 comments on commit 706e48b

Please sign in to comment.