Skip to content

Commit 02a8839

Browse files
authored
Merge pull request #3611 from opsmill/pog-repository-typing
Typing cleanup for git.repository
2 parents 2eb4ebc + 2a2ec20 commit 02a8839

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

backend/infrahub/git/repository.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -516,15 +516,7 @@ async def create_locally(
516516
return True
517517

518518
@classmethod
519-
async def new(cls, service: Optional[InfrahubServices] = None, **kwargs):
520-
service = service or InfrahubServices()
521-
self = cls(service=service, **kwargs)
522-
await self.create_locally()
523-
log.info("Created the new project locally.", repository=self.name)
524-
return self
525-
526-
@classmethod
527-
async def init(cls, service: Optional[InfrahubServices] = None, **kwargs):
519+
async def init(cls, service: Optional[InfrahubServices] = None, **kwargs: Any):
528520
service = service or InfrahubServices()
529521
self = cls(service=service, **kwargs)
530522
self.validate_local_directories()
@@ -861,7 +853,7 @@ async def get_conflicts(self, source_branch: str, dest_branch: str) -> List[str]
861853

862854
return conflict_files
863855

864-
async def import_objects_from_files(self, branch_name: str, commit: Optional[str] = None):
856+
async def import_objects_from_files(self, branch_name: str, commit: Optional[str] = None) -> None:
865857
if not commit:
866858
commit = self.get_commit_value(branch_name=branch_name)
867859

@@ -878,7 +870,9 @@ async def import_objects_from_files(self, branch_name: str, commit: Optional[str
878870
await self.import_jinja2_transforms(branch_name=branch_name, commit=commit, config_file=config_file)
879871
await self.import_artifact_definitions(branch_name=branch_name, commit=commit, config_file=config_file)
880872

881-
async def import_jinja2_transforms(self, branch_name: str, commit: str, config_file: InfrahubRepositoryConfig):
873+
async def import_jinja2_transforms(
874+
self, branch_name: str, commit: str, config_file: InfrahubRepositoryConfig
875+
) -> None:
882876
log.debug("Importing all Jinja2 transforms", repository=self.name, branch=branch_name, commit=commit)
883877

884878
schema = await self.sdk.schema.get(kind=InfrahubKind.TRANSFORMJINJA2, branch=branch_name)
@@ -986,7 +980,9 @@ async def update_jinja2_transform(
986980

987981
await existing_transform.save()
988982

989-
async def import_artifact_definitions(self, branch_name: str, commit: str, config_file: InfrahubRepositoryConfig):
983+
async def import_artifact_definitions(
984+
self, branch_name: str, commit: str, config_file: InfrahubRepositoryConfig
985+
) -> None:
990986
log.debug("Importing all Artifact Definitions", repository=self.name, branch=branch_name, commit=commit)
991987

992988
schema = await self.sdk.schema.get(kind=InfrahubKind.ARTIFACTDEFINITION, branch=branch_name)
@@ -1770,7 +1766,9 @@ async def compare_python_transform(
17701766
return False
17711767
return True
17721768

1773-
async def import_all_python_files(self, branch_name: str, commit: str, config_file: InfrahubRepositoryConfig):
1769+
async def import_all_python_files(
1770+
self, branch_name: str, commit: str, config_file: InfrahubRepositoryConfig
1771+
) -> None:
17741772
await self.import_python_check_definitions(branch_name=branch_name, commit=commit, config_file=config_file)
17751773
await self.import_python_transforms(branch_name=branch_name, commit=commit, config_file=config_file)
17761774
await self.import_generator_definitions(branch_name=branch_name, commit=commit, config_file=config_file)
@@ -1820,7 +1818,7 @@ async def get_file(self, commit: str, location: str) -> str:
18201818

18211819
return path.read_text(encoding="UTF-8")
18221820

1823-
async def render_jinja2_template(self, commit: str, location: str, data: dict):
1821+
async def render_jinja2_template(self, commit: str, location: str, data: dict) -> str:
18241822
commit_worktree = self.get_commit_worktree(commit=commit)
18251823

18261824
self.validate_location(commit=commit, worktree_directory=commit_worktree.directory, file_path=location)
@@ -1831,7 +1829,7 @@ async def render_jinja2_template(self, commit: str, location: str, data: dict):
18311829
template = templateEnv.get_template(location)
18321830
return template.render(**data)
18331831
except Exception as exc:
1834-
log.error(exc, exc_info=True, repository=self.name, commit=commit, location=location)
1832+
log.error(str(exc), exc_info=True, repository=self.name, commit=commit, location=location)
18351833
raise TransformError(repository_name=self.name, commit=commit, location=location, message=str(exc)) from exc
18361834

18371835
async def execute_python_check(
@@ -1894,7 +1892,7 @@ async def execute_python_check(
18941892

18951893
except Exception as exc:
18961894
log.critical(
1897-
exc,
1895+
str(exc),
18981896
exc_info=True,
18991897
repository=self.name,
19001898
branch=branch_name,
@@ -2090,7 +2088,7 @@ class InfrahubRepository(InfrahubRepositoryBase):
20902088
"""
20912089

20922090
def get_commit_value(self, branch_name: str, remote: bool = False) -> str:
2093-
branches = None
2091+
branches = {}
20942092
if remote:
20952093
branches = self.get_branches_from_remote()
20962094
else:
@@ -2265,6 +2263,14 @@ async def rebase(self, branch_name: str, source_branch: str = "main", push_remot
22652263

22662264
return response
22672265

2266+
@classmethod
2267+
async def new(cls, service: Optional[InfrahubServices] = None, **kwargs: Any) -> InfrahubRepository:
2268+
service = service or InfrahubServices()
2269+
self = cls(service=service, **kwargs)
2270+
await self.create_locally()
2271+
log.info("Created the new project locally.", repository=self.name)
2272+
return self
2273+
22682274

22692275
class InfrahubReadOnlyRepository(InfrahubRepositoryBase):
22702276
"""
@@ -2278,7 +2284,7 @@ class InfrahubReadOnlyRepository(InfrahubRepositoryBase):
22782284
)
22792285

22802286
@classmethod
2281-
async def new(cls, service: Optional[InfrahubServices] = None, **kwargs):
2287+
async def new(cls, service: Optional[InfrahubServices] = None, **kwargs: Any) -> InfrahubReadOnlyRepository:
22822288
service = service or InfrahubServices()
22832289

22842290
if "ref" not in kwargs or "infrahub_branch_name" not in kwargs:

0 commit comments

Comments
 (0)