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 committed Aug 6, 2024
1 parent 81cfdd5 commit 8b596ba
Show file tree
Hide file tree
Showing 57 changed files with 119 additions and 111 deletions.
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- 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: ruff
args: [ --fix ]
7 changes: 3 additions & 4 deletions inspire_dojson/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@
import re
from itertools import chain

from dojson.contrib.marc21.utils import create_record
from inspire_utils.helpers import force_list
from inspire_utils.record import get_value
from lxml.builder import E
from lxml.etree import tostring
from six import iteritems, text_type, unichr
from six.moves import urllib

from dojson.contrib.marc21.utils import create_record

from inspire_dojson.utils import create_record_from_dict, force_single_element
from inspire_utils.helpers import force_list
from inspire_utils.record import get_value

from .cds import cds2hep_marc
from .conferences import conferences
Expand Down
3 changes: 2 additions & 1 deletion inspire_dojson/cds/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
from __future__ import absolute_import, division, print_function

from itertools import chain
from inspire_utils.record import get_value

from inspire_utils.helpers import force_list
from inspire_utils.record import get_value

from ..model import FilterOverdo, clean_record

Expand Down
9 changes: 3 additions & 6 deletions inspire_dojson/cds/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@
import pycountry
import rfc3987
import six

from idutils import is_arxiv
from dojson import utils

from six.moves import urllib

from idutils import is_arxiv
from inspire_utils.helpers import force_list
from inspire_utils.name import normalize_name
from six.moves import urllib

from .model import cds2hep_marc
from ..utils import force_single_element, quote_url
from .model import cds2hep_marc

CATEGORIES = {
'Accelerators and Storage Rings': 'Accelerators',
Expand Down
7 changes: 2 additions & 5 deletions inspire_dojson/common/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@
import re
from datetime import datetime

from flask import current_app
from six.moves import urllib

from dojson import utils

from flask import current_app
from inspire_schemas.api import load_schema
from inspire_schemas.utils import classify_field
from inspire_utils.date import PartialDate, earliest_date
from inspire_utils.helpers import force_list, maybe_int
from six.moves import urllib

from ..conferences.model import conferences
from ..data.model import data
Expand All @@ -50,7 +48,6 @@
get_record_ref,
)


IS_INTERNAL_UID = re.compile(r'^(inspire:uid:)?\d{5}$')
IS_ORCID = re.compile(r'^(orcid:)?\d{4}-\d{4}-\d{4}-\d{3}[0-9X]$')

Expand Down
2 changes: 1 addition & 1 deletion inspire_dojson/conferences/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from __future__ import absolute_import, division, print_function

from ..model import FilterOverdo, add_schema, add_collection, clean_record
from ..model import FilterOverdo, add_collection, add_schema, clean_record


def remove_lone_series_number(record, blob):
Expand Down
5 changes: 2 additions & 3 deletions inspire_dojson/conferences/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
from __future__ import absolute_import, division, print_function

from dojson import utils
from inspire_utils.helpers import force_list, maybe_float, maybe_int

from inspire_utils.helpers import force_list, maybe_int, maybe_float

from .model import conferences
from ..utils import force_single_element
from ..utils.geo import parse_conference_address
from .model import conferences


def _trim_date(date):
Expand Down
3 changes: 1 addition & 2 deletions inspire_dojson/data/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

from __future__ import absolute_import, division, print_function

from ..model import FilterOverdo, add_schema, add_collection, clean_record

from ..model import FilterOverdo, add_collection, add_schema, clean_record

