Skip to content

Commit 462b86f

Browse files
committed
black
1 parent 15fe7e5 commit 462b86f

File tree

5 files changed

+90
-113
lines changed

5 files changed

+90
-113
lines changed

buildout.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ parts =
88

99
[versions]
1010
experimental.catalogplan =
11+
packaging = 24.1
1112

1213
[interpreter]
1314
recipe = zc.recipe.egg

setup.py

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
# -*- coding: utf-8 -*-
22
from setuptools import find_packages, setup
33

4-
version = '1.0.0a4.dev0'
4+
version = "1.0.0a4.dev0"
55

6-
setup(name='experimental.catalogplan',
7-
version=version,
8-
description="Experimental ZCatalog plan",
9-
long_description=(open("README.rst").read() + "\n" +
10-
open("CHANGES.rst").read()),
11-
long_description_content_type="text/x-rst",
12-
# Get more strings from
13-
# http://pypi.python.org/pypi?:action=list_classifiers
14-
classifiers=[
15-
'Framework :: Zope2',
16-
'Framework :: Plone',
17-
'Framework :: Plone :: 4.3',
18-
'Framework :: Plone :: 5.0',
19-
'Framework :: Plone :: 5.1',
20-
'Framework :: Plone :: 5.2',
21-
'License :: OSI Approved :: GNU General Public License v2 (GPLv2)',
22-
'Programming Language :: Python',
23-
'Programming Language :: Python :: 2.7',
24-
'Programming Language :: Python :: 3.7',
25-
'Programming Language :: Python :: 3.8',
26-
'Programming Language :: Python :: 3.9',
27-
'Programming Language :: Python :: 3.10',
28-
],
29-
keywords='monkeypatch traverse',
30-
author='Mauro Amico',
31-
author_email='mauro.amico@gmail.com',
32-
url='https://github.com/mamico/experimental.catalogplan',
33-
project_urls={
34-
'Issue Tracker': 'https://github.com/mamico/'
35-
'experimental.catalogplan/issues',
36-
'Sources': 'https://github.com/mamico/experimental.catalogplan',
37-
},
38-
license='BSD',
39-
packages=find_packages('src'),
40-
package_dir={'': 'src'},
41-
namespace_packages=['experimental', ],
42-
include_package_data=True,
43-
zip_safe=False,
44-
test_suite="experimental.catalogplan",
45-
install_requires=[
46-
'setuptools',
47-
# -*- Extra requirements: -*-
48-
'Products.ZCatalog>3.0,<6.3',
49-
],
50-
extras_require={
51-
'test': ['Products.CMFPlone[test]']
52-
},
53-
entry_points="""
6+
setup(
7+
name="experimental.catalogplan",
8+
version=version,
9+
description="Experimental ZCatalog plan",
10+
long_description=(open("README.rst").read() + "\n" + open("CHANGES.rst").read()),
11+
long_description_content_type="text/x-rst",
12+
# Get more strings from
13+
# http://pypi.python.org/pypi?:action=list_classifiers
14+
classifiers=[
15+
"Framework :: Zope2",
16+
"Framework :: Plone",
17+
"Framework :: Plone :: 4.3",
18+
"Framework :: Plone :: 5.0",
19+
"Framework :: Plone :: 5.1",
20+
"Framework :: Plone :: 5.2",
21+
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
22+
"Programming Language :: Python",
23+
"Programming Language :: Python :: 2.7",
24+
"Programming Language :: Python :: 3.7",
25+
"Programming Language :: Python :: 3.8",
26+
"Programming Language :: Python :: 3.9",
27+
"Programming Language :: Python :: 3.10",
28+
],
29+
keywords="monkeypatch traverse",
30+
author="Mauro Amico",
31+
author_email="mauro.amico@gmail.com",
32+
url="https://github.com/mamico/experimental.catalogplan",
33+
project_urls={
34+
"Issue Tracker": "https://github.com/mamico/" "experimental.catalogplan/issues",
35+
"Sources": "https://github.com/mamico/experimental.catalogplan",
36+
},
37+
license="BSD",
38+
packages=find_packages("src"),
39+
package_dir={"": "src"},
40+
namespace_packages=[
41+
"experimental",
42+
],
43+
include_package_data=True,
44+
zip_safe=False,
45+
test_suite="experimental.catalogplan",
46+
install_requires=[
47+
"setuptools",
48+
# -*- Extra requirements: -*-
49+
"six",
50+
"Products.ZCatalog>3.0",
51+
],
52+
extras_require={"test": ["Products.CMFPlone[test]"]},
53+
entry_points="""
5454
# -*- Entry points: -*-
5555
[z3c.autoinclude.plugin]
5656
target = plone
5757
""",
58-
)
58+
)

src/experimental/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# -*- coding: utf-8 -*-
22
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
33
try:
4-
__import__('pkg_resources').declare_namespace(__name__)
4+
__import__("pkg_resources").declare_namespace(__name__)
55
except ImportError:
66
from pkgutil import extend_path
7+
78
__path__ = extend_path(__path__, __name__)

src/experimental/catalogplan/__init__.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
import logging
33
import time
4-
4+
from importlib.metadata import version
55
from Products.PluginIndexes.interfaces import ILimitedResultIndex
66
from Products.ZCatalog.plan import Benchmark, CatalogPlan, PriorityMap
77

@@ -49,27 +49,23 @@ def CatalogPlan_make_key(self, query):
4949
key.append((name, repr(v)))
5050

5151
# --------- >8 ------------------------------------------------
52-
operatorkeys = [
53-
name for name in key
54-
if isinstance(query.get(name), dict)
55-
]
52+
operatorkeys = [name for name in key if isinstance(query.get(name), dict)]
5653
if operatorkeys:
5754
key = [name for name in key if name not in operatorkeys]
58-
key.extend([
59-
(name, tuple(sorted(query[name].keys()))) for name in operatorkeys
60-
])
55+
key.extend([(name, tuple(sorted(query[name].keys()))) for name in operatorkeys])
6156
# --------- 8< ------------------------------------------------
6257

6358
# Workaround: Python 2.x accepted different types as sort key
6459
# for the sorted builtin. Python 3 only sorts on identical types.
65-
tuple_keys = set(key) - set(
66-
[x for x in key if not isinstance(x, tuple)])
60+
tuple_keys = set(key) - set([x for x in key if not isinstance(x, tuple)])
6761
str_keys = set(key) - tuple_keys
6862
return tuple(sorted(str_keys)) + tuple(sorted(tuple_keys))
6963

7064

71-
logger.info("*** CatalogPlan.stop monkey patch ***")
72-
CatalogPlan.stop = CatalogPlan_stop
65+
# if ZCatalog < 6.4
66+
if version("Products.ZCatalog") < "6.4":
67+
logger.info("*** CatalogPlan.stop monkey patch ***")
68+
CatalogPlan.stop = CatalogPlan_stop
7369

74-
logger.info("*** CatalogPlan.make_key monkey patch ***")
75-
CatalogPlan.make_key = CatalogPlan_make_key
70+
logger.info("*** CatalogPlan.make_key monkey patch ***")
71+
CatalogPlan.make_key = CatalogPlan_make_key

src/experimental/catalogplan/tests/test_plan.py

Lines changed: 27 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def numbers(self):
2727
return (self.num, self.num + 1)
2828

2929
def getPhysicalPath(self):
30-
return '/{0}'.format(self.num)
30+
return "/{0}".format(self.num)
3131

3232
def start(self):
33-
return '2013-07-{0:02d}'.format(self.num + 1)
33+
return "2013-07-{0:02d}".format(self.num + 1)
3434

3535
def end(self):
36-
return '2013-07-{0:02d}'.format(self.num + 2)
36+
return "2013-07-{0:02d}".format(self.num + 2)
3737

3838

3939
class TestCatalogPlan(cleanup.CleanUp, unittest.TestCase):
@@ -46,10 +46,11 @@ def assertRegex(self, *args, **kwargs):
4646

4747
def setUp(self):
4848
cleanup.CleanUp.setUp(self)
49-
self.cat = Catalog('catalog')
49+
self.cat = Catalog("catalog")
5050

5151
def _makeOne(self, catalog=None, query=None):
5252
from Products.ZCatalog.plan import CatalogPlan
53+
5354
if catalog is None:
5455
catalog = self.cat
5556
return CatalogPlan(catalog, query=query)
@@ -61,14 +62,12 @@ def test_getCatalogPlan_partial(self):
6162
class SlowFieldIndex(FieldIndex):
6263
def query_index(self, record, resultset=None):
6364
time.sleep(0.1)
64-
return super(SlowFieldIndex, self).query_index(
65-
record, resultset)
65+
return super(SlowFieldIndex, self).query_index(record, resultset)
6666

6767
class SlowerDateRangeIndex(DateRangeIndex):
6868
def query_index(self, record, resultset=None):
6969
time.sleep(0.2)
70-
return super(SlowerDateRangeIndex, self).query_index(
71-
record, resultset)
70+
return super(SlowerDateRangeIndex, self).query_index(record, resultset)
7271

7372
cat.addIndex("num", SlowFieldIndex("num"))
7473
cat.addIndex("numbers", KeywordIndex("numbers"))
@@ -85,95 +84,75 @@ def query_index(self, record, resultset=None):
8584

8685
# without a plan index are orderd alphabetically by default
8786
self.assertEqual(zcat._catalog.getCatalogPlan(query1).plan(), None)
88-
self.assertEqual(
89-
cat._sorted_search_indexes(query1),
90-
["date", "num", "numbers"]
91-
)
87+
self.assertEqual(cat._sorted_search_indexes(query1), ["date", "num", "numbers"])
9288

9389
self.assertEqual([b.getPath() for b in zcat.search(query1)], ["2"])
9490
self.assertRegex(
95-
zcat.getCatalogPlan(),
96-
r"(?ms).*'date':\s*\([0-9\.]+, [0-9\.]+, True\)"
91+
zcat.getCatalogPlan(), r"(?ms).*'date':\s*\([0-9\.]+, [0-9\.]+, True\)"
9792
)
9893
self.assertRegex(
99-
zcat.getCatalogPlan(),
100-
r"(?ms).*'num':\s*\([0-9\.]+, [0-9\.]+, True\)"
94+
zcat.getCatalogPlan(), r"(?ms).*'num':\s*\([0-9\.]+, [0-9\.]+, True\)"
10195
)
10296
self.assertRegex(
103-
zcat.getCatalogPlan(),
104-
r"(?ms).*'numbers':\s*\([0-9\.]+, [0-9\.]+, True\)"
97+
zcat.getCatalogPlan(), r"(?ms).*'numbers':\s*\([0-9\.]+, [0-9\.]+, True\)"
10598
)
10699

107100
# after first search field are orderd by speed
108-
self.assertEqual(
109-
cat.getCatalogPlan(query2).plan(), ["numbers", "num", "date"])
101+
self.assertEqual(cat.getCatalogPlan(query2).plan(), ["numbers", "num", "date"])
110102

111103
self.assertEqual([b.getPath() for b in zcat.search(query2)], [])
112104

113105
# `date', `num`, and `numbers` are all involved to filter the
114106
# results(limit flag) despite in the last query search whitin
115107
# `num` and `date` wasn't done
116108
self.assertRegex(
117-
zcat.getCatalogPlan(),
118-
r"(?ms).*'date':\s*\([0-9\.]+, [0-9\.]+, True\)"
109+
zcat.getCatalogPlan(), r"(?ms).*'date':\s*\([0-9\.]+, [0-9\.]+, True\)"
119110
)
120111
self.assertRegex(
121-
zcat.getCatalogPlan(),
122-
r"(?ms).*'num':\s*\([0-9\.]+, [0-9\.]+, True\)"
112+
zcat.getCatalogPlan(), r"(?ms).*'num':\s*\([0-9\.]+, [0-9\.]+, True\)"
123113
)
124114
self.assertRegex(
125-
zcat.getCatalogPlan(),
126-
r"(?ms).*'numbers':\s*\([0-9\.]+, [0-9\.]+, True\)"
127-
)
128-
self.assertEqual(
129-
cat.getCatalogPlan(query2).plan(), ["numbers", "num", "date"]
115+
zcat.getCatalogPlan(), r"(?ms).*'numbers':\s*\([0-9\.]+, [0-9\.]+, True\)"
130116
)
117+
self.assertEqual(cat.getCatalogPlan(query2).plan(), ["numbers", "num", "date"])
131118

132119
# search again doesn't change the index order
133120
self.assertEqual([b.getPath() for b in zcat.search(query1)], ["2"])
134-
self.assertEqual(
135-
cat.getCatalogPlan(query2).plan(), ["numbers", "num", "date"]
136-
)
121+
self.assertEqual(cat.getCatalogPlan(query2).plan(), ["numbers", "num", "date"])
137122

138123
def test_not_query(self):
139124
# not query is generally slower, force this behavior for testing
140125
class SlowNotFieldIndex(FieldIndex):
141126
def query_index(self, record, resultset=None):
142-
if getattr(record, 'not', None):
127+
if getattr(record, "not", None):
143128
time.sleep(0.1)
144-
return super(SlowNotFieldIndex, self).query_index(
145-
record, resultset)
129+
return super(SlowNotFieldIndex, self).query_index(record, resultset)
146130

147131
zcat = ZCatalog("catalog")
148132
cat = zcat._catalog
149-
cat.addIndex(
150-
'num1', SlowNotFieldIndex('num1', extra={"indexed_attrs": "num"}))
151-
cat.addIndex(
152-
'num2', SlowNotFieldIndex('num2', extra={"indexed_attrs": "num"}))
133+
cat.addIndex("num1", SlowNotFieldIndex("num1", extra={"indexed_attrs": "num"}))
134+
cat.addIndex("num2", SlowNotFieldIndex("num2", extra={"indexed_attrs": "num"}))
153135
for i in range(100):
154136
obj = Dummy(i)
155137
zcat.catalog_object(obj, str(i))
156138

157139
query1 = {"num1": {"not": 2}, "num2": 3}
158-
query2 = {"num1": 2, "num2": {'not': 5}}
140+
query2 = {"num1": 2, "num2": {"not": 5}}
159141

160142
# without a plan index are orderd alphabetically by default
161143
for query in [query1, query2]:
162144
self.assertEqual(zcat._catalog.getCatalogPlan(query).plan(), None)
163-
self.assertEqual(
164-
cat._sorted_search_indexes(query),
165-
["num1", "num2"]
166-
)
145+
self.assertEqual(cat._sorted_search_indexes(query), ["num1", "num2"])
167146

168-
self.assertEqual([b.getPath() for b in zcat.search(query1)], ['3'])
169-
self.assertEqual([b.getPath() for b in zcat.search(query2)], ['2'])
147+
self.assertEqual([b.getPath() for b in zcat.search(query1)], ["3"])
148+
self.assertEqual([b.getPath() for b in zcat.search(query2)], ["2"])
170149
# although there are the same fields, the plans are different, and the
171150
# slower `not` query put the field as second in the plan
172151
self.assertEqual(cat.getCatalogPlan(query1).plan(), ["num2", "num1"])
173152
self.assertEqual(cat.getCatalogPlan(query2).plan(), ["num1", "num2"])
174153

175154
# search again doesn't change the order
176-
self.assertEqual([b.getPath() for b in zcat.search(query1)], ['3'])
177-
self.assertEqual([b.getPath() for b in zcat.search(query2)], ['2'])
155+
self.assertEqual([b.getPath() for b in zcat.search(query1)], ["3"])
156+
self.assertEqual([b.getPath() for b in zcat.search(query2)], ["2"])
178157
self.assertEqual(cat.getCatalogPlan(query1).plan(), ["num2", "num1"])
179158
self.assertEqual(cat.getCatalogPlan(query2).plan(), ["num1", "num2"])

0 commit comments

Comments
 (0)