Skip to content

Commit

Permalink
Use f-strings in aiida/engine/daemon/execmanager.py
Browse files Browse the repository at this point in the history
The automatic conversion of `.format` notation to f-strings that was
done quite some time ago missed a bunch of occurrences in the
`execmanager` module.
  • Loading branch information
unkcpz authored and sphuber committed Jun 22, 2023
1 parent 8ef74a2 commit 49cffff
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions aiida/engine/daemon/execmanager.py
Expand Up @@ -110,28 +110,26 @@ def upload_calculation(
remote_working_directory = computer.get_workdir().format(username=remote_user)
if not remote_working_directory.strip():
raise exceptions.ConfigurationError(
"[submission of calculation {}] No remote_working_directory configured for computer '{}'".format(
node.pk, computer.label
)
f'[submission of calculation {node.pk}] No remote_working_directory '
f"configured for computer '{computer.label}'"
)

# If it already exists, no exception is raised
try:
transport.chdir(remote_working_directory)
except IOError:
logger.debug(
'[submission of calculation {}] Unable to chdir in {}, trying to create it'.format(
node.pk, remote_working_directory
)
f'[submission of calculation {node.pk}] Unable to '
f'chdir in {remote_working_directory}, trying to create it'
)
try:
transport.makedirs(remote_working_directory)
transport.chdir(remote_working_directory)
except EnvironmentError as exc:
raise exceptions.ConfigurationError(
'[submission of calculation {}] '
'Unable to create the remote directory {} on '
"computer '{}': {}".format(node.pk, remote_working_directory, computer.label, exc)
f'[submission of calculation {node.pk}] '
f'Unable to create the remote directory {remote_working_directory} on '
f"computer '{computer.label}': {exc}"
)
# Store remotely with sharding (here is where we choose
# the folder structure of remote jobs; then I store this
Expand Down Expand Up @@ -249,37 +247,35 @@ def upload_calculation(
for (remote_computer_uuid, remote_abs_path, dest_rel_path) in remote_copy_list:
if remote_computer_uuid == computer.uuid:
logger.debug(
'[submission of calculation {}] copying {} remotely, directly on the machine {}'.format(
node.pk, dest_rel_path, computer.label
)
f'[submission of calculation {node.pk}] copying {dest_rel_path} '
f'remotely, directly on the machine {computer.label}'
)
try:
transport.copy(remote_abs_path, dest_rel_path)
except (IOError, OSError):
logger.warning(
'[submission of calculation {}] Unable to copy remote resource from {} to {}! '
'Stopping.'.format(node.pk, remote_abs_path, dest_rel_path)
f'[submission of calculation {node.pk}] Unable to copy remote '
f'resource from {remote_abs_path} to {dest_rel_path}! Stopping.'
)
raise
else:
raise NotImplementedError(
'[submission of calculation {}] Remote copy between two different machines is '
'not implemented yet'.format(node.pk)
f'[submission of calculation {node.pk}] Remote copy between two different machines is '
'not implemented yet'
)

for (remote_computer_uuid, remote_abs_path, dest_rel_path) in remote_symlink_list:
if remote_computer_uuid == computer.uuid:
logger.debug(
'[submission of calculation {}] copying {} remotely, directly on the machine {}'.format(
node.pk, dest_rel_path, computer.label
)
f'[submission of calculation {node.pk}] copying {dest_rel_path} remotely, '
f'directly on the machine {computer.label}'
)
try:
transport.symlink(remote_abs_path, dest_rel_path)
except (IOError, OSError):
logger.warning(
'[submission of calculation {}] Unable to create remote symlink from {} to {}! '
'Stopping.'.format(node.pk, remote_abs_path, dest_rel_path)
f'[submission of calculation {node.pk}] Unable to create remote symlink '
f'from {remote_abs_path} to {dest_rel_path}! Stopping.'
)
raise
else:
Expand All @@ -293,19 +289,17 @@ def upload_calculation(
with open(filepath, 'w', encoding='utf-8') as handle: # type: ignore[assignment]
for remote_computer_uuid, remote_abs_path, dest_rel_path in remote_copy_list:
handle.write(
'would have copied {} to {} in working directory on remote {}'.format(
remote_abs_path, dest_rel_path, computer.label
)
f'would have copied {remote_abs_path} to {dest_rel_path} in working '
f'directory on remote {computer.label}'
)

if remote_symlink_list:
filepath = os.path.join(workdir, '_aiida_remote_symlink_list.txt')
with open(filepath, 'w', encoding='utf-8') as handle: # type: ignore[assignment]
for remote_computer_uuid, remote_abs_path, dest_rel_path in remote_symlink_list:
handle.write(
'would have created symlinks from {} to {} in working directory on remote {}'.format(
remote_abs_path, dest_rel_path, computer.label
)
f'would have created symlinks from {remote_abs_path} to {dest_rel_path} in working'
f'directory on remote {computer.label}'
)

# Loop recursively over content of the sandbox folder copying all that are not in `provenance_exclude_list`. Note
Expand Down

0 comments on commit 49cffff

Please sign in to comment.