Skip to content

Commit

Permalink
Isort imports + fix Sphinx config. (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
icemac committed Feb 29, 2024
1 parent 55f3bb5 commit 2b2e271
Show file tree
Hide file tree
Showing 22 changed files with 76 additions and 49 deletions.
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'https://docs.python.org/3/': None,
'https://persistent.readthedocs.io/en/latest/': None,
"https://zodb.org/en/latest/": None,
"https://zopeinterface.readthedocs.io/en/latest/": None,
'python': ('https://docs.python.org/3/', None),
'persistent': ("https://persistent.readthedocs.io/en/latest/", None),
'zodb': ("https://zodb.org/en/latest/", None),
'zopeinterface': ("https://zopeinterface.readthedocs.io/en/latest/", None),
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import os
import sys

from distutils.errors import CCompilerError
from distutils.errors import DistutilsExecError
from distutils.errors import DistutilsPlatformError
Expand All @@ -24,6 +23,7 @@
from setuptools import setup
from setuptools.command.build_ext import build_ext


version = '5.3.dev0'

def _read(fname):
Expand Down
6 changes: 4 additions & 2 deletions src/BTrees/Interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#
##############################################################################

from zope.interface import Interface, Attribute
from zope.interface import Attribute
from zope.interface import Interface
from zope.interface.common.collections import IMapping
from zope.interface.common.collections import ISized
from zope.interface.common.sequence import IMinimalSequence
from zope.interface.common.collections import IMapping


# pylint:disable=inherit-non-class,no-method-argument,no-self-argument
# pylint:disable=unexpected-special-method-signature
Expand Down
1 change: 1 addition & 0 deletions src/BTrees/Length.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import persistent


class Length(persistent.Persistent):
"""BTree lengths are often too expensive to compute.
Expand Down
16 changes: 8 additions & 8 deletions src/BTrees/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
#############################################################################

import sys

import zope.interface

import BTrees.Interfaces

from ._module_builder import create_module


__all__ = [
'family32',
'family64',
Expand Down Expand Up @@ -88,14 +92,12 @@ def __repr__(self):

class _Family32(_Family):
_BITSIZE = 32
from BTrees import OIBTree as OI
from BTrees import OUBTree as OU

from BTrees import IFBTree as IF
from BTrees import IIBTree as II
from BTrees import IOBTree as IO
from BTrees import IUBTree as IU

from BTrees import OIBTree as OI
from BTrees import OUBTree as OU
from BTrees import UFBTree as UF
from BTrees import UIBTree as UI
from BTrees import UOBTree as UO
Expand All @@ -106,14 +108,12 @@ def __reduce__(self):

class _Family64(_Family):
_BITSIZE = 64
from BTrees import OLBTree as OI
from BTrees import OQBTree as OU

from BTrees import LFBTree as IF
from BTrees import LLBTree as II
from BTrees import LOBTree as IO
from BTrees import LQBTree as IU

from BTrees import OLBTree as OI
from BTrees import OQBTree as OU
from BTrees import QFBTree as UF
from BTrees import QLBTree as UI
from BTrees import QOBTree as UO
Expand Down
3 changes: 2 additions & 1 deletion src/BTrees/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

from persistent import Persistent

from .Interfaces import BTreesConflictError
from ._compat import compare
from .Interfaces import BTreesConflictError


# XXX: Fix these. These ignores are temporary to
# reduce the noise and help find specific issues during
Expand Down
1 change: 1 addition & 0 deletions src/BTrees/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import sys


PYPY = hasattr(sys, 'pypy_version_info')

def compare(x, y):
Expand Down
4 changes: 2 additions & 2 deletions src/BTrees/_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
Descriptions of the datatypes supported by this package.
"""

from abc import ABC
from operator import index as operator__index__
from struct import Struct
from struct import error as struct_error

from abc import ABC

from .utils import Lazy


# pylint:disable=raise-missing-from

class DataType:
Expand Down
18 changes: 10 additions & 8 deletions src/BTrees/_module_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@
BTree modules.
"""
import sys
from zope.interface import directlyProvides

from zope.interface import classImplements
from zope.interface import directlyProvides


def _create_classes(
module_name, key_datatype, value_datatype,
):
from ._base import MERGE # Won't always want this.
from ._base import Bucket
from ._base import MERGE # Won't always want this.
from ._base import Set
from ._base import Tree
from ._base import TreeSet
from ._base import _fix_pickle
from ._base import _TreeItems as TreeItems
from ._base import _TreeIterator
from ._base import _fix_pickle

classes = {}

Expand Down Expand Up @@ -84,11 +85,10 @@ def _create_classes(
return classes

def _create_set_operations(module_name, key_type, value_type, set_type):
from ._base import set_operation

from ._base import difference
from ._base import intersection
from ._base import multiunion
from ._base import set_operation
from ._base import union
from ._base import weightedIntersection
from ._base import weightedUnion
Expand Down Expand Up @@ -128,10 +128,11 @@ def _create_globals(module_name, key_datatype, value_datatype):
def populate_module(mod_globals,
key_datatype, value_datatype,
interface, module=None):
from . import Interfaces as interfaces
from ._compat import import_c_extension
import collections.abc

from . import Interfaces as interfaces
from ._base import _fix_pickle
from ._compat import import_c_extension

module_name = mod_globals['__name__']
# Define the Python implementations
Expand Down Expand Up @@ -204,8 +205,9 @@ def populate_module(mod_globals,

def create_module(prefix):
import types
from . import _datatypes as datatypes

from . import Interfaces
from . import _datatypes as datatypes

mod = types.ModuleType('BTrees.' + prefix + 'BTree')

Expand Down
1 change: 1 addition & 0 deletions src/BTrees/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# FOR A PARTICULAR PURPOSE
#
##############################################################################
# isort: skip_file
"""
Utilities for working with BTrees (TreeSets, Buckets, and Sets) at a low
level.
Expand Down
4 changes: 2 additions & 2 deletions src/BTrees/tests/_test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
from .common import NormalSetTests
from .common import SetConflictTestBase
from .common import SetResult
from .common import TestLongIntKeys
from .common import TestLongIntValues
from .common import Weighted
from .common import itemsToSet
from .common import makeMapBuilder
from .common import makeSetBuilder
from .common import TestLongIntKeys
from .common import TestLongIntValues


class _FilteredModuleProxy:
Expand Down
20 changes: 12 additions & 8 deletions src/BTrees/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
#
##############################################################################

import sys
import functools
import unittest
import platform
import sys
import unittest
from unittest import skip

from BTrees._compat import _c_optimizations_ignored
from BTrees._base import _tp_name
from BTrees._compat import PYPY
from BTrees._base import _tp_name
from BTrees._compat import _c_optimizations_ignored


def _no_op(test_method):
return test_method
Expand Down Expand Up @@ -107,6 +108,7 @@ def _getRoot(self):

def _closeRoot(self, root):
import transaction

# If we don't commit/abort the transaction, then
# closing the Connection tends to fail with
# "Cannot close connection joined to transaction"
Expand Down Expand Up @@ -1355,8 +1357,8 @@ def testAccessRaisesPOSKeyErrorOnSelf(self):
# We don't hide a POSKeyError that happens when
# accessing the object itself in `get()`.
# See https://github.com/zopefoundation/BTrees/issues/161
from ZODB.POSException import POSKeyError
import transaction
from ZODB.POSException import POSKeyError
transaction.begin()
m = self._makeOne()
root = self._getRoot()
Expand Down Expand Up @@ -1413,8 +1415,8 @@ def testAccessRaisesPOSKeyErrorOnNested(self):
# We don't hide a POSKeyError that happens when
# accessing sub objects in `get()`.
# See https://github.com/zopefoundation/BTrees/issues/161
from ZODB.POSException import POSKeyError
import transaction
from ZODB.POSException import POSKeyError
transaction.begin()
m = self._makeOne()
root = self._getRoot()
Expand Down Expand Up @@ -2931,8 +2933,9 @@ def testDifference(self):
self.assertEqual(set(A) - set(B), set(A - B))

def testLargerInputs(self): # pylint:disable=too-many-locals
from BTrees.IIBTree import IISet # pylint:disable=no-name-in-module
from random import randint

from BTrees.IIBTree import IISet # pylint:disable=no-name-in-module
MAXSIZE = 200
MAXVAL = 400
K = self.KEYS
Expand Down Expand Up @@ -3277,8 +3280,9 @@ def _makeOne(self):

def openDB(self):
import os
from ZODB.FileStorage import FileStorage

from ZODB.DB import DB
from ZODB.FileStorage import FileStorage
n = 'fs_tmp__%s' % os.getpid()
self.storage = FileStorage(n)
self.db = DB(self.storage)
Expand Down
5 changes: 4 additions & 1 deletion src/BTrees/tests/testBTrees.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class DegenerateBTree(unittest.TestCase):

def _build_degenerate_tree(self):
# Build the buckets and chain them together.
from BTrees.check import check
from BTrees.IIBTree import IISet
from BTrees.IIBTree import IITreeSet
from BTrees.check import check
bucket11 = IISet([11])

bucket7 = IISet()
Expand Down Expand Up @@ -255,6 +255,7 @@ def test_LP294788(self):
# To simulate real life, some random data is used to exercise the tree
import gc
import random

from BTrees.OOBTree import OOBTree

t = OOBTree()
Expand Down Expand Up @@ -431,6 +432,7 @@ def testFoo(self):
class FamilyTest(unittest.TestCase):
def test32(self):
from zope.interface.verify import verifyObject

import BTrees
from BTrees.IOBTree import IOTreeSet
verifyObject(BTrees.Interfaces.IBTreeFamily, BTrees.family32)
Expand Down Expand Up @@ -473,6 +475,7 @@ def test32(self):

def test64(self):
from zope.interface.verify import verifyObject

import BTrees
from BTrees.LOBTree import LOTreeSet
verifyObject(BTrees.Interfaces.IBTreeFamily, BTrees.family64)
Expand Down
5 changes: 3 additions & 2 deletions src/BTrees/tests/testConflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
##############################################################################
import unittest

from .common import _skip_wo_ZODB
from .common import ConflictTestBase
from .common import _skip_wo_ZODB


class NastyConfictFunctionalTests(ConflictTestBase, unittest.TestCase):
Expand All @@ -38,7 +38,8 @@ def openDB(self):
# serialization (ordering) of the datamanager, and the fact that these tests are
# single-threaded.
import threading
from ZODB.tests.MVCCMappingStorage import MVCCMappingStorage

from ZODB.tests.MVCCMappingStorage import MVCCMappingStorage
class _MVCCMappingStorage(MVCCMappingStorage):
def new_instance(self):
inst = MVCCMappingStorage.new_instance(self)
Expand Down
3 changes: 2 additions & 1 deletion src/BTrees/tests/testPersistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from unittest import TestCase

from ..OOBTree import OOBTree
from .common import _skip_wo_ZODB, ZODBAccess
from .common import ZODBAccess
from .common import _skip_wo_ZODB


BUCKET_SIZE = OOBTree.max_leaf_size
Expand Down
7 changes: 5 additions & 2 deletions src/BTrees/tests/test_OOBTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
##############################################################################
from BTrees import OOBTree

from .common import BTreeTests
from ._test_builder import update_module
from .common import BTreeTests


class OOBTreeTest(BTreeTests):

Expand Down Expand Up @@ -111,7 +112,9 @@ def test_None_is_smallest(self):

if 'Py' in self.__class__.__name__:
return
from BTrees.OOBTree import difference, union, intersection
from BTrees.OOBTree import difference
from BTrees.OOBTree import intersection
from BTrees.OOBTree import union
self.assertEqual(list(difference(t2, t).items()), [(None, -2)])
self.assertEqual(list(union(t, t2)), list(t2))
self.assertEqual(list(intersection(t, t2)), list(t))
Expand Down
2 changes: 1 addition & 1 deletion src/BTrees/tests/test__base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,8 +1465,8 @@ def _getTargetClass(self):

def _makeOne(self, items=None, bucket_type=None):
from .._base import Bucket
from .._datatypes import O
from .._datatypes import Any
from .._datatypes import O
if bucket_type is None:
class _Bucket(Bucket):
_to_key = O()
Expand Down
Loading

0 comments on commit 2b2e271

Please sign in to comment.