From d88ea564882360acde2f944a108d2d02fa57e56b Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Thu, 11 Mar 2021 10:52:20 +0200 Subject: [PATCH] csv_metadata_quality/check.py: Move all imports to top of file PEP8 recommends keeping imports at the top of the file. Also, I had to re-work the issn/isbn so they didn't conflict with the functions in check.py (flake8 warned about them being redefined). Imports sorted with isort. See: https://www.python.org/dev/peps/pep-0008/#imports --- csv_metadata_quality/check.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/csv_metadata_quality/check.py b/csv_metadata_quality/check.py index d0ba1f9..cfa870e 100755 --- a/csv_metadata_quality/check.py +++ b/csv_metadata_quality/check.py @@ -1,3 +1,4 @@ +import re from datetime import datetime, timedelta import pandas as pd @@ -6,6 +7,8 @@ import requests_cache import spdx_license_list from colorama import Fore from pycountry import languages +from stdnum import isbn as stdnum_isbn +from stdnum import issn as stdnum_issn def issn(field): @@ -18,8 +21,6 @@ def issn(field): See: https://arthurdejong.org/python-stdnum/doc/1.11/index.html#stdnum.module.is_valid """ - from stdnum import issn - # Skip fields with missing values if pd.isna(field): return @@ -27,7 +28,7 @@ def issn(field): # Try to split multi-value field on "||" separator for value in field.split("||"): - if not issn.is_valid(value): + if not stdnum_issn.is_valid(value): print(f"{Fore.RED}Invalid ISSN: {Fore.RESET}{value}") return field @@ -43,8 +44,6 @@ def isbn(field): See: https://arthurdejong.org/python-stdnum/doc/1.11/index.html#stdnum.module.is_valid """ - from stdnum import isbn - # Skip fields with missing values if pd.isna(field): return @@ -52,7 +51,7 @@ def isbn(field): # Try to split multi-value field on "||" separator for value in field.split("||"): - if not isbn.is_valid(value): + if not stdnum_isbn.is_valid(value): print(f"{Fore.RED}Invalid ISBN: {Fore.RESET}{value}") return field @@ -68,8 +67,6 @@ def separators(field, field_name): Prints the field with the invalid multi-value separator. """ - import re - # Skip fields with missing values if pd.isna(field): return @@ -278,8 +275,6 @@ def filename_extension(field): than .pdf, .xls(x), .doc(x), ppt(x), case insensitive). """ - import re - # Skip fields with missing values if pd.isna(field): return