Skip to content

Commit

Permalink
chore: mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
renatav committed Dec 3, 2024
1 parent f726788 commit 20a1142
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
27 changes: 20 additions & 7 deletions taf/auth_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AuthenticationRepository(GitRepository, TAFRepository):

_conf_dir = None
_dependencies: Dict = {}
_last_validated_data = None
_last_validated_data: Optional[Dict] = None

def __init__(
self,
Expand Down Expand Up @@ -143,9 +143,11 @@ def last_validated_commit(self) -> Optional[str]:
Return the last validated commit of the authentication repository
"""
try:
return self.last_validated_data[self.LAST_VALIDATED_KEY]
if self.last_validated_data is not None:
return self.last_validated_data[self.LAST_VALIDATED_KEY]
except KeyError:
return None
return None

@property
def last_validated_data(self) -> Optional[dict]:
Expand Down Expand Up @@ -190,7 +192,9 @@ def commit_and_push(
if new_commit_branch:
new_commit = self.top_commit_of_branch(new_commit_branch)
if new_commit:
self.set_last_validated_of_repo(self.name, new_commit)
self.set_last_validated_of_repo(
self.name, new_commit, set_last_validated_commit=True
)
self._log_notice(
f"Updated last_validated_commit to {new_commit}"
)
Expand Down Expand Up @@ -293,13 +297,22 @@ def set_last_validated_data(
self._log_debug(f"setting last validated data to: {last_data_str}")
Path(self.conf_dir, self.LAST_VALIDATED_FILENAME).write_text(last_data_str)

def set_last_validated_of_repo(self, repo_name: str, commit: str):
def set_last_validated_of_repo(
self,
repo_name: str,
commit: str,
set_last_validated_commit: Optional[bool] = True,
):
last_validated_data = self.last_validated_data or {}
last_validated_data[repo_name] = commit
last_validated_data[self.LAST_VALIDATED_KEY] = commit
last_data_str = json.dumps(last_validated_data, indent=4)
self._log_debug(f"setting last validated data to: {last_data_str}")
Path(self.conf_dir, self.LAST_VALIDATED_DATA_FILENAME).write_text(last_data_str)
if set_last_validated_commit and self.name == repo_name:
last_validated_data[self.LAST_VALIDATED_KEY] = last_validated_data[
self.name
]
Path(self.conf_dir, self.LAST_VALIDATED_FILENAME).write_text(last_data_str)

def auth_repo_commits_after_repos_last_validated(
self, target_repos: List, last_validated_data
Expand Down Expand Up @@ -519,11 +532,11 @@ def targets_at_revisions(
targets_at_revision = targets_at_revision["signed"]["targets"]

for target_path in targets_at_revision:
# if there are older auth repo commtis corresponding to repositories
# if there are older auth repo commits corresponding to repositories
# that were not validated in the one or more previous updates
# skip the ones that were validated more recently
# when the last validated commit of a repo is reached
# the repo is addes to the repos_to_skip list
# the repo is added to the repos_to_skip list
if target_path in repos_to_skip:
continue
if (
Expand Down
8 changes: 5 additions & 3 deletions taf/tests/test_updater/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,12 @@ def remove_last_validated_commit(auth_repo: AuthenticationRepository):


def remove_last_validated_data(auth_repo: AuthenticationRepository):
Path(auth_repo.conf_dir, auth_repo.LAST_VALIDATED_DATA_FILENAME).unlink()
Path(auth_repo.conf_dir, auth_repo.LAST_VALIDATED_FILENAME).unlink()
assert not auth_repo.last_validated_data


def replace_with_old_last_validated_commit_format(auth_repo: AuthenticationRepository):
last_validated_commit = auth_repo.last_validated_commit
last_validated_commit = auth_repo.last_validated_commit or ""
Path(auth_repo.conf_dir, auth_repo.LAST_VALIDATED_FILENAME).write_text(
last_validated_commit
)
Expand Down Expand Up @@ -771,7 +771,9 @@ def create_index_lock_in_repo(repo_path: str):
def set_head_commit(auth_repo: AuthenticationRepository):
last_valid_commit = auth_repo.head_commit_sha()
if last_valid_commit is not None:
auth_repo.set_last_validated_commit(last_valid_commit)
auth_repo.set_last_validated_of_repo(
auth_repo.name, last_valid_commit, set_last_validated_commit=True
)
else:
raise ValueError("Failed to retrieve the last valid commit SHA.")

Expand Down
3 changes: 0 additions & 3 deletions taf/updater/updater_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ def run(self):
raise UpdateFailedError(message)

except Exception as e:
import pdb

pdb.set_trace()
self.handle_error(e)
break
except KeyboardInterrupt as e:
Expand Down

0 comments on commit 20a1142

Please sign in to comment.