Skip to content

Commit

Permalink
chore: Lint Cleanup (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
RickiJay-WMDE committed Nov 12, 2024
1 parent f00c2af commit ef9aa37
Show file tree
Hide file tree
Showing 37 changed files with 88 additions and 113 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -25,8 +23,6 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -40,8 +36,6 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -55,8 +49,6 @@ jobs:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.10.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
2 changes: 1 addition & 1 deletion data/database_connection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Database Connection"""

from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from typing import AsyncGenerator

from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
Expand Down
4 changes: 2 additions & 2 deletions fetch_data/api_data/log_data/create_log_observation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Create Log Observation"""

from collections.abc import Iterable
from datetime import datetime
from json.decoder import JSONDecodeError
from typing import List
from requests.exceptions import ReadTimeout, SSLError
from data import get_async_session
from fetch_data.api_data.log_data.fetch_log_data import (
Expand Down Expand Up @@ -85,7 +85,7 @@ async def create_log_observation(wikibase_id: int) -> bool:


async def create_log_month(
wikibase: WikibaseModel, log_list: List[WikibaseLogRecord]
wikibase: WikibaseModel, log_list: Iterable[WikibaseLogRecord]
) -> WikibaseLogMonthObservationModel:
"""Create Log Month"""

Expand Down
10 changes: 5 additions & 5 deletions fetch_data/api_data/log_data/fetch_log_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Fetch Log Data"""

from datetime import datetime
from typing import List, Optional
from typing import Optional
from fetch_data.api_data.log_data.wikibase_log_record import WikibaseLogRecord
from fetch_data.utils import dict_to_url, fetch_api_data

Expand All @@ -24,10 +24,10 @@ def get_log_param_string(
return dict_to_url(parameters)


def get_log_list_from_url(url: str) -> List[WikibaseLogRecord]:
def get_log_list_from_url(url: str) -> list[WikibaseLogRecord]:
"""Get Log List from URL"""

data = []
data: list[WikibaseLogRecord] = []

query_data = fetch_api_data(url)
for record in query_data["query"]["logevents"]:
Expand All @@ -38,10 +38,10 @@ def get_log_list_from_url(url: str) -> List[WikibaseLogRecord]:

def get_month_log_list(
api_url: str, comparison_date: datetime, oldest: bool = False
) -> List[WikibaseLogRecord]:
) -> list[WikibaseLogRecord]:
"""Get Log List from api_url, limit to within 30 days of the comparison date"""

data: List[WikibaseLogRecord] = []
data: list[WikibaseLogRecord] = []
limit = 500

should_query = True
Expand Down
2 changes: 1 addition & 1 deletion fetch_data/api_data/user_data/fetch_multiple_user_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Fetch Multiple User Data"""

from collections.abc import Iterable
import json
from typing import Iterable
import requests
from fetch_data.api_data.user_data.user_data_url import user_url
from model.database import WikibaseModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Create Software Version Observation"""

from collections.abc import Iterable
from datetime import datetime
from typing import List
from urllib.error import HTTPError
from bs4 import BeautifulSoup, Tag
import requests
Expand Down Expand Up @@ -73,7 +73,7 @@ async def create_software_version_observation(

async def compile_extension_versions(
async_session: AsyncSession, soup: BeautifulSoup
) -> List[WikibaseSoftwareVersionModel]:
) -> list[WikibaseSoftwareVersionModel]:
"""Compile Extension Version List"""

extensions_table = soup.find(
Expand All @@ -93,12 +93,12 @@ async def compile_extension_versions(

async def compile_installed_software_versions(
async_session: AsyncSession, soup: BeautifulSoup
) -> List[WikibaseSoftwareVersionModel]:
) -> list[WikibaseSoftwareVersionModel]:
"""Compile Installed Software Version List"""

installed_software_table: Tag = soup.find("table", attrs={"id": "sv-software"})

software_versions: List[WikibaseSoftwareVersionModel] = []
software_versions: list[WikibaseSoftwareVersionModel] = []
row: Tag
for row in installed_software_table.find_all("tr"):
if row.find("td"):
Expand Down Expand Up @@ -141,12 +141,12 @@ async def compile_installed_software_versions(

async def compile_library_versions(
async_session: AsyncSession, soup: BeautifulSoup
) -> List[WikibaseSoftwareVersionModel]:
) -> list[WikibaseSoftwareVersionModel]:
"""Compile Library Version List"""

libraries_table = soup.find("table", attrs={"id": "sv-libraries"})

library_versions: List[WikibaseSoftwareVersionModel] = []
library_versions: list[WikibaseSoftwareVersionModel] = []
row: Tag
for row in libraries_table.find_all("tr"):
if row.find("td"):
Expand All @@ -169,7 +169,7 @@ async def compile_library_versions(

async def compile_skin_versions(
async_session: AsyncSession, soup: BeautifulSoup
) -> List[WikibaseSoftwareVersionModel]:
) -> list[WikibaseSoftwareVersionModel]:
"""Compile Skin Version List"""

installed_skin_table: Tag = soup.find(
Expand Down Expand Up @@ -237,8 +237,8 @@ async def get_software_version_from_row(


def unique_versions(
input_list: List[WikibaseSoftwareVersionModel],
) -> List[WikibaseSoftwareVersionModel]:
input_list: Iterable[WikibaseSoftwareVersionModel],
) -> list[WikibaseSoftwareVersionModel]:
"""Unique Version List"""

temp: dict[str, WikibaseSoftwareVersionModel] = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Compile Connectivity Distance"""

from typing import Iterable, List
from collections.abc import Iterable
from tqdm import tqdm


def compile_distance_dict(
all_nodes: List[str], link_dict: dict[str, set[str]]
all_nodes: Iterable[str], link_dict: dict[str, set[str]]
) -> dict[str, dict[str, int]]:
"""Compile Distance Dictionary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Compile Link Dictionary"""

from typing import List
from collections.abc import Iterable
from fetch_data.sparql_data.sparql_queries import ItemLink


def compile_link_dict(
clean_data: List[ItemLink], all_nodes: List[str], reverse: bool = False
clean_data: Iterable[ItemLink], all_nodes: Iterable[str], reverse: bool = False
) -> dict[str, set[str]]:
"""Compile Link Dictionary
Expand Down
3 changes: 1 addition & 2 deletions fetch_data/sparql_data/sparql_queries/item_links.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Links between items"""

import re
from typing import List


ITEM_LINKS_QUERY = """SELECT ?item ?object WHERE {
Expand Down Expand Up @@ -36,7 +35,7 @@ def clean_point(point: dict) -> ItemLink:
)


def clean_item_link_data(results: dict) -> List[ItemLink]:
def clean_item_link_data(results: dict) -> list[ItemLink]:
"""Query Results to list of data"""

return [clean_point(p) for p in results["results"]["bindings"]]
3 changes: 2 additions & 1 deletion fetch_data/utils/counts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Counts"""

from typing import Iterable, TypeVar
from collections.abc import Iterable
from typing import TypeVar


T = TypeVar("T")
Expand Down
3 changes: 1 addition & 2 deletions model/database/wikibase_category_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Wikibase Category Table"""

from typing import List
from sqlalchemy import Enum, Integer, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship

Expand All @@ -18,7 +17,7 @@ class WikibaseCategoryModel(ModelBase):
id: Mapped[int] = mapped_column("id", Integer, primary_key=True, autoincrement=True)
"""ID"""

wikibases: Mapped[List["WikibaseModel"]] = relationship(
wikibases: Mapped[list["WikibaseModel"]] = relationship(
"WikibaseModel", lazy="selectin", back_populates="category"
)
"""Wikibases"""
Expand Down
16 changes: 8 additions & 8 deletions model/database/wikibase_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Wikibase Table"""

from typing import List, Optional
from typing import Optional
from sqlalchemy import Boolean, ForeignKey, Integer, String, and_
from sqlalchemy.orm import Mapped, mapped_column, relationship

Expand Down Expand Up @@ -212,7 +212,7 @@ class WikibaseModel(ModelBase):
)
"""Special:Version URL"""

connectivity_observations: Mapped[List[WikibaseConnectivityObservationModel]] = (
connectivity_observations: Mapped[list[WikibaseConnectivityObservationModel]] = (
relationship(
"WikibaseConnectivityObservationModel",
back_populates="wikibase",
Expand All @@ -221,37 +221,37 @@ class WikibaseModel(ModelBase):
)
"""Connectivity Observations"""

log_observations: Mapped[List[WikibaseLogObservationModel]] = relationship(
log_observations: Mapped[list[WikibaseLogObservationModel]] = relationship(
"WikibaseLogObservationModel", back_populates="wikibase", lazy="select"
)
"""Log Observations"""

property_popularity_observations: Mapped[
List[WikibasePropertyPopularityObservationModel]
list[WikibasePropertyPopularityObservationModel]
] = relationship(
"WikibasePropertyPopularityObservationModel",
back_populates="wikibase",
lazy="select",
)
"""Property Popularity Observations"""

quantity_observations: Mapped[List[WikibaseQuantityObservationModel]] = (
quantity_observations: Mapped[list[WikibaseQuantityObservationModel]] = (
relationship(
"WikibaseQuantityObservationModel", back_populates="wikibase", lazy="select"
)
)
"""Quantity Observations"""

software_version_observations: Mapped[
List[WikibaseSoftwareVersionObservationModel]
list[WikibaseSoftwareVersionObservationModel]
] = relationship(
"WikibaseSoftwareVersionObservationModel",
back_populates="wikibase",
lazy="select",
)
"""Software Version Observations"""

statistics_observations: Mapped[List[WikibaseStatisticsObservationModel]] = (
statistics_observations: Mapped[list[WikibaseStatisticsObservationModel]] = (
relationship(
"WikibaseStatisticsObservationModel",
back_populates="wikibase",
Expand All @@ -260,7 +260,7 @@ class WikibaseModel(ModelBase):
)
"""Statistics Observations"""

user_observations: Mapped[List[WikibaseUserObservationModel]] = relationship(
user_observations: Mapped[list[WikibaseUserObservationModel]] = relationship(
"WikibaseUserObservationModel", back_populates="wikibase", lazy="select"
)
"""User Observations"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Wikibase Connectivity Observation Table"""

from typing import List, Optional
from typing import Optional
from sqlalchemy import Double, Integer
from sqlalchemy.orm import Mapped, mapped_column, relationship

Expand Down Expand Up @@ -37,7 +37,7 @@ class WikibaseConnectivityObservationModel(ModelBase, WikibaseObservationModel):
"""Average steps for item -> item connections, ignoring disconnected items"""

item_relationship_count_observations: Mapped[
List[WikibaseConnectivityObservationItemRelationshipCountModel]
list[WikibaseConnectivityObservationItemRelationshipCountModel]
] = relationship(
"WikibaseConnectivityObservationItemRelationshipCountModel",
back_populates="connectivity_observation",
Expand All @@ -46,7 +46,7 @@ class WikibaseConnectivityObservationModel(ModelBase, WikibaseObservationModel):
"""Item / Relationship Count Observations"""

object_relationship_count_observations: Mapped[
List[WikibaseConnectivityObservationObjectRelationshipCountModel]
list[WikibaseConnectivityObservationObjectRelationshipCountModel]
] = relationship(
"WikibaseConnectivityObservationObjectRelationshipCountModel",
back_populates="connectivity_observation",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Wikibase Log Month Observation Table"""

from datetime import datetime
from typing import List, Optional
from typing import Optional
from sqlalchemy import DateTime, Integer
from sqlalchemy.orm import Mapped, mapped_column, relationship

Expand Down Expand Up @@ -43,12 +43,12 @@ class WikibaseLogMonthObservationModel(ModelBase):
)
"""Number of Unique Users, Without Bots"""

log_type_records: Mapped[List[WikibaseLogMonthLogTypeObservationModel]] = (
log_type_records: Mapped[list[WikibaseLogMonthLogTypeObservationModel]] = (
relationship("WikibaseLogMonthLogTypeObservationModel", lazy="selectin")
)
"""Log Type Observations"""

user_type_records: Mapped[List[WikibaseLogMonthUserTypeObservationModel]] = (
user_type_records: Mapped[list[WikibaseLogMonthUserTypeObservationModel]] = (
relationship("WikibaseLogMonthUserTypeObservationModel", lazy="selectin")
)
"""User Type Observations"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Wikibase Property Popularity Observation Table"""

from typing import List
from sqlalchemy.orm import Mapped, relationship

from model.database.base import ModelBase
Expand All @@ -17,7 +16,7 @@ class WikibasePropertyPopularityObservationModel(ModelBase, WikibaseObservationM

__tablename__ = "wikibase_property_usage_observation"

property_count_observations: Mapped[List[WikibasePropertyPopularityCountModel]] = (
property_count_observations: Mapped[list[WikibasePropertyPopularityCountModel]] = (
relationship(
"WikibasePropertyPopularityCountModel",
back_populates="wikibase_property_popularity_observation",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Wikibase User Group Table"""

from typing import List
from sqlalchemy import Boolean, Integer, String, UniqueConstraint
from sqlalchemy.orm import Mapped, mapped_column, relationship

Expand All @@ -27,7 +26,7 @@ class WikibaseUserGroupModel(ModelBase):
)
"""Wikibase Default?"""

user_group_observations: Mapped[List[WikibaseUserObservationGroupModel]] = (
user_group_observations: Mapped[list[WikibaseUserObservationGroupModel]] = (
relationship(
"WikibaseUserObservationGroupModel",
back_populates="user_group",
Expand Down
Loading

0 comments on commit ef9aa37

Please sign in to comment.