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

dev: Add W, PLC, PLE Ruff Rules #591

Merged
merged 2 commits into from
May 31, 2024
Merged
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
2 changes: 1 addition & 1 deletion api/shared/repo/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RepositoryViewSetMixin(
OwnerPropertyMixin,
viewsets.GenericViewSet,
):
lookup_value_regex = "[\w\.@\:\-~]+"
lookup_value_regex = r"[\w\.@\:\-~]+"
lookup_field = "repo_name"
accessors = RepoAccessors()

Expand Down
2 changes: 1 addition & 1 deletion codecov_auth/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class StateMixin(object):

def __init__(self, *args, **kwargs):
self.redis = get_redis_connection()
return super().__init__(*args, **kwargs)
super().__init__(*args, **kwargs)

def _session_key(self) -> str:
return f"{self.service}_oauth_state"
Expand Down
2 changes: 1 addition & 1 deletion core/migrations/0026_auto_20230605_1134.py
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';
"""
),
]
2 changes: 1 addition & 1 deletion graphql_api/dataloader/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def key(cls, commit):

def __init__(self, info, repository_id, *args, **kwargs):
self.repository_id = repository_id
return super().__init__(info, *args, **kwargs)
super().__init__(info, *args, **kwargs)

def batch_queryset(self, keys):
# We don't select the `report` or `files_array` columns here b/c then can be
Expand Down
2 changes: 1 addition & 1 deletion graphql_api/dataloader/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def key(cls, commit_comparison):

def __init__(self, info, repository_id, *args, **kwargs):
self.repository_id = repository_id
return super().__init__(info, *args, **kwargs)
super().__init__(info, *args, **kwargs)

def batch_queryset(self, keys):
return CommitComparisonService.fetch_precomputed(self.repository_id, keys)
Expand Down
2 changes: 1 addition & 1 deletion graphql_api/tests/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
percentCovered
... on PathContentFile {
isCriticalFile
}
}
}
}
... on MissingHeadReport {
Expand Down
2 changes: 1 addition & 1 deletion graphs/tests/test_badge_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ def test_flag_badge(self, full_report_mock):
data={"flag": "unittests"},
)

expected_badge = """<svg xmlns="http://www.w3.org/2000/svg" width="122" height="20">
expected_badge = """<svg xmlns="http://www.w3.org/2000/svg" width="122" height="20">
<linearGradient id="b" x2="0" y2="100%">
<stop offset="0" stop-color="#bbb" stop-opacity=".1" />
<stop offset="1" stop-opacity=".1" />
Expand Down
2 changes: 1 addition & 1 deletion legacy_migrations/migrations/0002_yaml_history_table.py
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
2 changes: 1 addition & 1 deletion legacy_migrations/migrations/0003_auto_20230120_1837.py
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
4 changes: 2 additions & 2 deletions legacy_migrations/migrations/legacy_sql/upgrades/v442.py
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
32 changes: 16 additions & 16 deletions legacy_migrations/migrations/legacy_sql/upgrades/v443.py
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
4 changes: 2 additions & 2 deletions legacy_migrations/migrations/legacy_sql/upgrades/v448.py
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 owners
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
6 changes: 3 additions & 3 deletions legacy_migrations/migrations/legacy_sql/upgrades/v451.py
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
5 changes: 3 additions & 2 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ indent-width = 4
target-version = "py312"

[lint]
# Currently only enabled for F, I, and E rules, with a few exclusions: https://docs.astral.sh/ruff/rules/
select = ["F", "I", "E"]
# Currently only enabled for F (Pyflakes), I (isort), E,W (pycodestyle:Error/Warning), PLC (Pylint:Convention)
# and PLE (Pylint:Error) rules: https://docs.astral.sh/ruff/rules/
select = ["F", "I", "E", "W", "PLC", "PLE"]
ignore = ["F841", "F401", "F405", "F403", "E501", "E712", "E711"]

# Allow fix for all enabled rules (when `--fix`) is provided.
Expand Down
2 changes: 1 addition & 1 deletion services/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def context(self):
context["Marketo"] = {"marketo_cookie": marketo_cookie}
if ga_cookie:
# id is everything after the "GA.1." prefix
match = re.match("^.+\.(.+?\..+?)$", ga_cookie)
match = re.match(r"^.+\.(.+?\..+?)$", ga_cookie)
if match:
ga_client_id = match.group(1)
context["externalIds"].append(
Expand Down
2 changes: 1 addition & 1 deletion upload/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def determine_repo_for_upload(upload_params):
elif service:
if not using_global_token:
# verify CI TODO

# Get repo info from CI TODO
"""

Expand Down
2 changes: 1 addition & 1 deletion upload/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@
name="new_upload.commits",
),
# This was getting in the way of the new endpoints, so I moved to the end
re_path("(?P<version>\w+)/?", UploadHandler.as_view(), name="upload-handler"),
re_path(r"(?P<version>\w+)/?", UploadHandler.as_view(), name="upload-handler"),
]
Loading