Skip to content

Commit

Permalink
Remove unused import with ruff
Browse files Browse the repository at this point in the history
In particular, I was interested in F401. This should clean up all unused imports in the repo.
We have to be careful with celery tasks because they don't get picked up if they are not "imported" anywhere.
I've added an annotation on the `__init__` files that import these "unused" tasks.
  • Loading branch information
michelletran-codecov committed May 2, 2024
1 parent cad2709 commit 6624bbd
Show file tree
Hide file tree
Showing 184 changed files with 243 additions and 453 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ background_app/.report.json
# Vim temporary files
*.swp
*.swo

# Pycharm/Intellij
.idea/
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ update-requirements:

lint.install:
echo "Installing..."
pip install -Iv black==22.3.0 isort
pip install -Iv ruff

lint.run:
black .
isort --profile black .
ruff check --select F401 --select I . --fix
ruff format

lint.check:
echo "Linting..."
black --check .
ruff format --check
echo "Sorting..."
isort --profile black --check .
ruff check --select F401 --select I .

build.requirements:
# if docker pull succeeds, we have already build this version of
Expand Down
1 change: 0 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import django
from celery import Celery, signals

import database.events
from helpers.logging_config import get_logging_config_dict
from helpers.sentry import initialize_sentry, is_sentry_enabled

Expand Down
1 change: 0 additions & 1 deletion celery_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import logging.config
import os
import re
from datetime import timedelta

from celery import signals
Expand Down
1 change: 0 additions & 1 deletion database/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@


class CodecovBaseModel(Base):

__abstract__ = True

def get_db_session(self):
Expand Down
1 change: 0 additions & 1 deletion database/models/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from sqlalchemy.dialects import postgresql
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import backref, relationship
from test_results_parser import Outcome

from database.base import CodecovBaseModel, MixinBaseClass
from database.models.core import Commit, CompareCommit, Repository
Expand Down
1 change: 0 additions & 1 deletion database/models/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class TimeseriesBaseModel(CodecovBaseModel):

__abstract__ = True


Expand Down
2 changes: 0 additions & 2 deletions database/tests/factories/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class ProfilingCommitFactory(factory.Factory):

version_identifier = factory.Faker("slug")
repository = factory.SubFactory(RepositoryFactory)

Expand All @@ -14,7 +13,6 @@ class Meta:


class ProfilingUploadFactory(factory.Factory):

profiling_commit = factory.SubFactory(ProfilingCommitFactory)

class Meta:
Expand Down
1 change: 0 additions & 1 deletion database/tests/factories/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class RepositoryFlagFactory(factory.Factory):

repository = factory.SubFactory(RepositoryFactory)
flag_name = factory.Sequence(lambda n: f"flag{n}")

Expand Down
2 changes: 0 additions & 2 deletions database/tests/factories/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class MeasurementFactory(factory.Factory):

owner_id = 1
repo_id = 1
name = "testing"
Expand All @@ -20,7 +19,6 @@ class Meta:


class DatasetFactory(factory.Factory):

repository_id = 1
name = "testing"
backfilled = False
Expand Down
4 changes: 1 addition & 3 deletions database/tests/unit/test_events.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os

import pytest

import database.events
import database.events # noqa: F401
from database.tests.factories import RepositoryFactory


Expand Down
2 changes: 0 additions & 2 deletions database/tests/unit/test_model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from unittest.mock import PropertyMock

from shared.storage.exceptions import FileNotInStorageError
from shared.utils.ReportEncoder import ReportEncoder

from database.models.core import Commit
from database.tests.factories.core import CommitFactory
Expand All @@ -11,7 +10,6 @@

class TestArchiveField(object):
class ClassWithArchiveField(object):

commit: Commit
id = 1
external_id = "external_id"
Expand Down
1 change: 0 additions & 1 deletion database/tests/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def test_updatestamp_update(self, dbsession):


class TestReportDetailsModel(object):

