Skip to content

Commit

Permalink
global: enforce line length
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalEgn authored and drjova committed Sep 10, 2024
1 parent 4247d27 commit 5fb5f82
Show file tree
Hide file tree
Showing 104 changed files with 1,838 additions and 584 deletions.
9 changes: 6 additions & 3 deletions .github/actions/combine-durations/combine_durations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

current_path = Path(".").resolve()
print(
f"Combining durations with split-prefix={split_prefix} and durations-path={durations_path} in {current_path}."
f"Combining durations with split-prefix={split_prefix} and"
f" durations-path={durations_path} in {current_path}."
)
split_paths = Path(".").glob(f"{split_prefix}*/{durations_path.name}")
try:
previous_durations = json.loads(durations_path.read_text())
print(
f"Loaded previous durations from {durations_path}, found {len(previous_durations)} test durations."
f"Loaded previous durations from {durations_path}, found"
f" {len(previous_durations)} test durations."
)
except FileNotFoundError:
previous_durations = {}
Expand All @@ -31,7 +33,8 @@
}
new_durations.update(updated_durations)
print(
f"Updated durations from {path} containing {len(updated_durations)} changed test durations."
f"Updated durations from {path} containing {len(updated_durations)} changed"
" test durations."
)

durations_path.parent.mkdir(parents=True, exist_ok=True)
Expand Down
3 changes: 2 additions & 1 deletion backend/inspirehep/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def set_orcid_push_setting():

if len(tokens) != 1:
raise ValueError(
f"One token per remote account is expected, but found {len(tokens)} for {orcid}"
f"One token per remote account is expected, but found {len(tokens)} for"
f" {orcid}"
)

