Skip to content

Commit

Permalink
add W and PLW, fix or comment out all errors (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajay-sentry authored Jun 7, 2024
1 parent bf76a73 commit 9de2b01
Show file tree
Hide file tree
Showing 26 changed files with 58 additions and 59 deletions.
6 changes: 3 additions & 3 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ indent-width = 4
target-version = "py312"

[lint]
# 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"]
# Currently only enabled for F (Pyflakes), I (isort), E,W, (pycodestyle:Error/Warning),
# and PLC/E/W (Pylint:Convention/Error/Warning) rules: https://docs.astral.sh/ruff/rules/
select = ["F", "I", "E", "W", "PLC", "PLE", "PLW"]
ignore = ["E501"]

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand Down
2 changes: 1 addition & 1 deletion shared/api_archive/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Service class for interfacing with codecov's underlying storage layer, minio
class StorageService(MinioStorageService):
def __init__(self, in_config=None):
global MINIO_CLIENT
global MINIO_CLIENT # noqa: PLW0603

# init minio
if in_config is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Migration(migrations.Migration):
operations = [
migrations.RunSQL(
"""
ALTER TYPE notifications ADD VALUE IF NOT exists 'codecov_slack_app';
ALTER TYPE notifications ADD VALUE IF NOT exists 'codecov_slack_app';
"""
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Migration(migrations.Migration):
migrations.RunSQL(
sql="""
create index if not exists yaml_history_ownerid_timestamp
on yaml_history (ownerid, timestamp);
on yaml_history (ownerid, timestamp);
""",
reverse_sql="drop index if exists yaml_history_ownerid_timestamp;",
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Migration(migrations.Migration):
migrations.RunSQL(
"""
drop trigger repos_before_update on repos;
create trigger repos_before_update before update on repos
for each row
when (new.name is not null and new.name is distinct from old.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ def run_sql(schema_editor):
SFUNC = _agg_report_totals,
STYPE = text[]
);
"""
)
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def run_sql(schema_editor):
begin
select o.service, o.service_id into _service, _service_id
from owners o where o.ownerid = $1;
if _service = 'gitlab' then
select get_gitlab_repos_activated($1, _service_id) into _repos_activated;
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def run_sql(schema_editor):
create or replace function get_owner(service, citext) returns jsonb as $$
with data as (
select service_id, service, ownerid::text, username, avatar_url,
select service_id, service, ownerid::text, username, avatar_url,
updatestamp, plan, name, integration_id, free,
plan_activated_users, plan_auto_activate, plan_user_count
from owners
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def run_sql(schema_editor):
create or replace function get_users(int[]) returns jsonb as $$
with data as (
select service, service_id::text, ownerid::text, username, name, email, avatar_url
select service, service_id::text, ownerid::text, username, name, email, avatar_url
from owners
where array[ownerid] <@ $1
limit array_length($1, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def run_sql(schema_editor):
if not found then
insert into owners (service, service_id, username, name, email, avatar_url, parent_service_id)
values ($1,
(_team.d->>'id')::text,
(_team.d->>'username')::citext,
(_team.d->>'name')::text,
(_team.d->>'email')::text,
(_team.d->>'avatar_url')::text,
values ($1,
(_team.d->>'id')::text,
(_team.d->>'username')::citext,
(_team.d->>'name')::text,
(_team.d->>'email')::text,
(_team.d->>'avatar_url')::text,
(_team.d->>'parent_id')::text
)
returning ownerid into _ownerid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def run_sql(schema_editor):
schema_editor.execute(
"""
"""
create table branches(
repoid int references repos on delete cascade not null,
updatestamp timestamptz not null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def run_sql(schema_editor):
schema_editor.execute(
"""
"""
create table owners(
ownerid serial primary key,
service service not null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def run_sql(schema_editor):
schema_editor.execute(
"""
"""
create table repos(
repoid serial primary key,
ownerid int references owners on delete cascade not null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def run_sql(schema_editor):
schema_editor.execute(
"""
"""
create table sessions(
sessionid serial primary key,
token uuid unique default uuid_generate_v4() not null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def run_sql(schema_editor):
schema_editor.execute(
"""
"""
CREATE TABLE IF NOT EXISTS "users" (
"id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
"external_id" uuid NOT NULL UNIQUE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
def run_sql(schema_editor):
schema_editor.execute(
"""
"""
create or replace function pulls_drop_flare() returns trigger as $$
begin
new.flare = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def run_sql(schema_editor):
-- get_ownerid.sql
create or replace function get_owner(service, citext) returns jsonb as $$
with data as (
select service_id, service, ownerid::text, username, avatar_url,
select service_id, service, ownerid::text, username, avatar_url,
updatestamp, plan, name, integration_id, free,
plan_activated_users, plan_auto_activate, plan_user_count
from owners
Expand Down Expand Up @@ -60,7 +60,7 @@ def run_sql(schema_editor):
-- get_user.sql
create or replace function get_users(int[]) returns jsonb as $$
with data as (
select service, service_id::text, ownerid::text, username, name, email, avatar_url
select service, service_id::text, ownerid::text, username, name, email, avatar_url
from owners
where array[ownerid] <@ $1
limit array_length($1, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ def run_sql(schema_editor):
begin
select array(
with recursive tree as (
select ownerid,
service_id,
select ownerid,
service_id,
array[]::text[] as ancestors_service_id,
1 as depth
from owners
where parent_service_id is null
and service = 'gitlab'
from owners
where parent_service_id is null
and service = 'gitlab'
and ownerid = $1
union all
select owners.ownerid,
owners.service_id,
select owners.ownerid,
owners.service_id,
tree.ancestors_service_id || owners.parent_service_id,
depth + 1 as depth
from owners, tree
where owners.parent_service_id = tree.service_id
and depth <= 20
)
select ownerid
from tree
select ownerid
from tree
where $2 = any(tree.ancestors_service_id)
) into _decendents_owner_ids;
Expand All @@ -84,7 +84,7 @@ def run_sql(schema_editor):
begin
select o.service, o.service_id into _service, _service_id
from owners o where o.ownerid = $1;
if _service = 'gitlab' then
select get_gitlab_repos_activated($1, _service_id) into _repos_activated;
else
Expand Down Expand Up @@ -147,12 +147,12 @@ def run_sql(schema_editor):
if not found then
insert into owners (service, service_id, username, name, email, avatar_url, parent_service_id)
values ($1,
(_team.d->>'id')::text,
(_team.d->>'username')::citext,
(_team.d->>'name')::text,
(_team.d->>'email')::text,
(_team.d->>'avatar_url')::text,
values ($1,
(_team.d->>'id')::text,
(_team.d->>'username')::citext,
(_team.d->>'name')::text,
(_team.d->>'email')::text,
(_team.d->>'avatar_url')::text,
(_team.d->>'parent_id')::text
)
returning ownerid into _ownerid;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def run_sql(schema_editor):
'v4-10m', 'v4-10y', 'v4-20m', 'v4-20y', 'v4-50m', 'v4-50y', 'v4-125m', 'v4-125y', 'v4-300m', 'v4-300y', -- 'v4-10m', 'v4-10y', 'v4-20m', 'v4-20y', 'v4-50m', 'v4-50y', 'v4-125m', 'v4-125y', 'v4-300m', 'v4-300y',
'users', 'users-inappm', 'users-inappy', 'users-free'); -- 'users', 'users-inappm', 'users-inappy', 'users-free');
-- alter all enum columns
alter table owners
alter table owner;
alter column plan type plans using plan::text::plans;
-- drop the old enum
drop type plans__;
drop type plans__;
ALTER TABLE ONLY owners ALTER COLUMN plan SET DEFAULT 'users-free'; -- ALTER TABLE ONLY owners ALTER COLUMN plan SET DEFAULT 'users-free';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ def run_sql(schema_editor):
-- Here we're commenting out all plan related migrations below because they break on enterprise
-- these migrations have been run already for production, but can break some production
-- deployments. Specifically the setting of the plan column to a new default causes problems with
-- web's ability to migrate effectively in some scenarios.
-- deployments. Specifically the setting of the plan column to a new default causes problems with
-- web's ability to migrate effectively in some scenarios.
-- If you're starting from scratch in dev, you will need to run the below migrations manually,
-- or comment out these migrations before starting up codecov.io for the first time.
-- or comment out these migrations before starting up codecov.io for the first time.
-- This isn't ideal, and will hopefully be addressed when we move all migrations to Django.
Expand Down
2 changes: 1 addition & 1 deletion shared/reports/filtered.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def lines(self):
return self._cached_lines
ret = []
for ln, line in self.report_file.lines:
line = self.line_modifier(line)
line = self.line_modifier(line) # noqa: PLW2901
if line:
ret.append((ln, line))
self._cached_lines = ret
Expand Down
14 changes: 7 additions & 7 deletions shared/reports/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def lines(self):
func = self._line_modifier
for ln, line in enumerate(self._lines, start=1):
if line:
line = self._line(line)
line = self._line(line) # noqa: PLW2901
if func:
line = func(line)
line = func(line) # noqa: PLW2901
if not line:
continue
yield ln, line
Expand Down Expand Up @@ -196,9 +196,9 @@ def __iter__(self):
func = self._line_modifier
for line in self._lines:
if line:
line = self._line(line)
line = self._line(line) # noqa: PLW2901
if func:
line = func(line)
line = func(line) # noqa: PLW2901
if not line:
yield None
yield line
Expand Down Expand Up @@ -294,9 +294,9 @@ def _getslice(self, start, stop):
func = self._line_modifier
for ln, line in enumerate(self._lines[start - 1 : stop - 1], start=start):
if line:
line = self._line(line)
line = self._line(line) # noqa: PLW2901
if func:
line = func(line)
line = func(line) # noqa: PLW2901
if not line:
continue
yield ln, line
Expand Down Expand Up @@ -1377,7 +1377,7 @@ def save_diff_calculation(self, diff, diff_result):
data["totals"] = file_totals
network_file = self._files[filename]
if file_totals.lines == 0:
file_totals = dataclasses.replace(
file_totals = dataclasses.replace( # noqa: PLW2901
file_totals, coverage=None, complexity=None, complexity_total=None
)
network_file.diff_totals = file_totals
Expand Down
1 change: 0 additions & 1 deletion shared/reports/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ def build_from_encoded_data(cls, sessions_array: Union[dict, list]):
for idx, session_totals in enumerate(sessions_array):
if session_totals is not None:
non_null_items[idx] = session_totals
non_null_items = non_null_items
return cls(session_count=session_count, non_null_items=non_null_items)
elif isinstance(sessions_array, cls):
return sessions_array
Expand Down
2 changes: 1 addition & 1 deletion shared/torngit/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from enum import Enum, auto
from enum import Enum
from typing import Dict, List, Optional, Tuple

import httpx
Expand Down
4 changes: 2 additions & 2 deletions shared/torngit/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class GitHubGraphQLQueries(object):
REPOS_FROM_NODEIDS="""
query GetReposFromNodeIds($node_ids: [ID!]!) {
nodes(ids: $node_ids) {
__typename
__typename
... on Repository {
# databaseId == service_id
databaseId
Expand Down Expand Up @@ -1457,7 +1457,7 @@ async def list_teams(self, token=None):
url = self.count_and_get_url_template(
url_name="list_teams_org_name"
).substitute(login=organization["login"])
org = await self.api(client, "get", url, token=token)
org = await self.api(client, "get", url, token=token) # noqa: PLW2901
data.append(
dict(
name=organization.get("name", org["login"]),
Expand Down
2 changes: 1 addition & 1 deletion shared/utils/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def merge_partial_line(p1, p2):
for cov, group in groupby(
sorted([(cl, max(cv)) for cl, cv in list(fl.items())]), lambda c: c[1]
):
group = list(group)
group = list(group) # noqa: PLW2901
append(_ifg(group[0][0], group[-1][0], cov))

# never ends
Expand Down

0 comments on commit 9de2b01

Please sign in to comment.