Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single ruff linter #562

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: black Lint
uses: psf/black@stable
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
options: "--check --diff"
src: "."
version: "24.3.0"
- name: isort Lint
uses: isort/isort-action@master
- name: flake8 Lint
uses: py-actions/flake8@v2
python-version: '3.9'
- name: run ruff linter and formatter
run: |
pip install ruff==0.4.9
ruff check .
ruff format . --check
2 changes: 0 additions & 2 deletions hub/management/commands/base_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ class BaseConstituencyGroupListImportCommand(BaseAreaImportCommand):
do_not_convert = True

def process_data(self, df: pd.DataFrame):

if not self._quiet:
self.stdout.write(f"{self.message} ({self.area_type})")

Expand Down Expand Up @@ -372,7 +371,6 @@ def set_data_type(self):
self.data_type = list(self.data_types.values())[0]

def get_dataframe(self):

if not self.data_file.exists():
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def add_area(self, gss):
return None

def get_df(self):

if self.data_file.exists() is False:
return None

Expand Down
5 changes: 2 additions & 3 deletions hub/management/commands/import_air_quality_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Command(BaseCommand):
"pollutant": "NOx",
"metric": "Annual mean",
"header_label": "nox2021",
"comments": "µg m\u207B\u00B3 (NO\u2093 as NO\u2082)",
"comments": "µg m\u207b\u00b3 (NO\u2093 as NO\u2082)",
"csv_link": "https://uk-air.defra.gov.uk/datastore/pcm/mapnox2021.csv",
},
"so_2": {
Expand All @@ -75,7 +75,7 @@ class Command(BaseCommand):
"pollutant": "Ozone",
"metric": "DGT120",
"header_label": "dgt12021",
"comments": "number of days on which the daily max 8-hr concentration is greater than 120 µg m\u207B\u00B3",
"comments": "number of days on which the daily max 8-hr concentration is greater than 120 µg m\u207b\u00b3",
"csv_link": "https://uk-air.defra.gov.uk/datastore/pcm/mapdgt12021.csv",
},
"benzene": {
Expand Down Expand Up @@ -155,7 +155,6 @@ def delete_data(self):
AreaData.objects.filter(data_type__in=self.data_types).delete()

def get_dataframe(self):

if not self.gridcode_lookup_file.exists():
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_brexit_votes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Command(BaseImportFromDataFrameCommand):
}

def get_dataframe(self):

if not self.data_file.exists():
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_brexit_votes_new_cons.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Command(BaseImportFromDataFrameCommand):
}

def get_dataframe(self):

if not self.data_file.exists():
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_cen_nzsg_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def handle(self, quiet=False, *args, **options):
self.import_results()

def get_df(self):

file_loc = Path("data", "cen_nzsg_members.csv")
if not file_loc.exists():
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Command(BaseImportFromDataFrameCommand):
}

def get_dataframe(self):

if self.data_file.exists() is False:
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def build_constituency_name_lookup(self):
return names_lookup_dict

def get_df(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_council_scorecards_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def add_data_sets(self, df):
self.data_types[name] = data_type

def get_dataframe(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_efpc_fuel_poverty_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def delete_data(self):
).delete()

def get_dataframe(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_foe_constituency_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def get_row_data(self, row, conf):
}

def get_dataframe(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_foe_supporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class Command(BaseImportFromDataFrameCommand):
}

def get_dataframe(self):

if self.data_file.exists() is False:
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Command(BaseImportFromDataFrameCommand):
}

def get_dataframe(self):

if self.data_file.exists() is False:
return None

Expand Down
4 changes: 0 additions & 4 deletions hub/management/commands/import_hnh_polling_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,10 @@ def log(self, message):
self.stdout.write(message)

def extract_and_save_data(self):

self.log(self.message)

area_type = self.get_area_type()
for file in self.files:

file_loc = settings.BASE_DIR / "data" / file["source_filename"]

if not file_loc.exists():
Expand Down Expand Up @@ -435,7 +433,6 @@ def delete_data(self):
def update_averages(self):
self.log("Calculating averages for DataTypes:")
for file in self.files:

file_loc = settings.BASE_DIR / "data" / file["source_filename"]

if not file_loc.exists():
Expand Down Expand Up @@ -469,7 +466,6 @@ def update_averages(self):
def update_max_min(self):
self.log("Calculating min/max values for DataTypes:")
for file in self.files:

file_loc = settings.BASE_DIR / "data" / file["source_filename"]

if not file_loc.exists():
Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_last_election_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def get_area_type(self):
return AreaType.objects.get(code=self.area_type)

def get_general_election_data(self):

df = pd.read_csv(
self.general_election_source_file,
usecols=[
Expand Down
2 changes: 0 additions & 2 deletions hub/management/commands/import_mp_job_titles.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def get_area_type(self):
return AreaType.objects.get(code="WMC")

def get_df(self):

if not self.data_file.exists():
self.stderr.write(f"Data file {self.data_file} does not exist")
return None
Expand Down Expand Up @@ -109,7 +108,6 @@ def add_results(self, results, data_type):
PersonData.objects.filter(data_type=data_type).exclude(pk__in=mp_list).delete()

def import_results(self):

df = self.get_df()

if df is None:
Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_mps_appg_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def add_mps(self, df):
return df

def get_climate_appgs(self):

climate_appgs_list = Path("data", "climate_APPGs.txt")

if not climate_appgs_list.exists():
Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_mps_standing_down_2024.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def get_person_from_name(self, name):
return None

def get_df(self):

if not self.data_file.exists():
self.stderr.write(f"Data file {self.data_file} does not exist")
return None
Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_new_constituencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def add_arguments(self, parser):
)

def download_constituencies(self):

source_file = "https://pages.mysociety.org/2025-constituencies/data/parliament_con_2025/latest/parl_constituencies_2025.parquet"
parquet_path = settings.BASE_DIR / "data" / "parl_constituencies_2025.parquet"

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_nt_property_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def get_df(self) -> Optional[pd.DataFrame]:
return pd.read_csv(self.data_file)

def process_data(self, df: pd.DataFrame):

# df.group_name = df.group_name.apply(
# lambda x: x.split(" | ")[0] if type(x) == str else x
# )
Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_onward_polling_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def build_constituency_name_lookup(self):
return names_lookup_dict

def get_dataframe(self):

if not self.data_file.exists():
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class Command(BaseImportFromDataFrameCommand):
}

def get_dataframe(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_rspb_nature_reserves.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class Command(MultipleAreaTypesMixin, BaseConstituencyGroupListImportCommand):
count_data_type = "rspb_reserves_count"

def get_df(self):

if self.data_file.exists() is False:
return None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Command(BaseConstituencyGroupListImportCommand):
count_data_type = "tcc_open_letter_signatories_count"

def get_df(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_wi_group_locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class Command(MultipleAreaTypesMixin, BaseConstituencyGroupListImportCommand):
count_data_type = "constituency_wi_group_count"

def get_df(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_wildlife_trust_reserves.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class Command(MultipleAreaTypesMixin, BaseConstituencyGroupListImportCommand):
}

def get_df(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_wildlife_trusts_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Command(BaseConstituencyGroupListImportCommand):
group_data_type = "wildlife_trusts_regions"

def get_df(self):

if not self.data_file.exists():
return None

Expand Down
1 change: 0 additions & 1 deletion hub/management/commands/import_wwf_supporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Command(BaseImportFromDataFrameCommand):
}

def get_dataframe(self):

if self.data_file.exists() is False:
return None

Expand Down
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys

Expand Down
Loading
Loading