Skip to content

Commit

Permalink
dev: Remove all the excluded ruff rules except E501 (#235)
Browse files Browse the repository at this point in the history
* fix most of the F and E rules post excluding test

* fix the unused import rule

* remove this comment bit

* merge main, update comment
  • Loading branch information
ajay-sentry authored Jun 4, 2024
1 parent 5da2084 commit 95c7e98
Show file tree
Hide file tree
Showing 33 changed files with 67 additions and 49 deletions.
3 changes: 2 additions & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ exclude = [
"node_modules",
"site-packages",
"venv",
"**test**"
]

# Same as Black.
Expand All @@ -39,7 +40,7 @@ target-version = "py312"
# Currently only enabled for F (Pyflakes), I (isort), E (pycodestyle:Error), PLC (Pylint:Convention)
# and PLE (Pylint:Error) rules: https://docs.astral.sh/ruff/rules/
select = ["F", "I", "E", "PLC", "PLE"]
ignore = ["F841", "F401","F405", "F403", "E501", "E712", "E711", "E741"]
ignore = ["E501"]

# Allow fix for all enabled rules (when `--fix`) is provided.
# The preferred method (for now) w.r.t. fixable rules is to manually update the makefile
Expand Down
1 change: 0 additions & 1 deletion shared/api_archive/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from django.conf import settings
from django.utils import timezone
from minio import Minio

from shared.api_archive.storage import StorageService
from shared.config import get_config
Expand Down
18 changes: 18 additions & 0 deletions shared/bundle_analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,21 @@
ModuleReport,
)
from shared.bundle_analysis.storage import BundleAnalysisReportLoader, StoragePaths

__all__ = [
"models",
"AssetChange",
"BundleAnalysisComparison",
"BundleChange",
"BundleComparison",
"MissingBaseReportError",
"MissingBundleError",
"MissingHeadReportError",
"Parser",
"AssetReport",
"BundleAnalysisReport",
"BundleReport",
"ModuleReport",
"BundleAnalysisReportLoader",
"StoragePaths",
]
2 changes: 1 addition & 1 deletion shared/bundle_analysis/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from enum import Enum
from typing import List, Optional
from typing import Optional

import sqlalchemy
from sqlalchemy import Column, ForeignKey, Table, create_engine, types
Expand Down
3 changes: 1 addition & 2 deletions shared/bundle_analysis/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import logging
import re
import uuid
from typing import Optional, Tuple
from typing import Tuple

import ijson
from sqlalchemy.orm import Session as DbSession

