1 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License").
4 # You may not use this file except in compliance with the License.
5 # A copy of the License is located at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # or in the "license" file accompanying this file. This file is distributed
10 # on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11 # express or implied. See the License for the specific language governing
12 # permissions and limitations under the License.
23 class MissingOutput(Exception):
28 @dataclasses.dataclass
30 """Copy output artifacts to a directory, raising MissingOutput if they don't exist"""
32 artifacts_dir: pathlib.Path
36 def copy_output_artifact(self, fyle):
38 if os.path.isfile(fyle):
39 shutil.copy(fyle, self.artifacts_dir)
41 if os.path.isdir(fyle):
42 shutil.copytree(fyle, self.artifacts_dir, dirs_exist_ok=True)
44 raise FileNotFoundError
45 except FileNotFoundError as e:
46 if "phony_outputs" not in self.job_args:
47 raise MissingOutput() from e
49 if self.job_args["phony_outputs"] is None:
50 raise MissingOutput() from e
52 if not self.job_args["phony_outputs"]:
53 # User supplied an empty list of phony outputs, so all outputs
54 # are considered phony
57 if fyle in self.job_args["phony_outputs"]:
60 raise MissingOutput() from e