filters = [
add_schema('data.json'),
Expand Down
2 changes: 1 addition & 1 deletion inspire_dojson/data/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from dojson import utils
from idutils import normalize_doi

from .model import data
from ..utils import force_single_element, get_record_ref
from .model import data


@data.over('dois', '^0247.')
Expand Down
4 changes: 1 addition & 3 deletions inspire_dojson/experiments/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@

from dojson import utils
from dojson.errors import IgnoreKey

from inspire_utils.date import normalize_date
from inspire_utils.helpers import force_list, maybe_int

from .model import experiments
from ..utils import force_single_element, get_record_ref

from .model import experiments

EXPERIMENT_CATEGORIES_MAP = \
{'1': 'Collider Experiments',
Expand Down
2 changes: 1 addition & 1 deletion inspire_dojson/hep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from __future__ import absolute_import, division, print_function

from .model import hep, hep2marc # noqa: F401
from .rules import ( # noqa: F401
bd0xx,
bd1xx,
Expand All @@ -36,4 +37,3 @@
bd9xx,
bdFFT,
)
from .model import hep, hep2marc # noqa: F401
3 changes: 1 addition & 2 deletions inspire_dojson/hep/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
import itertools

import six

from inspire_schemas.builders.literature import is_citeable
from inspire_schemas.utils import (
convert_old_publication_info_to_new,
normalize_arxiv_category,
)
from inspire_schemas.builders.literature import is_citeable
from inspire_utils.helpers import force_list
from inspire_utils.record import get_value

Expand Down
5 changes: 1 addition & 4 deletions inspire_dojson/hep/rules/bd0xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,14 @@
from collections import defaultdict

import pycountry

from dojson import utils
from idutils import is_arxiv_post_2007, is_doi, is_handle, normalize_doi

from inspire_schemas.api import load_schema
from inspire_schemas.utils import normalize_arxiv_category
from inspire_utils.helpers import force_list

from ..model import hep, hep2marc
from ...utils import force_single_element, normalize_isbn

from ..model import hep, hep2marc

RE_LANGUAGE = re.compile(r'\/| or | and |,|=|\s+')

Expand Down
4 changes: 1 addition & 3 deletions inspire_dojson/hep/rules/bd1xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
import re

from dojson import utils

from inspire_utils.dedupers import dedupe_list
from inspire_utils.helpers import force_list, maybe_int

from ..model import hep, hep2marc
from ...utils import (
force_single_element,
get_record_ref,
)

from ..model import hep, hep2marc

ORCID = re.compile(r'\d{4}-\d{4}-\d{4}-\d{3}[0-9Xx]')

Expand Down
4 changes: 1 addition & 3 deletions inspire_dojson/hep/rules/bd2xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
from __future__ import absolute_import, division, print_function

import langdetect

from dojson import utils

from inspire_utils.helpers import force_list

from ..model import hep, hep2marc
from ...utils import normalize_date_aggressively
from ..model import hep, hep2marc


@hep.over('titles', '^(210|245|246|247)..')
Expand Down
2 changes: 1 addition & 1 deletion inspire_dojson/hep/rules/bd3xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

from inspire_utils.helpers import maybe_int

from ..model import hep, hep2marc
from ...utils import force_single_element
from ..model import hep, hep2marc


@hep.over('number_of_pages', '^300..')
Expand Down
4 changes: 1 addition & 3 deletions inspire_dojson/hep/rules/bd5xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
import re

from dojson import utils

from inspire_utils.date import normalize_date
from inspire_utils.helpers import force_list, maybe_int

from ..model import hep, hep2marc
from ...utils import force_single_element, get_record_ref

from ..model import hep, hep2marc

IS_DEFENSE_DATE = re.compile('Presented (on )?(?P<defense_date>.*)', re.IGNORECASE)

Expand Down
4 changes: 1 addition & 3 deletions inspire_dojson/hep/rules/bd6xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
from __future__ import absolute_import, division, print_function

import six

from dojson import utils

from inspire_utils.helpers import force_list

from ..model import hep, hep2marc
from ...utils import force_single_element, get_record_ref
from ..model import hep, hep2marc

ENERGY_RANGES_MAP = {
'1': '0-3 GeV',
Expand Down
3 changes: 1 addition & 2 deletions inspire_dojson/hep/rules/bd7xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from __future__ import absolute_import, division, print_function

from dojson import utils

from inspire_schemas.api import load_schema
from inspire_schemas.utils import (
convert_new_publication_info_to_old,
Expand All @@ -34,13 +33,13 @@
)
from inspire_utils.helpers import force_list, maybe_int

from ..model import hep, hep2marc
from ...utils import (
force_single_element,
get_recid_from_ref,
get_record_ref,
normalize_isbn,
)
from ..model import hep, hep2marc


@hep.over('collaborations', '^710..')
Expand Down
3 changes: 1 addition & 2 deletions inspire_dojson/hep/rules/bd9xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from dojson import utils
from idutils import is_arxiv_post_2007

from inspire_schemas.api import ReferenceBuilder, load_schema
from inspire_schemas.utils import (
build_pubnote,
Expand All @@ -38,8 +37,8 @@
from inspire_utils.helpers import force_list, maybe_int
from inspire_utils.record import get_value

from ..model import hep, hep2marc
from ...utils import force_single_element, get_recid_from_ref, get_record_ref
from ..model import hep, hep2marc

COLLECTIONS_MAP = {
'babar-analysisdocument': 'BABAR Analysis Documents',
Expand Down
3 changes: 1 addition & 2 deletions inspire_dojson/hep/rules/bdFFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@
import re

from dojson import utils

from inspire_utils.helpers import force_list

from ..model import hep, hep2marc
from ...utils import absolute_url, afs_url, afs_url_to_path
from ..model import hep, hep2marc


@hep.over('documents', '^FFT[^%][^%]')
Expand Down
3 changes: 1 addition & 2 deletions inspire_dojson/hepnames/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

from __future__ import absolute_import, division, print_function

from ..model import FilterOverdo, add_schema, add_collection, clean_marc, clean_record

from ..model import FilterOverdo, add_collection, add_schema, clean_marc, clean_record

hepnames_filters = [
add_schema('authors.json'),
Expand Down
10 changes: 4 additions & 6 deletions inspire_dojson/hepnames/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import re

from dojson import utils

from inspire_schemas.api import load_schema
from inspire_schemas.utils import (
normalize_arxiv_category,
Expand All @@ -37,16 +36,15 @@
from inspire_utils.helpers import force_list, maybe_int
from inspire_utils.name import normalize_name

from .model import hepnames, hepnames2marc
from ..utils import (
force_single_element,
get_record_ref,
get_recid_from_ref,
get_record_ref,
normalize_rank,
quote_url,
unquote_url
unquote_url,
)

from .model import hepnames, hepnames2marc

AWARD_YEAR = re.compile(r'\(?(?P<year>\d{4})\)?')
INSPIRE_BAI = re.compile(r'(\w+\.)+\d+')
Expand Down Expand Up @@ -760,7 +758,7 @@ def _is_deleted(value):
return force_single_element(value.get('c', '')).upper() == 'DELETED'

def _is_stub(value):
return not (force_single_element(value.get('a', '')).upper() == 'USEFUL')
return force_single_element(value.get('a', '')).upper() != 'USEFUL'

deleted = self.get('deleted')
stub = self.get('stub')
Expand Down
2 changes: 1 addition & 1 deletion inspire_dojson/institutions/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from __future__ import absolute_import, division, print_function

from ..model import FilterOverdo, add_schema, add_collection, clean_record
from ..model import FilterOverdo, add_collection, add_schema, clean_record


def combine_addresses_and_location(record, blob):
Expand Down
4 changes: 1 addition & 3 deletions inspire_dojson/institutions/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
import re

from dojson import utils

from inspire_utils.helpers import force_list, maybe_float, maybe_int

from .model import institutions
from ..utils import force_single_element, get_record_ref
from ..utils.geo import parse_institution_address

from .model import institutions

ACRONYM = re.compile(r'\s*\((.*)\)\s*$')

Expand Down
Loading

0 comments on commit 8b596ba

Please sign in to comment.