From e5b035d10911deb9dcd0b0f8667d4f1eda89248b Mon Sep 17 00:00:00 2001 From: "Michael E. Rose" Date: Wed, 18 Dec 2024 10:08:10 +0100 Subject: [PATCH] Remove unnecessary imports and sort imports --- pubmed_parser/medline_parser.py | 4 ++-- pubmed_parser/pubmed_oa_parser.py | 5 +++-- pubmed_parser/pubmed_web_parser.py | 13 ++++--------- pubmed_parser/utils.py | 12 +++++------- pyproject.toml | 3 +-- tests/test_pubmed_oa_parser.py | 6 ++++-- tests/test_pubmed_web_parser.py | 3 ++- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/pubmed_parser/medline_parser.py b/pubmed_parser/medline_parser.py index a431f91..5e3e7d4 100644 --- a/pubmed_parser/medline_parser.py +++ b/pubmed_parser/medline_parser.py @@ -2,11 +2,11 @@ Parsers for MEDLINE XML """ import re -import numpy as np import gzip from itertools import chain + from lxml import etree -from collections import defaultdict + from pubmed_parser.utils import read_xml, stringify_children, month_or_day_formater diff --git a/pubmed_parser/pubmed_oa_parser.py b/pubmed_parser/pubmed_oa_parser.py index 21217ac..aa8dd5f 100644 --- a/pubmed_parser/pubmed_oa_parser.py +++ b/pubmed_parser/pubmed_oa_parser.py @@ -2,11 +2,12 @@ Parsers for PubMed XML """ import os -from lxml import etree from itertools import chain -from .utils import read_xml, stringify_affiliation_rec, stringify_children + +from lxml import etree from unidecode import unidecode +from .utils import read_xml, stringify_affiliation_rec, stringify_children def list_xml_path(path_dir): """ diff --git a/pubmed_parser/pubmed_web_parser.py b/pubmed_parser/pubmed_web_parser.py index 97df0af..9ce8205 100644 --- a/pubmed_parser/pubmed_web_parser.py +++ b/pubmed_parser/pubmed_web_parser.py @@ -1,15 +1,10 @@ -import sys import re import time +from urllib.request import urlopen + import requests -from lxml import etree -from lxml import html -from unidecode import unidecode - -try: - from urllib.request import urlopen -except ImportError: - from urllib2 import urlopen +from lxml import etree, html + from .utils import stringify_children diff --git a/pubmed_parser/utils.py b/pubmed_parser/utils.py index 0dbc9f0..2928939 100644 --- a/pubmed_parser/utils.py +++ b/pubmed_parser/utils.py @@ -1,13 +1,11 @@ import calendar -import collections -try: - from collections.abc import Iterable -except: - from collections import Iterable +from itertools import chain from time import strptime -from six import string_types + +from collections.abc import Iterable + from lxml import etree -from itertools import chain +from six import string_types def remove_namespace(tree): diff --git a/pyproject.toml b/pyproject.toml index 732641a..82d4a73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,8 +45,7 @@ dependencies = [ "lxml", "unidecode", "requests", - "six", - "numpy" + "six" ] dynamic = ["version"] diff --git a/tests/test_pubmed_oa_parser.py b/tests/test_pubmed_oa_parser.py index a279b82..5ed329f 100644 --- a/tests/test_pubmed_oa_parser.py +++ b/tests/test_pubmed_oa_parser.py @@ -1,9 +1,11 @@ -import os -import tarfile from io import BytesIO + +import tarfile import requests + import pubmed_parser as pp + def fetch_pubmed_xml(db_dir): """Fetch Pubmed OA XML package""" url = f'https://ftp.ncbi.nlm.nih.gov/pub/pmc/oa_package/{db_dir}.tar.gz' diff --git a/tests/test_pubmed_web_parser.py b/tests/test_pubmed_web_parser.py index 8641911..46caded 100644 --- a/tests/test_pubmed_web_parser.py +++ b/tests/test_pubmed_web_parser.py @@ -1,6 +1,7 @@ -import pubmed_parser as pp import random +import pubmed_parser as pp + def test_pubmed_web_parser_all_fields_content(): """