From e67b8ec0fa85e57443e9b237ce2e78cf4db08ab7 Mon Sep 17 00:00:00 2001 From: Erik Vroon Date: Sat, 7 Oct 2023 17:23:33 +0200 Subject: [PATCH] Add vulture check (#296) --- .github/workflows/backend.yml | 4 ++++ backend/Pipfile | 1 + backend/bracket/config.py | 8 -------- backend/bracket/logic/scheduling/ladder_teams.py | 2 +- backend/bracket/models/db/court.py | 4 ---- backend/bracket/models/db/match.py | 11 ----------- backend/bracket/models/db/player.py | 4 ---- backend/bracket/models/db/stage.py | 7 ------- backend/bracket/routes/models.py | 8 -------- backend/bracket/sql/clubs.py | 4 ++-- backend/pyproject.toml | 15 ++++++++++++++- 11 files changed, 22 insertions(+), 46 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index d989fa88..ec0e3c3d 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -57,3 +57,7 @@ jobs: - name: Run ruff run: pipenv run ruff check . working-directory: backend + + - name: Run vulture + run: ! pipenv run vulture |grep "unused function\|unused class\|unused method" + working-directory: backend diff --git a/backend/Pipfile b/backend/Pipfile index 9ebd5de3..4eb79308 100644 --- a/backend/Pipfile +++ b/backend/Pipfile @@ -39,6 +39,7 @@ pytest-asyncio = ">=0.20.3" pytest-cov = ">=4.0.0" pytest-xdist = ">=3.2.1" ruff = ">=0.0.292" +vulture = ">=2.10" [requires] python_version = "3.10" diff --git a/backend/bracket/config.py b/backend/bracket/config.py index 413d8839..73c57119 100644 --- a/backend/bracket/config.py +++ b/backend/bracket/config.py @@ -14,14 +14,6 @@ class Environment(EnumAutoStr): DEMO = auto() CI = auto() - def get_env_filepath(self) -> str: - return { - Environment.PRODUCTION: 'prod.env', - Environment.DEVELOPMENT: 'dev.env', - Environment.CI: 'ci.env', - Environment.DEMO: 'demo.env', - }[self] - def get_log_level(self) -> int: return { Environment.CI: logging.WARNING, diff --git a/backend/bracket/logic/scheduling/ladder_teams.py b/backend/bracket/logic/scheduling/ladder_teams.py index 22c21e6c..bc69ab99 100644 --- a/backend/bracket/logic/scheduling/ladder_teams.py +++ b/backend/bracket/logic/scheduling/ladder_teams.py @@ -6,7 +6,7 @@ from bracket.sql.rounds import get_rounds_for_stage from bracket.sql.teams import get_teams_with_members -async def get_possible_upcoming_matches_for_teams( +async def todo_get_possible_upcoming_matches_for_teams( tournament_id: int, stage_id: int, filter_: MatchFilter ) -> list[SuggestedMatch]: suggestions: list[SuggestedMatch] = [] diff --git a/backend/bracket/models/db/court.py b/backend/bracket/models/db/court.py index 0100de36..89fa023b 100644 --- a/backend/bracket/models/db/court.py +++ b/backend/bracket/models/db/court.py @@ -10,10 +10,6 @@ class Court(BaseModelORM): tournament_id: int -class CourtInDB(Court): - id: int - - class CourtBody(BaseModelORM): name: str diff --git a/backend/bracket/models/db/match.py b/backend/bracket/models/db/match.py index 32bbb516..4c90ef1f 100644 --- a/backend/bracket/models/db/match.py +++ b/backend/bracket/models/db/match.py @@ -20,11 +20,6 @@ class Match(BaseModelORM): court_id: int | None -class UpcomingMatch(BaseModel): - team1_id: int - team2_id: int - - class MatchWithDetails(Match): team1: FullTeamWithPlayers team2: FullTeamWithPlayers @@ -57,12 +52,6 @@ class MatchCreateBody(BaseModelORM): court_id: int | None -class MatchToInsert(MatchCreateBody): - created: datetime_utc - team1_score: int = 0 - team2_score: int = 0 - - class MatchFilter(BaseModel): elo_diff_threshold: int only_behind_schedule: bool diff --git a/backend/bracket/models/db/player.py b/backend/bracket/models/db/player.py index 39c31ea8..28da5436 100644 --- a/backend/bracket/models/db/player.py +++ b/backend/bracket/models/db/player.py @@ -21,10 +21,6 @@ class Player(BaseModelORM): return self.id if self.id is not None else int(self.created.timestamp()) -class PlayerInDB(Player): - id: int - - class PlayerBody(BaseModelORM): name: str active: bool diff --git a/backend/bracket/models/db/stage.py b/backend/bracket/models/db/stage.py index a186bab7..6ad50a9e 100644 --- a/backend/bracket/models/db/stage.py +++ b/backend/bracket/models/db/stage.py @@ -33,10 +33,3 @@ class StageActivateBody(BaseModelORM): class StageCreateBody(BaseModelORM): type: StageType - - -class StageToInsert(BaseModelORM): - created: datetime_utc - tournament_id: int - type: StageType - is_active: bool = False diff --git a/backend/bracket/routes/models.py b/backend/bracket/routes/models.py index 146c6b0a..6fead751 100644 --- a/backend/bracket/routes/models.py +++ b/backend/bracket/routes/models.py @@ -48,10 +48,6 @@ class SinglePlayerResponse(DataResponse[Player]): pass -class RoundsResponse(DataResponse[list[Round]]): - pass - - class RoundsWithMatchesResponse(DataResponse[list[StageWithRounds]]): pass @@ -64,10 +60,6 @@ class SingleMatchResponse(DataResponse[Match]): pass -class TeamsResponse(DataResponse[list[Team]]): - pass - - class TeamsWithPlayersResponse(DataResponse[list[FullTeamWithPlayers]]): pass diff --git a/backend/bracket/sql/clubs.py b/backend/bracket/sql/clubs.py index 933f05a0..4b597bb7 100644 --- a/backend/bracket/sql/clubs.py +++ b/backend/bracket/sql/clubs.py @@ -47,7 +47,7 @@ async def sql_delete_club(club_id: int) -> None: await database.execute(query=query, values={'club_id': club_id}) -async def sql_remove_user_from_club(club_id: int, user_id: int) -> None: +async def todo_sql_remove_user_from_club(club_id: int, user_id: int) -> None: query = ''' DELETE FROM users_x_clubs WHERE club_id = :club_id @@ -66,7 +66,7 @@ async def get_clubs_for_user_id(user_id: int) -> list[Club]: return [Club.parse_obj(result._mapping) for result in results] -async def get_club_for_user_id(club_id: int, user_id: int) -> Club | None: +async def todo_get_club_for_user_id(club_id: int, user_id: int) -> Club | None: query = ''' SELECT clubs.* FROM clubs JOIN users_x_clubs uxc on clubs.id = uxc.club_id diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 4aa20730..fbfc0f9e 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -115,4 +115,17 @@ respect-gitignore = false show-fixes = true show-source = true target-version = "py311" -exclude = [".mypy_cache", ".pytest_cache", "__pycache__"] \ No newline at end of file +exclude = [".mypy_cache", ".pytest_cache", "__pycache__"] + +[tool.vulture] +min_confidence = 0 +paths = ["."] +ignore_decorators = ["@pytest.*", "@*router*", "@app.*", "@*validator*"] +ignore_names = [ + "todo*", + "RestartableUvicornWorker", + "_generate_next_value_", + "downgrade", + "upgrade" +] +sort_by_size = true