Skip to content

Commit ae20f24

Browse files
committed
Fix static analysis issues and code formatting
1 parent 33fa723 commit ae20f24

2 files changed

Lines changed: 44 additions & 14 deletions

File tree

dev/generate_country_codes.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
"""
33
Generate ISO 3166-1 alpha-2 country codes YAML file for DOAJ fetch script.
44
"""
5+
# Standard library
56
import os
67
import sys
8+
9+
# Third-party
710
import yaml
811

912
# Add parent directory so shared can be imported
1013
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "scripts"))
11-
import shared
14+
# First-party/Local
15+
import shared # noqa: E402
1216

1317
# ISO 3166-1 alpha-2 country codes (official list)
1418
COUNTRIES = [
@@ -268,17 +272,22 @@ def main():
268272
"""Generate ISO country codes YAML file."""
269273
repo_path = shared.path_join(os.path.dirname(__file__), "..")
270274
output_file = shared.path_join(repo_path, "data", "iso_country_codes.yaml")
271-
275+
272276
header = [
273277
"# ISO 3166-1 alpha-2 country codes to country names mapping",
274278
"# Used by DOAJ API for publisher country identification",
275279
"# Generated programmatically by dev/generate_country_codes.py",
276280
]
277-
281+
278282
with open(output_file, "w", encoding="utf-8") as file_object:
279283
file_object.write("\n".join(header) + "\n")
280-
yaml.dump(COUNTRIES, file_object, default_flow_style=False, allow_unicode=True)
281-
284+
yaml.dump(
285+
COUNTRIES,
286+
file_object,
287+
default_flow_style=False,
288+
allow_unicode=True,
289+
)
290+
282291
print(f"Generated {output_file} with {len(COUNTRIES)} country codes")
283292

284293

scripts/1-fetch/doaj_fetch.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,12 @@ def save_count_data(
409409
country_names = load_country_names()
410410

411411
# Save license counts
412-
with open(FILE_DOAJ_COUNT, "w", encoding="utf-8", newline="\n") as file_object:
413-
writer = csv.DictWriter(file_object, fieldnames=HEADER_COUNT, dialect="unix")
412+
with open(
413+
FILE_DOAJ_COUNT, "w", encoding="utf-8", newline="\n"
414+
) as file_object:
415+
writer = csv.DictWriter(
416+
file_object, fieldnames=HEADER_COUNT, dialect="unix"
417+
)
414418
writer.writeheader()
415419
for lic, count in license_counts.items():
416420
writer.writerow({"TOOL_IDENTIFIER": lic, "COUNT": count})
@@ -439,8 +443,12 @@ def save_count_data(
439443
)
440444

441445
# Save language counts with readable names
442-
with open(FILE_DOAJ_LANGUAGE, "w", encoding="utf-8", newline="\n") as file_object:
443-
writer = csv.DictWriter(file_object, fieldnames=HEADER_LANGUAGE, dialect="unix")
446+
with open(
447+
FILE_DOAJ_LANGUAGE, "w", encoding="utf-8", newline="\n"
448+
) as file_object:
449+
writer = csv.DictWriter(
450+
file_object, fieldnames=HEADER_LANGUAGE, dialect="unix"
451+
)
444452
writer.writeheader()
445453
for lic, languages in language_counts.items():
446454
for lang_code, count in languages.items():
@@ -455,8 +463,12 @@ def save_count_data(
455463
)
456464

457465
# Save year counts
458-
with open(FILE_DOAJ_YEAR, "w", encoding="utf-8", newline="\n") as file_object:
459-
writer = csv.DictWriter(file_object, fieldnames=HEADER_YEAR, dialect="unix")
466+
with open(
467+
FILE_DOAJ_YEAR, "w", encoding="utf-8", newline="\n"
468+
) as file_object:
469+
writer = csv.DictWriter(
470+
file_object, fieldnames=HEADER_YEAR, dialect="unix"
471+
)
460472
writer.writeheader()
461473
for lic, years in year_counts.items():
462474
for year, count in years.items():
@@ -465,7 +477,9 @@ def save_count_data(
465477
)
466478

467479
# Save publisher counts
468-
with open(FILE_DOAJ_PUBLISHER, "w", encoding="utf-8", newline="\n") as file_object:
480+
with open(
481+
FILE_DOAJ_PUBLISHER, "w", encoding="utf-8", newline="\n"
482+
) as file_object:
469483
writer = csv.DictWriter(
470484
file_object, fieldnames=HEADER_PUBLISHER, dialect="unix"
471485
)
@@ -529,8 +543,15 @@ def query_doaj(args):
529543
}
530544

531545
try:
532-
with open(FILE_PROVENANCE, "w", encoding="utf-8", newline="\n") as file_object:
533-
yaml.dump(provenance_data, file_object, default_flow_style=False, indent=2)
546+
with open(
547+
FILE_PROVENANCE, "w", encoding="utf-8", newline="\n"
548+
) as file_object:
549+
yaml.dump(
550+
provenance_data,
551+
file_object,
552+
default_flow_style=False,
553+
indent=2,
554+
)
534555
except Exception as e:
535556
LOGGER.error("Failed to write provenance file: %s", e)
536557
raise shared.QuantifyingException(

0 commit comments

Comments
 (0)