Skip to content

imports cleanup #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --import-mode=importlib
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
from distutils.core import setup
from pathlib import PurePath
from platform import python_implementation
from sys import version_info

from os.path import abspath, dirname, join
from typing import List

from setuptools import find_packages
Expand Down
16 changes: 8 additions & 8 deletions src/pyff/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
from six import b
from six.moves.urllib_parse import quote_plus

from .constants import config
from .exceptions import ResourceException
from .logs import get_log
from .pipes import plumbing
from .repo import MDRepository
from .resource import Resource
from .samlmd import entity_display_name
from .utils import b2u, dumptree, duration2timedelta, hash_id, json_serializer, utc_now
from pyff.constants import config
from pyff.exceptions import ResourceException
from pyff.logs import get_log
from pyff.pipes import plumbing
from pyff.repo import MDRepository
from pyff.resource import Resource
from pyff.samlmd import entity_display_name
from pyff.utils import b2u, dumptree, duration2timedelta, hash_id, json_serializer, utc_now

log = get_log(__name__)

Expand Down
17 changes: 7 additions & 10 deletions src/pyff/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
from lxml.etree import DocumentInvalid
from six.moves.urllib_parse import quote_plus, urlparse

from pyff.pipes import registry

from .constants import NS
from .decorators import deprecated
from .exceptions import MetadataException
from .logs import get_log
from .pipes import PipeException, PipelineCallback, Plumbing, pipe
from .resource import ResourceOpts
from .samlmd import (
from pyff.constants import NS
from pyff.decorators import deprecated
from pyff.exceptions import MetadataException
from pyff.logs import get_log
from pyff.pipes import PipeException, PipelineCallback, Plumbing, pipe, registry
from pyff.samlmd import (
annotate_entity,
discojson_t,
entitiesdescriptor,
Expand All @@ -41,7 +38,7 @@
set_reginfo,
sort_entities,
)
from .utils import (
from pyff.utils import (
datetime2iso,
dumptree,
duration2timedelta,
Expand Down
5 changes: 2 additions & 3 deletions src/pyff/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import getopt
import json
import logging
import multiprocessing
import os
import re
import sys
Expand All @@ -14,7 +13,7 @@
import pyconfig
import six

from . import __version__ as pyff_version
from pyff import __version__ as pyff_version

__author__ = 'leifj'

Expand Down Expand Up @@ -230,7 +229,7 @@ class Config(object):
The :py:const:`pyff.constants:config` object is a singleton instance of this Class and contains all
configuration parameters available to pyFF. Each parameter can be set directly, via :py:mod:`pyconfig`
or via environment variables by prefixing the setting name in upper case with "PYFF_". The setting
called "loglevel" then becomes "PYFF_LOGLEVEL" etc. Any occurence of '.' or '-' is also transscribed
called "loglevel" then becomes "PYFF_LOGLEVEL" etc. Any occurrence of '.' or '-' is also transcribed
to '_' when the setting is referenced as an environment variable.


Expand Down
5 changes: 1 addition & 4 deletions src/pyff/decorators.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""
Various decorators used in pyFF.
"""
import functools
import time
from collections import namedtuple

from .logs import get_log
from pyff.logs import get_log

__author__ = 'leifj'

Expand Down
6 changes: 3 additions & 3 deletions src/pyff/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import threading
from datetime import datetime

from .constants import config
from .logs import get_log
from .utils import Watchable, load_callable, url_get
from pyff.constants import config
from pyff.logs import get_log
from pyff.utils import Watchable, load_callable, url_get

log = get_log(__name__)

Expand Down
6 changes: 3 additions & 3 deletions src/pyff/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import sys
import traceback

from .constants import config, parse_options
from .pipes import plumbing
from .repo import MDRepository
from pyff.constants import config, parse_options
from pyff.pipes import plumbing
from pyff.repo import MDRepository


def main():
Expand Down
11 changes: 4 additions & 7 deletions src/pyff/mdq.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@

from __future__ import unicode_literals

import importlib
import logging
import os
import sys

import gunicorn.app.base
from six import iteritems

from .api import mkapp
from .constants import config, parse_options
from .logs import get_log
from .repo import MDRepository
from pyff.api import mkapp
from pyff.constants import config, parse_options
from pyff.logs import get_log
from pyff.repo import MDRepository

log = get_log(__name__)

Expand Down
10 changes: 5 additions & 5 deletions src/pyff/parse.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os
from abc import ABC
from collections import deque
from typing import Any, AnyStr, Dict, List, Mapping, Optional, Union
from typing import Any, List, Mapping, Optional

from xmlsec.crypto import CertDict

from .constants import NS
from .logs import get_log
from .resource import Resource, ResourceOpts
from .utils import find_matching_files, parse_xml, root, unicode_stream, utc_now
from pyff.constants import NS
from pyff.logs import get_log
from pyff.resource import Resource
from pyff.utils import find_matching_files, parse_xml, root, unicode_stream, utc_now

__author__ = 'leifj'

Expand Down
8 changes: 4 additions & 4 deletions src/pyff/pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from apscheduler.schedulers.background import BackgroundScheduler
from lxml.etree import ElementTree

from .logs import get_log
from .repo import MDRepository
from .store import SAMLStoreBase
from .utils import PyffException, is_text, resource_string
from pyff.logs import get_log
from pyff.repo import MDRepository
from pyff.store import SAMLStoreBase
from pyff.utils import PyffException, is_text, resource_string

log = get_log(__name__)

Expand Down
12 changes: 6 additions & 6 deletions src/pyff/repo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import random

from .constants import config
from .logs import get_log
from .resource import Resource, ResourceOpts
from .samlmd import entitiesdescriptor, root
from .store import make_icon_store_instance, make_store_instance
from .utils import is_text, make_default_scheduler
from pyff.constants import NS, config
from pyff.logs import get_log
from pyff.resource import Resource, ResourceOpts
from pyff.samlmd import entitiesdescriptor, root
from pyff.store import make_icon_store_instance, make_store_instance
from pyff.utils import is_text, make_default_scheduler

log = get_log(__name__)

Expand Down
34 changes: 24 additions & 10 deletions src/pyff/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,38 @@
from collections import deque
from datetime import datetime
from threading import Condition, Lock
from typing import TYPE_CHECKING, Any, Callable, Deque, Dict, Iterable, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Any, Callable, Deque, Dict, Iterable, List, Optional, Tuple
from urllib.parse import quote as urlescape

import requests
from lxml.etree import ElementTree
from pydantic import BaseModel, Field
from requests.adapters import Response

from .constants import config
from .exceptions import ResourceException
from .fetch import make_fetcher
from .logs import get_log
from .utils import Watchable, hex_digest, img_to_data, non_blocking_lock, resource_string, safe_write, url_get, utc_now
from pyff.constants import config
from pyff.exceptions import ResourceException
from pyff.fetch import make_fetcher
from pyff.logs import get_log
from pyff.utils import (
Watchable,
hex_digest,
img_to_data,
non_blocking_lock,
resource_string,
safe_write,
url_get,
utc_now,
)

if TYPE_CHECKING:
from .parse import PyffParser
from .pipes import PipelineCallback
from .utils import Lambda
from pyff.parse import PyffParser
from pyff.pipes import PipelineCallback
from pyff.utils import Lambda

# ensure static analysis doesn't flag these as unused
assert PyffParser
assert PipelineCallback
assert Lambda

requests.packages.urllib3.disable_warnings()

Expand Down Expand Up @@ -405,7 +419,7 @@ def parse(self, getter: Callable[[str], Response]) -> Deque[Resource]:

info['State'] = 'Parsing'
# local import to avoid circular import
from .parse import parse_resource
from pyff.parse import parse_resource

parse_info = parse_resource(self, data)
if parse_info is not None:
Expand Down
15 changes: 7 additions & 8 deletions src/pyff/samlmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
from distutils.util import strtobool
from io import BytesIO
from itertools import chain
from typing import Any, Dict, Mapping, Optional, Tuple
from typing import Any, Dict, Mapping, Optional

from lxml import etree
from lxml.builder import ElementMaker
from lxml.etree import DocumentInvalid, ElementTree
from xmlsec.crypto import CertDict

from .constants import ATTRS, NF_URI, NS, config
from .exceptions import *
from .logs import get_log
from .parse import PyffParser, add_parser
from .resource import Resource, ResourceOpts
from .utils import (
from pyff.constants import ATTRS, NF_URI, NS, config
from pyff.exceptions import *
from pyff.logs import get_log
from pyff.parse import PyffParser, add_parser
from pyff.resource import Resource, ResourceOpts
from pyff.utils import (
Lambda,
b2u,
check_signature,
Expand Down Expand Up @@ -89,7 +89,6 @@ def parse_saml_metadata(
:param opts: ResourceOpts instance
:param base_url: use this base url to resolve relative URLs for XInclude processing
:param validation_errors: A dict that will be used to return validation errors to the caller
:param cleanup: A list of callables that can be used to pre-process parsed metadata before validation. Use as a clue-bat.

:return: Tuple with t (ElementTree), expire_time_offset, exception
"""
Expand Down
11 changes: 5 additions & 6 deletions src/pyff/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
from whoosh.qparser import MultifieldParser, QueryParser
from whoosh.writing import CLEAR

from pyff import merge_strategies
from pyff.constants import ATTRS, ATTRS_INV, NS, config
from pyff.logs import get_log
from pyff.resource import IconHandler

from . import merge_strategies
from .constants import ATTRS, ATTRS_INV, NS, config
from .logs import get_log
from .samlmd import (
from pyff.samlmd import (
EntitySet,
discojson,
entitiesdescriptor,
Expand All @@ -37,7 +36,7 @@
iter_entities,
object_id,
)
from .utils import (
from pyff.utils import (
LRUProxyDict,
avg_domain_distance,
b2u,
Expand Down
1 change: 0 additions & 1 deletion src/pyff/test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
import random
import socket
import subprocess
import sys
Expand Down
1 change: 0 additions & 1 deletion src/pyff/test/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import fakeredis

from pyff.constants import ATTRS
from pyff.samlmd import iter_entities
from pyff.store import MemoryStore, RedisWhooshStore, SAMLStoreBase, entity_attribute_dict
from pyff.utils import parse_xml, resource_filename, root

Expand Down
2 changes: 1 addition & 1 deletion src/pyff/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
url_get,
)

from ..merge_strategies import remove, replace_existing
from pyff.merge_strategies import remove, replace_existing


class TestMetadata(TestCase):
Expand Down
8 changes: 4 additions & 4 deletions src/pyff/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from xmldiff.formatting import DiffFormatter
from xmldiff.main import diff_trees

from .constants import config, parse_options
from .resource import Resource
from .samlmd import diff, iter_entities
from .store import MemoryStore
from pyff.constants import config, parse_options
from pyff.resource import Resource
from pyff.samlmd import diff, iter_entities
from pyff.store import MemoryStore


def difftool():
Expand Down
10 changes: 5 additions & 5 deletions src/pyff/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from itertools import chain
from threading import local
from time import gmtime, strftime
from typing import Any, BinaryIO, Callable, Optional, Union
from typing import BinaryIO, Callable, Optional, Union

import pkg_resources
import requests
Expand All @@ -45,10 +45,10 @@
from requests_file import FileAdapter
from six.moves.urllib_parse import urlparse

from . import __version__
from .constants import NS, config
from .exceptions import *
from .logs import get_log
from pyff import __version__
from pyff.constants import NS, config
from pyff.exceptions import *
from pyff.logs import get_log

etree.set_default_parser(etree.XMLParser(resolve_entities=False))

Expand Down
4 changes: 2 additions & 2 deletions src/pyff/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from wsgiref.simple_server import make_server

from .api import mkapp
from .repo import MDRepository
from pyff.api import mkapp
from pyff.repo import MDRepository

md = MDRepository()
app = mkapp(md=md)
Expand Down