diff --git a/src/fishbowl/fishbowl.py b/src/fishbowl/fishbowl.py index 7a910e8f..1a70ec94 100644 --- a/src/fishbowl/fishbowl.py +++ b/src/fishbowl/fishbowl.py @@ -23,16 +23,17 @@ from gafferpy.gaffer_types import parse_java_type_to_string from collections import defaultdict from typing import Any, Callable, Dict, List, Set +from datetime import datetime class Fishbowl: def __init__( self, gaffer_connector: GafferConnector, - generated_directory_path: str = "generated" + generated_directory_path: str | Path = "generated" ): self._gaffer_connector = gaffer_connector - self.generated_directory_path = generated_directory_path + self.generated_directory_path = Path(generated_directory_path) print("Generating Python API from REST service...") self._generate_library() print( @@ -43,7 +44,8 @@ def __init__( def _write_to_file(self, file_path: Path, data: str) -> None: if data: - file_path.unlink() # removes file + if file_path.exists(): + file_path.unlink() # removes file with open(file_path, "w+") as file: file.write(data) @@ -76,6 +78,7 @@ def _generate_library(self): templates_dir = parent_dir / "templates" file_loader = FileSystemLoader(templates_dir) self.env = Environment(loader=file_loader) + self.env.globals['copyright_years'] = f"2022-{datetime.now().year}" operations_python = self._generate_operations() functions_python = self._generate_transform_functions() @@ -245,7 +248,7 @@ def _generate_import_strings(self, import_map[module].add(_class) return [ - f"from {import_path} import {','.join(sorted(classes))}" for import_path, + f"from {import_path} import {', '.join(sorted(classes))}" for import_path, classes in import_map.items() ] diff --git a/src/fishbowl/templates/base.py.j2 b/src/fishbowl/templates/base.py.j2 index 635c183a..5b07d16e 100644 --- a/src/fishbowl/templates/base.py.j2 +++ b/src/fishbowl/templates/base.py.j2 @@ -1,5 +1,5 @@ # -# Copyright 2022 Crown Copyright +# Copyright {{ copyright_years }} Crown Copyright # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License.