Skip to content

Commit

Permalink
Merge branch 'main' into gh-59-add-gremlin-endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
wb36499 authored Oct 10, 2024
2 parents f7f1f96 + 9c13d0e commit f0dc933
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/fishbowl/fishbowl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
]

Expand Down
2 changes: 1 addition & 1 deletion src/fishbowl/templates/base.py.j2
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit f0dc933

Please sign in to comment.