Skip to content

Commit

Permalink
global: add pre-commit with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalEgn authored and drjova committed Sep 10, 2024
1 parent df7bf82 commit 4247d27
Show file tree
Hide file tree
Showing 623 changed files with 1,814 additions and 2,564 deletions.
31 changes: 16 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
files: ^backend/
repos:
- repo: https://github.com/psf/black
rev: '24.2.0'
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: 'v3.1.0'
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: name-tests-test
args: [ --pytest-test-first ]
exclude: '^(?!factories/)'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.6
hooks:
- id: prettier
- repo: https://github.com/pycqa/isort
rev: '5.13.2'
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: '7.0.0'
hooks:
- id: flake8
args: ['--config=backend/setup.cfg']
- id: ruff
args: [ --fix ]
- id: ruff-format
1 change: 0 additions & 1 deletion backend/gunicorn_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 CERN.
#
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

"""inspirehep."""


from .version import __version__

__all__ = ("__version__",)
1 change: 0 additions & 1 deletion backend/inspirehep/access_control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/accounts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
5 changes: 2 additions & 3 deletions backend/inspirehep/accounts/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down Expand Up @@ -84,8 +83,8 @@ def get_current_user_remote_orcid_account():


def get_allowed_roles_for_collections(collections, read_only=True):
private_collections = set(collections) - (
current_app.config["NON_PRIVATE_LITERATURE_COLLECTIONS"]
private_collections = (
set(collections) - (current_app.config["NON_PRIVATE_LITERATURE_COLLECTIONS"])
)
roles = set()
for col in private_collections:
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/accounts/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 CERN.
#
Expand Down
13 changes: 6 additions & 7 deletions backend/inspirehep/accounts/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 CERN.
#
Expand All @@ -24,9 +23,9 @@
"scope": " ".join(["/read-limited", "/activities/update", "/person/update"]),
"show_login": "true",
}
REMOTE_SANDBOX_REST_APP["signup_handler"][
"setup"
] = "inspirehep.accounts.handlers:account_setup_handler"
REMOTE_SANDBOX_REST_APP["signup_handler"]["setup"] = (
"inspirehep.accounts.handlers:account_setup_handler"
)
# ==============================================================================

# ORCID production =============================================================
Expand All @@ -37,9 +36,9 @@
"scope": " ".join(["/read-limited", "/activities/update", "/person/update"]),
"show_login": "true",
}
REMOTE_REST_APP["signup_handler"][
"setup"
] = "inspirehep.accounts.handlers:account_setup_handler"
REMOTE_REST_APP["signup_handler"]["setup"] = (
"inspirehep.accounts.handlers:account_setup_handler"
)
REMOTE_REST_APP["params"]["access_token_url"] = "https://api.orcid.org/oauth/token"
REMOTE_REST_APP["params"]["authorize_url"] = "https://orcid.org/oauth/authorize"
# ==============================================================================
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/accounts/decorators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/accounts/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
6 changes: 3 additions & 3 deletions backend/inspirehep/accounts/handlers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 CERN.
#
Expand All @@ -12,9 +11,10 @@
from invenio_oauthclient.utils import oauth_link_external_id
from invenio_pidstore.models import PersistentIdentifier

from .api import get_current_user_remote_orcid_account
from inspirehep.accounts.api import get_current_user_remote_orcid_account
from inspirehep.records.utils import get_pid_for_pid


def get_current_user_data():
remote_orcid_account = get_current_user_remote_orcid_account()
orcid_account_extra_data = (
Expand All @@ -26,7 +26,7 @@ def get_current_user_data():
"email": current_user.email,
"roles": [role.name for role in current_user.roles],
"orcid": orcid,
"profile_control_number": get_pid_for_pid('orcid', orcid, 'recid'),
"profile_control_number": get_pid_for_pid("orcid", orcid, "recid"),
"allow_orcid_push": orcid_account_extra_data.get("allow_push"),
}
}
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/accounts/roles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
8 changes: 3 additions & 5 deletions backend/inspirehep/accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 CERN.
#
Expand All @@ -15,13 +14,12 @@
from webargs import fields
from webargs.flaskparser import FlaskParser

from inspirehep.accounts.api import get_current_user_remote_orcid_account
from inspirehep.accounts.decorators import login_required
from inspirehep.accounts.handlers import get_current_user_data
from inspirehep.orcid.tasks import push_account_literature_to_orcid
from inspirehep.serializers import jsonify

from .api import get_current_user_remote_orcid_account
from .decorators import login_required
from .handlers import get_current_user_data

parser = FlaskParser()

