Skip to content

Commit

Permalink
Remove superfluous ERROR_NO_RETRIEVED_FOLDER from CalcJob subclasses
Browse files Browse the repository at this point in the history
The `ERROR_NO_RETRIEVED_FOLDER` is now defined on the `CalcJob`
base class and the `CalcJob.parse` method already checks for the
presence of the retrieved folder and return the exit code if it is
missing. This allows us to remove the similar exit codes that are
currently defined on the calculation plugins shipped with `aiida-core`
`ArithmeticAddCalculation` and `TemplateReplacerCalculation` as well as
the check for the presence of the `retrieved` output from the
corresponding parsers. The fact that is now checked in the `CalcJob`
base class means that `Parser` implementations can assume safely that
the retrieved output node exists.
  • Loading branch information
sphuber committed Jun 7, 2020
1 parent 31a7cc0 commit 98d7881
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 23 deletions.
2 changes: 0 additions & 2 deletions aiida/calculations/arithmetic/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def define(cls, spec):
spec.input('y', valid_type=(orm.Int, orm.Float), help='The right operand.')
spec.input('settings', required=False, valid_type=orm.Dict, help='Optional settings.')
spec.output('sum', valid_type=(orm.Int, orm.Float), help='The sum of the left and right operand.')
spec.exit_code(300, 'ERROR_NO_RETRIEVED_FOLDER',
message='The retrieved folder data node could not be accessed.')
spec.exit_code(310, 'ERROR_READING_OUTPUT_FILE',
message='The output file could not be read from the retrieved folder.')
spec.exit_code(320, 'ERROR_INVALID_OUTPUT',
Expand Down
2 changes: 0 additions & 2 deletions aiida/calculations/templatereplacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def define(cls, spec):
spec.output('output_parameters', valid_type=orm.Dict, required=True)
spec.default_output_node = 'output_parameters'

spec.exit_code(100, 'ERROR_NO_RETRIEVED_FOLDER',
message='The retrieved folder data node could not be accessed.')
spec.exit_code(101, 'ERROR_NO_TEMPORARY_RETRIEVED_FOLDER',
message='The temporary retrieved folder data node could not be accessed.')
spec.exit_code(105, 'ERROR_NO_OUTPUT_FILE_NAME_DEFINED',
Expand Down
11 changes: 4 additions & 7 deletions aiida/parsers/plugins/arithmetic/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ class ArithmeticAddParser(Parser):

def parse(self, **kwargs): # pylint: disable=inconsistent-return-statements
"""Parse the contents of the output files retrieved in the `FolderData`."""
try:
output_folder = self.retrieved
except AttributeError:
return self.exit_codes.ERROR_NO_RETRIEVED_FOLDER
if self.node.exit_status == self.exit_codes.ERROR_NO_RETRIEVED_FOLDER.status:
return

try:
with output_folder.open(self.node.get_attribute('output_filename'), 'r') as handle:
with self.retrieved.open(self.node.get_attribute('output_filename'), 'r') as handle:
result = self.parse_stdout(handle)
except (OSError, IOError):
return self.exit_codes.ERROR_READING_OUTPUT_FILE
Expand All @@ -42,8 +40,7 @@ def parse(self, **kwargs): # pylint: disable=inconsistent-return-statements

@staticmethod
def parse_stdout(filelike):
"""
Parse the sum from the output of the ArithmeticAddcalculation written to standard out
"""Parse the sum from the output of the ArithmeticAddcalculation written to standard out
:param filelike: filelike object containing the output
:returns: the sum
Expand Down
17 changes: 5 additions & 12 deletions aiida/parsers/plugins/templatereplacer/doubler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,21 @@
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################

import os

from aiida.common import exceptions
from aiida.orm import Dict
from aiida.parsers.parser import Parser
from aiida.plugins import CalculationFactory

TemplatereplacerCalculation = CalculationFactory('templatereplacer')


class TemplatereplacerDoublerParser(Parser):

def parse(self, **kwargs):
"""Parse the contents of the output files retrieved in the `FolderData`."""
template = self.node.inputs.template.get_dict()
if self.node.exit_status == self.exit_codes.ERROR_NO_RETRIEVED_FOLDER.status:
return

try:
output_folder = self.retrieved
except exceptions.NotExistent:
return self.exit_codes.ERROR_NO_RETRIEVED_FOLDER
output_folder = self.retrieved
template = self.node.inputs.template.get_dict()

try:
output_file = template['output_file_name']
Expand Down Expand Up @@ -73,8 +67,7 @@ def parse(self, **kwargs):

@staticmethod
def parse_stdout(filelike):
"""
Parse the sum from the output of the ArithmeticAddcalculation written to standard out
"""Parse the sum from the output of the ArithmeticAddcalculation written to standard out.
:param filelike: filelike object containing the output
:returns: the sum
Expand Down

0 comments on commit 98d7881

Please sign in to comment.