from shared.bundle_analysis.models import (
SCHEMA,
Asset,
AssetType,
Bundle,
Expand Down
2 changes: 1 addition & 1 deletion shared/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _env_var_value_cast(self, data):
elif re.match(r"^-?\d+\.\d+$", data):
try:
return float(data)
except ValueError as e:
except ValueError:
pass

return data
Expand Down
1 change: 0 additions & 1 deletion shared/django_apps/codecov_auth/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import django.contrib.postgres.fields
import django.contrib.postgres.fields.citext
import django.db.models.deletion
from django.conf import settings
from django.contrib.postgres.operations import CITextExtension
from django.db import migrations, models

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import django.contrib.postgres.fields
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 3.1.13 on 2021-11-23 15:35

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

from shared.django_apps.codecov_auth.models import _generate_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import django.contrib.postgres.fields
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import uuid

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import uuid

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 3.2.12 on 2023-01-19 19:06

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 4.1.7 on 2023-05-22 17:53

import uuid

import django.contrib.postgres.fields.citext
import django.db.models.deletion
Expand Down
2 changes: 0 additions & 2 deletions shared/django_apps/core/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.db.models import (
Avg,
Count,
DateTimeField,
F,
FloatField,
IntegerField,
Expand Down Expand Up @@ -132,7 +131,6 @@ def with_latest_coverage_change(self):
branch) of each repository. Depends on having called "with_latest_commit_totals_before" with
"include_previous_totals=True".
"""
from shared.django_apps.core.models import Commit

return self.annotate(
latest_coverage=Cast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from django.db import migrations

from shared.django_apps.migration_utils import RiskyRemoveField


class Migration(migrations.Migration):
dependencies = [
Expand Down
4 changes: 2 additions & 2 deletions shared/django_apps/dummy_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pathlib import Path

from shared.django_apps.db_settings import *
from shared.django_apps.db_settings import * # noqa: F403

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent
Expand Down Expand Up @@ -61,7 +61,7 @@
AUTH_USER_MODEL = "codecov_auth.User"

# Needed as certain migrations refer to it
SKIP_RISKY_MIGRATION_STEPS = get_config("migrations", "skip_risky_steps", default=False)
SKIP_RISKY_MIGRATION_STEPS = get_config("migrations", "skip_risky_steps", default=False) # noqa: F405

TEST = True

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 3.1.6 on 2021-03-15 20:15

from django.conf import settings
from django.db import migrations

from shared.django_apps.legacy_migrations.migrations.legacy_sql.main.main import (
Expand Down
10 changes: 10 additions & 0 deletions shared/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@
metrics = statsd

start_prometheus = start_http_server


__all__ = [
"Counter",
"Histogram",
"Summary",
"statsd",
"metrics",
"start_prometheus",
]
8 changes: 4 additions & 4 deletions shared/reports/filtered.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ def calculate_diff(self, all_file_segments):
[
(i, fg(i))
for i, line in enumerate(
[l for l in segment["lines"] if l[0] != "-"],
[ln for ln in segment["lines"] if ln[0] != "-"],
start=int(segment["header"][2]) or 1,
)
if line[0] == "+"
]
)
for segment in all_file_segments
]
lines = [l for l in lines if l[1] is not None]
lines = [ln for ln in lines if ln[1] is not None]
return self.calculate_totals_from_lines(lines)

def get(self, ln):
Expand All @@ -112,9 +112,9 @@ def _process_totals(self):
return self.calculate_totals_from_lines(self.lines)

@classmethod
def sum_of_complexity(cls, l):
def sum_of_complexity(cls, ln):
# (hit, total)
c = l[1].complexity
c = ln[1].complexity
if not c:
# no coverage data provided
return (0, 0)
Expand Down
12 changes: 6 additions & 6 deletions shared/reports/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def calculate_diff(self, all_file_segments):
[
fg(i)
for i, line in enumerate(
[l for l in segment["lines"] if l[0] != "-"],
[ln for ln in segment["lines"] if ln[0] != "-"],
start=int(segment["header"][2]) or 1,
)
if line[0] == "+"
Expand Down Expand Up @@ -436,9 +436,9 @@ def _process_totals(self) -> ReportTotals:
partials = cov.count(LineType.partial)
total_lines = hits + misses + partials

def sum_of_complexity(l):
def sum_of_complexity(ln):
# (hit, total)
c = l[1].complexity
c = ln[1].complexity
if not c:
# no coverage data provided
return (0, 0)
Expand Down Expand Up @@ -1480,12 +1480,12 @@ def _ignore_to_func(ignore):
if eof:
if isinstance(eof, str):
# Sometimes eof is 'N', not sure which cases
return lambda l: str(l) > eof or l in lines
return lambda ln: str(ln) > eof or ln in lines
# This means the eof as a number: the last line of the file and
# anything after that should be ignored
return lambda l: l > eof or l in lines
return lambda ln: ln > eof or ln in lines
else:
return lambda l: l in lines
return lambda ln: ln in lines


def _dumps_not_none(value):
Expand Down
2 changes: 1 addition & 1 deletion shared/reports/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def __bool__(self):
return self.session_count > 0

def append(self, totals: SessionTotals):
if totals == None:
if totals is None:
log.warning("Trying to append None session total to SessionTotalsArray")
return
new_totals_index = self.session_count
Expand Down
1 change: 0 additions & 1 deletion shared/rollouts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import logging
import os
from enum import Enum
from functools import cached_property
from typing import Optional

Expand Down
9 changes: 4 additions & 5 deletions shared/storage/aws.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import gzip
import logging
from io import BytesIO

import boto3
from botocore.exceptions import ClientError
Expand Down Expand Up @@ -167,9 +166,9 @@ def delete_file(self, bucket_name, path):
bool: True if the deletion was succesful
"""
try:
response = self.storage_client.delete_object(Bucket=bucket_name, Key=path)
self.storage_client.delete_object(Bucket=bucket_name, Key=path)
return True
except ClientError as e:
except ClientError:
raise

def delete_files(self, bucket_name, paths=[]):
Expand All @@ -195,7 +194,7 @@ def delete_files(self, bucket_name, paths=[]):
response = self.storage_client.delete_objects(
Bucket=bucket_name, Delete=objects_to_delete
)
except ClientError as e:
except ClientError:
raise
deletes = [error.get("Key") for error in response.get("Deleted")]
return [key in deletes for key in paths]
Expand All @@ -215,7 +214,7 @@ def list_folder_contents(self, bucket_name, prefix=None, recursive=True):
response = self.storage_client.list_objects(
Bucket=bucket_name, Prefix=prefix
)
except ClientError as e:
except ClientError:
raise
contents = response.get("Contents")
return [
Expand Down
1 change: 0 additions & 1 deletion shared/storage/gcp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import gzip
import logging
from io import BytesIO

import google.cloud.exceptions
from google.cloud import storage
Expand Down
2 changes: 1 addition & 1 deletion shared/storage/minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def read_file(self, bucket_name, path, file_obj=None):
f"File {path} does not exist in {bucket_name}"
)
raise e
except MinioException as e:
except MinioException:
raise

"""
Expand Down
4 changes: 2 additions & 2 deletions shared/torngit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def diff_to_json(self, diff):
elif sol4 == "@@ -":
# ex: "@@ -31,8 +31,8 @@ blah blah blah"
# ex: "@@ -0,0 +1 @@"
l = get_start_of_line(source).groups()
segment = dict(header=[l[0], l[1], l[2], l[3]], lines=[])
ln = get_start_of_line(source).groups()
segment = dict(header=[ln[0], ln[1], ln[2], ln[3]], lines=[])
_file["segments"].append(segment)

elif source == "":
Expand Down
4 changes: 2 additions & 2 deletions shared/torngit/bitbucket.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
import urllib.parse as urllib_parse
from typing import List, Optional
from typing import List

import httpx
from oauthlib import oauth1
Expand Down Expand Up @@ -802,7 +802,7 @@ async def find_pull_request(
self, commit=None, branch=None, state="open", token=None
):
state = {"open": "OPEN", "merged": "MERGED", "close": "DECLINED"}.get(state, "")
pulls, page = [], 0
page = 0
async with self.get_client() as client:
if commit or branch:
while True:
Expand Down
4 changes: 2 additions & 2 deletions shared/torngit/bitbucket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def diff_to_json(self, diff_json):
_file["segments"].append(segment)
for seg in hunk["segments"]:
t = seg["type"][0]
for l in seg["lines"]:
for ln in seg["lines"]:
segment["lines"].append(
("-" if t == "R" else "+" if t == "A" else " ")
+ l["line"]
+ ln["line"]
)

if results:
Expand Down
2 changes: 1 addition & 1 deletion shared/torngit/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ async def set_commit_status(
),
token=token,
)
except TorngitClientError as ce:
except TorngitClientError:
raise
if merge_commit:
api_url = self.count_and_get_url_template(
Expand Down
2 changes: 1 addition & 1 deletion shared/typings/oauth_token_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Awaitable, Callable, Optional, TypedDict
from typing import Awaitable, Callable, Optional, TypedDict


class Token(TypedDict):
Expand Down
Loading

0 comments on commit 95c7e98

Please sign in to comment.