blueprint = Blueprint(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""update primary key in students advisors
"""
"""update primary key in students advisors"""

import sqlalchemy as sa
from alembic import op
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand All @@ -9,11 +8,10 @@

import sqlalchemy as sa
from alembic import op
from inspirehep.records.models import AuthorSchemaType
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy_utils import UUIDType

from inspirehep.records.models import AuthorSchemaType

revision = "595c36d68964"
down_revision = "cea5fa2e5d2c"
branch_labels = ()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand All @@ -8,7 +7,6 @@
"""Inspirehep initial revision of migrations
which makes db identical like in inspire-next"""


# revision identifiers, used by Alembic.
revision = "7be4c8b5c5e8"
down_revision = "b5be5fda2ee7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# under the terms of the MIT License; see LICENSE file for more details.

"""add recid to RecordsAuthors id_type"""

from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

"""Add index for ObjectVersion.key"""


# revision identifiers, used by Alembic.
revision = "e5e43ad8f861"
down_revision = "788a3a61a635"
Expand Down
13 changes: 6 additions & 7 deletions backend/inspirehep/assign/tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 CERN.
#
Expand Down Expand Up @@ -117,9 +116,9 @@ def assign_conference(record, conference_ref, cnum):
cnum=cnum,
)
elif cnum == record_cnum:
builder.record["publication_info"][idx][
"conference_record"
] = conference_ref
builder.record["publication_info"][idx]["conference_record"] = (
conference_ref
)
LOGGER.warning(
"conference cnum already assigned to paper without ref.",
recid=record.control_number,
Expand Down Expand Up @@ -226,9 +225,9 @@ def create_rt_ticket_for_claiming_action(
from_author_recid, lit_record.get("authors", [])
)
if matched_author_name:
incompatibile_names_papers[
f"{INSPIREHEP_URL}/literature/{paper_recid}"
] = matched_author_name
incompatibile_names_papers[f"{INSPIREHEP_URL}/literature/{paper_recid}"] = (
matched_author_name
)

to_author_names = []
to_author_names.extend(get_value(to_author_record, "name.name_variants", []))
Expand Down
8 changes: 2 additions & 6 deletions backend/inspirehep/assign/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down Expand Up @@ -117,10 +116,7 @@ def get_last_names(name):
return {unidecode(parsed_name.first)}
# corner case for full names without comma,
# we are treating them as last names (ie. "Smith Davis")
if "," not in name:
names = name.split()
else:
names = parsed_name.last_list
names = name.split() if "," not in name else parsed_name.last_list

return {unidecode(name) for name in names}

Expand Down Expand Up @@ -148,7 +144,7 @@ def _check_names_compability(lit_record, author_parsed_name, last_names_only=Fal
)
matched_authors_recids = [
recid
for recid in lit_authors_names_recids.keys()
for recid in lit_authors_names_recids
if lit_authors_names_recids[recid] == author_name_to_compare
]
if len(matched_authors_recids) == 1:
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/assign/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2020 CERN.
#
Expand Down
3 changes: 1 addition & 2 deletions backend/inspirehep/cds/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 CERN.
#
Expand All @@ -8,13 +7,13 @@

import requests
import structlog
from opensearch_dsl import Q
from flask import current_app
from idutils import is_arxiv
from inspire_schemas.builders import LiteratureBuilder
from inspire_utils.record import get_value, get_values_for_schema
from invenio_db import db
from invenio_pidstore.errors import PIDDoesNotExistError
from opensearch_dsl import Q
from sqlalchemy.exc import SQLAlchemyError

from inspirehep.cds.errors import CDSSyncError, MissingCDSServerConfig
Expand Down
5 changes: 2 additions & 3 deletions backend/inspirehep/cds/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 CERN.
#
Expand Down Expand Up @@ -42,10 +41,10 @@ def sync(since=None):
elif not isinstance(since, date):
try:
since = datetime.strptime(since, "%Y-%m-%d").date()
except ValueError:
except ValueError as e:
raise WrongDateFormat(
f"`since`: {since} is in wrong format. Should be in ISO format: YYYY-MM-DD."
)
) from e
try:
click.echo("Starting CDS Sync.")
sync_identifiers(since)
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/cds/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 CERN.
#
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/cds/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 CERN.
#
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/cds/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
3 changes: 1 addition & 2 deletions backend/inspirehep/celery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down Expand Up @@ -26,7 +25,7 @@
class CeleryTask(AppContextTask):
def on_failure(self, exc, task_id, args, kwargs, einfo):
if isinstance(
exc, (InvalidRequestError, OperationalError, Psycopg2OperationalError)
exc, InvalidRequestError | OperationalError | Psycopg2OperationalError
):
LOGGER.exception("Shutting down celery process")
try:
Expand Down
1 change: 0 additions & 1 deletion backend/inspirehep/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2019 CERN.
#
Expand Down
5 changes: 5 additions & 0 deletions backend/inspirehep/curation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Copyright (C) 2021 CERN.
#
# inspirehep is free software; you can redistribute it and/or modify it under
# the terms of the MIT License; see LICENSE file for more details.
Loading

0 comments on commit 4247d27

Please sign in to comment.