sample_files_array = [
{
"filename": "file_1.go",
Expand Down
2 changes: 0 additions & 2 deletions database/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import json
import logging
import time
from contextlib import contextmanager
from functools import lru_cache
from typing import Any, Callable, Optional

from shared.storage.exceptions import FileNotInStorageError
Expand Down
2 changes: 1 addition & 1 deletion enterprise/hooks/hook-opentelemetry.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from PyInstaller.utils.hooks import collect_all, copy_metadata
from PyInstaller.utils.hooks import copy_metadata

datas = copy_metadata("opentelemetry-sdk")
1 change: 1 addition & 0 deletions helpers/backfills.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

log = logging.getLogger(__name__)


# GH App Backfills
# Looping and adding all repositories in the installation app
def add_repos_service_ids_from_provider(
Expand Down
6 changes: 4 additions & 2 deletions helpers/checkpoint_logger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import itertools
import logging
import time
from enum import Enum, auto
from enum import Enum
from typing import (
Any,
Callable,
Expand Down Expand Up @@ -114,7 +114,9 @@ class BaseFlow(str, Enum):
is_failure: ClassVar[Callable[[T], bool]]
log_counters: ClassVar[Callable[[T], None]]

def _generate_next_value_(name: str, start: int, count: int, last_values: list[Any]): # type: ignore[override]
def _generate_next_value_(
name: str, start: int, count: int, last_values: list[Any]
): # type: ignore[override]
"""
This powers `enum.auto()`. It sets the value of "MyEnum.A" to "A".
"""
Expand Down
2 changes: 0 additions & 2 deletions helpers/github_installation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Optional

from sqlalchemy.orm import Session

from database.models.core import (
Expand Down
1 change: 1 addition & 0 deletions helpers/pathmap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# ruff: noqa: F401
from helpers.pathmap.pathmap import _check_ancestors, _resolve_path, clean_path

from .tree import Tree
Expand Down
2 changes: 0 additions & 2 deletions helpers/pathmap/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import operator
from difflib import SequenceMatcher

from .utils import _extract_match


class Tree:
def __init__(self, *args, **kwargs):
Expand Down
5 changes: 2 additions & 3 deletions helpers/tests/unit/test_checkpoint_logger.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import json
import unittest
from enum import Enum, auto
from unittest.mock import ANY, patch
from enum import auto
from unittest.mock import patch

import pytest
import sentry_sdk
from prometheus_client import REGISTRY
from shared.utils.test_utils import mock_metrics

Expand Down
2 changes: 0 additions & 2 deletions helpers/tests/unit/test_environment.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
from pathlib import PosixPath

from shared.config import get_config

from helpers.environment import (
Environment,
_calculate_current_env,
Expand Down
2 changes: 0 additions & 2 deletions helpers/tests/unit/test_logging_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from helpers.environment import Environment
from helpers.logging_config import (
CustomLocalJsonFormatter,
Expand Down
3 changes: 0 additions & 3 deletions helpers/tests/unit/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
from unittest.mock import Mock

import pytest
from shared.django_apps.pg_telemetry.models import SimpleMetric as PgSimpleMetric
from shared.django_apps.ts_telemetry.models import SimpleMetric as TsSimpleMetric

from database.models import Commit
from database.tests.factories.core import CommitFactory, OwnerFactory, RepositoryFactory
from helpers.telemetry import MetricContext, TimeseriesTimer, fire_and_forget

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
2 changes: 0 additions & 2 deletions rollouts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from shared.rollouts import Feature

from database.models import Owner, Repository

# Declare the feature variants and parameters via Django Admin
LIST_REPOS_GENERATOR_BY_OWNER_ID = Feature("list_repos_generator")

Expand Down
3 changes: 0 additions & 3 deletions services/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
from datetime import datetime
from enum import Enum
from hashlib import md5
from typing import Dict, Optional
from uuid import uuid4

from shared.config import get_config
from shared.storage.base import BaseStorageService
from shared.storage.exceptions import FileNotInStorageError
from shared.utils.ReportEncoder import ReportEncoder

from helpers.metrics import metrics
Expand Down Expand Up @@ -40,7 +38,6 @@ def get_path(self, **kwaargs) -> str:
# Service class for performing archive operations. Meant to work against the
# underlying StorageService
class ArchiveService(object):

"""
The root level of the archive. In s3 terms,
this would be the name of the bucket
Expand Down
6 changes: 2 additions & 4 deletions services/bots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import random
from datetime import datetime, timezone
from typing import Dict, List, Optional, Tuple, TypedDict
from typing import Dict, List, Optional, Tuple

from shared.config import get_config
from shared.github import is_installation_rate_limited
Expand Down Expand Up @@ -104,9 +104,8 @@ def get_owner_installation_id(
# using the installations to list these values
# We have this secondary value because `deprecated_using_integration` is... deprecated
# And might get out-of-sync soon
ignore_installation: bool = False
ignore_installation: bool = False,
) -> Optional[Dict]:

log.info(
"Getting owner installation id",
extra=dict(
Expand Down Expand Up @@ -174,7 +173,6 @@ def get_repo_appropriate_bot_token(
repo: Repository,
installation_info: Optional[Dict] = None,
) -> Tuple[Dict, Optional[Owner]]:

log.info(
"Get repo appropriate bot token",
extra=dict(
Expand Down
4 changes: 0 additions & 4 deletions services/comparison/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
from shared.reports.changes import get_changes_using_rust, run_comparison_using_rust
from shared.reports.types import Change
from shared.torngit.exceptions import (
TorngitClientError,
TorngitClientGeneralError,
TorngitError,
TorngitObjectNotFoundError,
)

from database.enums import CompareCommitState, TestResultsProcessingError
Expand All @@ -33,7 +30,6 @@ class NotificationContext(object):


class ComparisonProxy(object):

"""The idea of this class is to produce a wrapper around Comparison with functionalities that
are useful to the notifications context.
Expand Down
10 changes: 7 additions & 3 deletions services/comparison/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,13 @@ def iter_changed_lines(
# we have a head line
if line_has_changed(base_line, head_line):
# unexpected: coverage data changed
yield ln if yield_line_numbers else (
base_line.coverage,
head_line.coverage,
yield (
ln
if yield_line_numbers
else (
base_line.coverage,
head_line.coverage,
)
)
# coverage data remains the same
else:
Expand Down
1 change: 0 additions & 1 deletion services/comparison/tests/unit/test_comparison_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def make_sample_comparison(adjusted_base=False):


class TestComparisonProxy(object):

compare_url = "https://api.github.com/repos/{}/compare/{}...{}"

@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion services/comparison/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from shared.reports.resources import Report
from shared.yaml import UserYaml

from database.models import Commit, Pull
from database.models import Commit
from services.repository import EnrichedPull


Expand Down
3 changes: 1 addition & 2 deletions services/decoration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
from shared.config import get_config
from sqlalchemy import func

from conftest import dbsession
from database.enums import Decoration, ReportType, TrialStatus
from database.models import Commit, Owner, Repository
from database.models.reports import CommitReport, Upload
from services.billing import BillingPlan, is_pr_billing_plan
from services.billing import is_pr_billing_plan
from services.license import requires_license
from services.repository import EnrichedPull

Expand Down
2 changes: 1 addition & 1 deletion services/failure_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(
ignore_predefined=False,
override_predefined=False,
*,
key_analysis_order: Optional[List[str]] = None
key_analysis_order: Optional[List[str]] = None,
):
flags = regex.MULTILINE

Expand Down
1 change: 0 additions & 1 deletion services/flake_detection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from collections import defaultdict
from dataclasses import dataclass
from datetime import datetime, timedelta
from functools import cached_property
from logging import getLogger
from sys import getsizeof

Expand Down

0 comments on commit 6624bbd

Please sign in to comment.