Skip to content

Commit

Permalink
Pre-commit: replace old format string interpolation with f-strings
Browse files Browse the repository at this point in the history
Since Python 3.5 is no longer supported, format string interpolations
can now be replaced by f-strings, introduced in Python 3.6, which are
more readable, require less characters and are more efficient.

All of the conversions were done automatically with the linting tool
`flynt` which is also added as a pre-commit hook. It is added before the
`yapf` step because since `flynt` will touch formatting, `yapf` will
then get a chance to check it.
  • Loading branch information
sphuber committed Oct 15, 2020
1 parent 2156b45 commit 302fb10
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/ikamensh/flynt/
rev: '0.55'
hooks:
- id: flynt
args: [
'--line-length=120',
'--fail-on-change',
]

- repo: https://github.com/pre-commit/mirrors-yapf
rev: v0.30.0
hooks:
Expand Down
4 changes: 2 additions & 2 deletions aiida_pseudo/cli/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def cmd_install_sssp(version, functional, protocol, traceback):
url_archive = f'{URL_SSSP_BASE}/SSSP_{version}_{functional}_{protocol}.tar.gz'
filepath_archive = os.path.join(dirpath, 'archive.tar.gz')

url_metadata = '{}/SSSP_{}_{}_{}.json'.format(URL_SSSP_BASE, version, functional, protocol)
url_metadata = f'{URL_SSSP_BASE}/SSSP_{version}_{functional}_{protocol}.json'
filepath_metadata = os.path.join(dirpath, 'metadata.json')

with attempt('downloading selected pseudo potentials archive... ', include_traceback=traceback):
Expand All @@ -121,7 +121,7 @@ def cmd_install_sssp(version, functional, protocol, traceback):
handle.flush()
handle.seek(0)
metadata = json.load(handle)
description += '\nPseudo metadata md5: {}'.format(md5_file(filepath_metadata))
description += f'\nPseudo metadata md5: {md5_file(filepath_metadata)}'

with attempt('unpacking archive and parsing pseudos... ', include_traceback=traceback):
family = create_family_from_archive(SsspFamily, label, filepath_archive)
Expand Down
2 changes: 1 addition & 1 deletion aiida_pseudo/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def attempt(message, exception_types=Exception, include_traceback=False):
echo.echo_highlight(' [FAILED]', color='error', bold=True)
message = str(exception)
if include_traceback:
message += '\n' + ''.join(traceback.format_exception(*sys.exc_info()))
message += f"\n{''.join(traceback.format_exception(*sys.exc_info()))}"
echo.echo_critical(message)
else:
echo.echo_highlight(' [OK]', color='success', bold=True)
Expand Down

0 comments on commit 302fb10

Please sign in to comment.