push_account_literature_to_orcid.apply_async(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def upgrade():
"CREATE TABLE tmp_records_authors (LIKE records_authors INCLUDING CONSTRAINTS);"
)
op.execute(
f"INSERT INTO tmp_records_authors SELECT * FROM records_authors WHERE id_type IN {new_enum_types};"
"INSERT INTO tmp_records_authors SELECT * FROM records_authors WHERE id_type"
f" IN {new_enum_types};"
)
op.execute(
"ALTER TABLE tmp_records_authors ALTER COLUMN id_type TYPE VARCHAR(255);"
Expand Down Expand Up @@ -81,7 +82,8 @@ def upgrade():
op.execute(f"CREATE TYPE enum_author_schema_type AS ENUM {new_enum_types};")
op.execute("ALTER TABLE tmp_records_authors RENAME TO records_authors")
op.execute(
"ALTER TABLE records_authors ALTER COLUMN id_type TYPE enum_author_schema_type USING (id_type::enum_author_schema_type);"
"ALTER TABLE records_authors ALTER COLUMN id_type TYPE enum_author_schema_type"
" USING (id_type::enum_author_schema_type);"
)


Expand All @@ -91,5 +93,6 @@ def downgrade():
op.execute("DROP TYPE IF EXISTS enum_author_schema_type;")
op.execute(f"CREATE TYPE enum_author_schema_type AS ENUM {old_enum_values}")
op.execute(
"ALTER TABLE records_authors ALTER COLUMN id_type TYPE enum_author_schema_type USING (id_type::enum_author_schema_type);"
"ALTER TABLE records_authors ALTER COLUMN id_type TYPE enum_author_schema_type"
" USING (id_type::enum_author_schema_type);"
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ def upgrade():
"""Upgrade database."""
op.execute("CREATE SEQUENCE records_authors_id_seq OWNED BY records_authors.id;")
op.execute(
"SELECT SETVAL('records_authors_id_seq', (select max(id) from records_authors), false)"
"SELECT SETVAL('records_authors_id_seq', (select max(id) from records_authors),"
" false)"
)
op.execute(
"ALTER TABLE records_authors ALTER COLUMN id SET DEFAULT nextval('records_authors_id_seq');"
"ALTER TABLE records_authors ALTER COLUMN id SET DEFAULT"
" nextval('records_authors_id_seq');"
)
op.execute(
"ALTER TABLE records_authors ADD CONSTRAINT pk_authors_records PRIMARY KEY (id)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ def downgrade():
op.execute("DROP TYPE IF EXISTS enum_author_schema_type;")
op.execute(f"CREATE TYPE enum_author_schema_type AS ENUM {old_enum_values}")
op.execute(
"ALTER TABLE records_authors ALTER COLUMN id_type TYPE enum_author_schema_type USING (id_type::enum_author_schema_type);"
"ALTER TABLE records_authors ALTER COLUMN id_type TYPE enum_author_schema_type"
" USING (id_type::enum_author_schema_type);"
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ def upgrade():
"""Upgrade database."""
op.rename_table("record_citations", "records_citations")
op.execute(
"ALTER TABLE records_citations RENAME CONSTRAINT fk_record_citations_cited TO fk_records_citations_cited_id"
"ALTER TABLE records_citations RENAME CONSTRAINT fk_record_citations_cited TO"
" fk_records_citations_cited_id"
)
op.execute(
"ALTER TABLE records_citations RENAME CONSTRAINT fk_record_citations_citer TO fk_records_citations_citer_id"
"ALTER TABLE records_citations RENAME CONSTRAINT fk_record_citations_citer TO"
" fk_records_citations_citer_id"
)
op.execute(
"ALTER INDEX idx_citations_cited RENAME TO ix_records_citations_cited_id"
Expand All @@ -33,10 +35,12 @@ def downgrade():
"""Downgrade database."""
op.rename_table("records_citations", "record_citations")
op.execute(
"ALTER TABLE record_citations RENAME CONSTRAINT fk_records_citations_cited_id TO fk_record_citations_cited"
"ALTER TABLE record_citations RENAME CONSTRAINT fk_records_citations_cited_id"
" TO fk_record_citations_cited"
)
op.execute(
"ALTER TABLE record_citations RENAME CONSTRAINT fk_records_citations_citer_id TO fk_record_citations_citer"
"ALTER TABLE record_citations RENAME CONSTRAINT fk_records_citations_citer_id"
" TO fk_record_citations_citer"
)
op.execute(
"ALTER INDEX ix_records_citations_cited_id RENAME TO idx_citations_cited"
Expand Down
3 changes: 2 additions & 1 deletion backend/inspirehep/assign/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def assign_to_new_stub_author(author_record, literature_recids):
stub_author_data = update_author_names({"name": {}}, author_signatures)
else:
LOGGER.warning(
"Author not found in literature authors, creating stub author with author record data",
"Author not found in literature authors, creating stub author with author"
" record data",
author_recid=from_author_recid,
)
stub_author_data = {"name": author_record["name"]}
Expand Down
12 changes: 7 additions & 5 deletions backend/inspirehep/cds/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def sync_identifiers(since=None):
since = since or last_run_date
if not since:
LOGGER.error(
"CDS Sync failed. No `since` provided and no successful runs in DB. Aborting."
"CDS Sync failed. No `since` provided and no successful runs in DB."
" Aborting."
)
raise CDSSyncError("Missing `since` date")

Expand Down Expand Up @@ -144,10 +145,11 @@ def get_record_for_provided_ids(control_numbers, arxivs, dois, report_numbers):
for report_number in report_numbers:
arxiv = report_number.lower().split("arxiv:")[-1]
# Report numbers might contain arxivs or normal report numbers
if is_arxiv(arxiv):
record_object = get_record_for_pid_or_none("arxiv", arxiv)
else:
record_object = query_report_number(report_number)
record_object = (
get_record_for_pid_or_none("arxiv", arxiv)
if is_arxiv(arxiv)
else query_report_number(report_number)
)
if record_object:
LOGGER.info(
"Matched record by `report_number`",
Expand Down
8 changes: 6 additions & 2 deletions backend/inspirehep/cds/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ def cds():
"-s",
"since",
default=None,
help="Date from when CDS should be synced. If not provided last successful run date will be used.",
help=(
"Date from when CDS should be synced. If not provided last successful run date"
" will be used."
),
)
@with_appcontext
def sync(since=None):
Expand All @@ -43,7 +46,8 @@ def sync(since=None):
since = datetime.strptime(since, "%Y-%m-%d").date()
except ValueError as e:
raise WrongDateFormat(
f"`since`: {since} is in wrong format. Should be in ISO format: YYYY-MM-DD."
f"`since`: {since} is in wrong format. Should be in ISO format:"
" YYYY-MM-DD."
) from e
try:
click.echo("Starting CDS Sync.")
Expand Down
5 changes: 4 additions & 1 deletion backend/inspirehep/curation/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ def __init__(self, collaboration_id, subgroup, **kwargs):
super().__init__(**kwargs)
self.collaboration_id = collaboration_id
self.subgroup_missing = subgroup
self.message = f"Subgroup {self.subgroup_missing} was not found in collaboration {self.collaboration_id} (normalization problem)."
self.message = (
f"Subgroup {self.subgroup_missing} was not found in collaboration"
f" {self.collaboration_id} (normalization problem)."
)
9 changes: 5 additions & 4 deletions backend/inspirehep/curation/search_check_do/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ def search(self):
search_instance = self.search_class()
# For literature, `query_from_iq` does unwanted permission checks,
# so we work around it
if isinstance(search_instance, LiteratureSearch):
query = search_instance.query(IQ(self.query, search_instance))
else:
query = search_instance.query_from_iq(self.query)
query = (
search_instance.query(IQ(self.query, search_instance))
if isinstance(search_instance, LiteratureSearch)
else search_instance.query_from_iq(self.query)
)
query = query.params(_source={}, size=self.size, scroll="60m")
if shard_filter := self._current_shard_filter():
query = query.filter("script", script=shard_filter)
Expand Down
10 changes: 8 additions & 2 deletions backend/inspirehep/curation/search_check_do/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ def do(record, logger, state):


class MoveFermilabURLs(SearchCheckDo):
query = "urls.value:http://lss.fnal.gov/cgi-bin/find_paper.pl* OR urls.value:https://lss.fnal.gov/cgi-bin/find_paper.pl*"
query = (
"urls.value:http://lss.fnal.gov/cgi-bin/find_paper.pl* OR"
" urls.value:https://lss.fnal.gov/cgi-bin/find_paper.pl*"
)

@staticmethod
def check(record, logger, state):
Expand All @@ -197,7 +200,10 @@ def do(record, logger, state):
class HideElsevierFulltext(SearchCheckDo):
"""Hide fulltexts from Elsevier that have been incorrectly set as non-hidden."""

query = "(jy 2013 or 2014 or 2015) and documents.filename:'xml' and (arxiv_eprints.value:* or not documents.hidden:true)"
query = (
"(jy 2013 or 2014 or 2015) and documents.filename:'xml' and"
" (arxiv_eprints.value:* or not documents.hidden:true)"
)

@staticmethod
def check(record, logger, state):
Expand Down
6 changes: 5 additions & 1 deletion backend/inspirehep/curation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ def find_unambiguous_affiliation(result, wf_id):
)
if matched_aff:
message_payload = {"literature recid": matched_author["control_number"]}
message = f"Found matching affiliation, literature recid: {matched_author['control_number']}, raw_affiliations: {matched_author_raw_affs}, matched affiliations: {matched_aff}"
message = (
"Found matching affiliation, literature recid:"
f" {matched_author['control_number']}, raw_affiliations:"
f" {matched_author_raw_affs}, matched affiliations: {matched_aff}"
)
if wf_id:
message += f" workflow_id: {wf_id}"
LOGGER.info("Found matching affiliation", message_payload)
Expand Down
15 changes: 12 additions & 3 deletions backend/inspirehep/disambiguation/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,30 @@ def _send_celery_group_disambiguation_task(uuids, batch_size):
@click.option(
"--total-records",
type=int,
help="Number of records to disambiguate, if not passed all records with at least one not disambiguated will be sent to the queue",
help=(
"Number of records to disambiguate, if not passed all records with at least one"
" not disambiguated will be sent to the queue"
),
)
@click.option(
"--indexing-queue-limit",
type=int,
default=MAX_INDEXER_QUEUE_LEN,
show_default=True,
help="Number of records to disambiguate, if not passed all records with at least one not disambiguated will be sent to the queue",
help=(
"Number of records to disambiguate, if not passed all records with at least one"
" not disambiguated will be sent to the queue"
),
)
@click.option(
"--disambiguation-queue-limit",
type=int,
default=MAX_DISAMBIGUATION_QUEUE_LEN,
show_default=True,
help="Number of records to disambiguate, if not passed all records with at least one not disambiguated will be sent to the queue",
help=(
"Number of records to disambiguate, if not passed all records with at least one"
" not disambiguated will be sent to the queue"
),
)
def disambiguate_all_not_disambiguated(
celery_batch_size, total_records, indexing_queue_limit, disambiguation_queue_limit
Expand Down
2 changes: 1 addition & 1 deletion backend/inspirehep/editor/authorlist_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def create_authors(text):
else:
# authors = parse_blocks(text_blocks)
raise ValueError(
"Authors grouped by affiliation? - Comming soon." "Or too many empty lines."
"Authors grouped by affiliation? - Comming soon.Or too many empty lines."
)

if warnings:
Expand Down
10 changes: 8 additions & 2 deletions backend/inspirehep/editor/editor_soft_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ def prepare_editor_lock_api_payload(self):
]
).strip(", ")
if existing_user_locks:
editor_user_lock_msg = f"Record opened by {existing_user_locks} Their modifications aren't saved yet, they (or yours) might get lost."
editor_user_lock_msg = (
f"Record opened by {existing_user_locks} Their modifications aren't"
" saved yet, they (or yours) might get lost."
)
payload["user_locks"] = editor_user_lock_msg
elif existing_task_locks:
editor_task_lock_msg = f"Scheduled tasks: {existing_task_locks}. Your modifications might get lost"
editor_task_lock_msg = (
f"Scheduled tasks: {existing_task_locks}. Your modifications might get"
" lost"
)
payload["task_locks"] = editor_task_lock_msg
return payload
5 changes: 4 additions & 1 deletion backend/inspirehep/editor/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

class EditorRevertToRevisionError(RESTException):
code = 400
description = "Something went wrong while reverting to the previous revision, please try again later."
description = (
"Something went wrong while reverting to the previous revision, please try"
" again later."
)


class EditorGetRevisionError(RESTException):
Expand Down
3 changes: 2 additions & 1 deletion backend/inspirehep/editor/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,8 @@ def normalize_affiliations_for_authors(parsed_authors):
if normalized_affiliation:
author["affiliations"] = normalized_affiliation
LOGGER.info(
"Found ambiguous affiliations for raw affiliations, skipping affiliation linking.",
"Found ambiguous affiliations for raw affiliations, skipping affiliation"
" linking.",
ambiguous_affiliations=normalized_affiliations_result["ambiguous_affiliations"],
)
return parsed_authors
7 changes: 3 additions & 4 deletions backend/inspirehep/hal/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ def _hal_push(record):
hal_id = hal_value[0] if hal_value else ""
lock_name = f"hal:{record['control_number']}"
with distributed_lock(lock_name, blocking=True):
if hal_id:
receipt = _hal_update(tei, hal_id, record)
else:
receipt = _hal_create(tei, record)
receipt = (
_hal_update(tei, hal_id, record) if hal_id else _hal_create(tei, record)
)
if receipt and receipt.id != hal_id:
_write_hal_id_to_record(record, receipt.id)
return receipt
Expand Down
8 changes: 6 additions & 2 deletions backend/inspirehep/hepdata/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ def hepdata():
"-s",
"since",
default=None,
help="Date from when hepdata should be harvested. If not provided the date from a day before would be used.",
help=(
"Date from when hepdata should be harvested. If not provided the date from a"
" day before would be used."
),
)
@with_appcontext
def harvest(since):
Expand All @@ -37,7 +40,8 @@ def harvest(since):
since = datetime.strptime(since, "%Y-%m-%d").date()
except ValueError as e:
raise ValueError(
f"`since`: {since} is in wrong format. Should be in ISO format: YYYY-MM-DD."
f"`since`: {since} is in wrong format. Should be in ISO format:"
" YYYY-MM-DD."
) from e
else:
since = (datetime.now() - timedelta(1)).strftime("%Y-%m-%d")
Expand Down
12 changes: 6 additions & 6 deletions backend/inspirehep/indexer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class InspireRecordIndexer(RecordIndexer):
def _prepare_record(record, index, doc_type="_doc", arguments=None, **kwargs):
from inspirehep.records.api import LiteratureRecord

if current_app.config["FEATURE_FLAG_ENABLE_FULLTEXT"] and isinstance(
record, LiteratureRecord
):
data = record.serialize_for_es_with_fulltext()
else:
data = record.serialize_for_es()
data = (
record.serialize_for_es_with_fulltext()
if current_app.config["FEATURE_FLAG_ENABLE_FULLTEXT"]
and isinstance(record, LiteratureRecord)
else record.serialize_for_es()
)
before_record_index.send(
current_app._get_current_object(),
json=data,
Expand Down
Loading

0 comments on commit 5fb5f82

Please sign in to comment.