Skip to content

Commit

Permalink
Add several linters via pre-commit
Browse files Browse the repository at this point in the history
modified:   .pre-commit-config.yaml
modified:   setup.py
modified:   src/Products/ZopeTree/IZopeTree.py
modified:   src/Products/ZopeTree/TreeObjectWrapper.py
modified:   src/Products/ZopeTree/ZopeTree.py
modified:   src/Products/ZopeTree/__init__.py
modified:   src/Products/ZopeTree/tests/test_ZopeTree.py
modified:   src/Products/__init__.py
modified:   tox.ini
  • Loading branch information
jugmac00 committed Oct 1, 2020
1 parent 2b867d3 commit 63c68a1
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 138 deletions.
26 changes: 21 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
repos:
- repo: https://github.com/mgedmin/check-python-versions
rev: 0.15.1
hooks:
- id: check-python-versions
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
rev: v3.2.0
hooks:
- id: debug-statements
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black
language_version: python3.6
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
- repo: https://github.com/mgedmin/check-manifest
rev: "0.39"
- id: flake8
additional_dependencies:
- flake8-click==0.3.1
- flake8-bugbear==20.1.4
- repo: https://github.com/PyCQA/isort.git
rev: 5.5.4
hooks:
- id: check-manifest
- id: isort
90 changes: 44 additions & 46 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
from setuptools import find_packages
from setuptools import setup
from setuptools import find_packages, setup

setup(name='Products.ZopeTree',
version='2.0.2.dev0',
url='https://github.com/jugmac00/Products.ZopeTree',
project_urls={
'Issue Tracker':
'https://github.com/jugmac00/Products.ZopeTree/issues',
'Sources':
'https://github.com/jugmac00/Products.ZopeTree',
},
description="ZopeTree is a light-weight tree implementation.",
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
maintainer='Juergen Gmach',
maintainer_email="juergen.gmach@googlemail.com",
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Zope :: 4',
'Framework :: Zope :: 5',
'Intended Audience :: Developers',
'License :: OSI Approved :: Mozilla Public License 1.1 (MPL 1.1)',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
],
packages=find_packages('src'),
namespace_packages=['Products'],
package_dir={'': 'src'},
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*',
install_requires=[
'Zope',
'setuptools',
'six',
'AccessControl',
'zope.interface',
'zope.testing',
],
include_package_data=True,
zip_safe=False,
options={"bdist_wheel": {"universal": "1"}},
)
setup(
name="Products.ZopeTree",
version="2.0.2.dev0",
url="https://github.com/jugmac00/Products.ZopeTree",
project_urls={
"Issue Tracker": "https://github.com/jugmac00/Products.ZopeTree/issues",
"Sources": "https://github.com/jugmac00/Products.ZopeTree",
},
description="ZopeTree is a light-weight tree implementation.",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
maintainer="Juergen Gmach",
maintainer_email="juergen.gmach@googlemail.com",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Framework :: Zope :: 4",
"Framework :: Zope :: 5",
"Intended Audience :: Developers",
"License :: OSI Approved :: Mozilla Public License 1.1 (MPL 1.1)",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
packages=find_packages("src"),
namespace_packages=["Products"],
package_dir={"": "src"},
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*",
install_requires=[
"Zope",
"setuptools",
"six",
"AccessControl",
"zope.interface",
"zope.testing",
],
include_package_data=True,
zip_safe=False,
options={"bdist_wheel": {"universal": "1"}},
)
32 changes: 22 additions & 10 deletions src/Products/ZopeTree/IZopeTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@
# License (MPL)
#

from zope.interface import Interface, Attribute
from zope.interface import Attribute, Interface


class INode(Interface):

object = Attribute("""
object = Attribute(
"""
The object that is being wrapped.
""")
"""
)

depth = Attribute("""
depth = Attribute(
"""
The positional depth of this node in the tree.
""")
"""
)

expanded = Attribute("""
expanded = Attribute(
"""
True if this node is expanded.
""")
"""
)

def __init__(object, depth, id_attr, children_attr, expanded_nodes=[]):
"""
Expand Down Expand Up @@ -79,9 +85,15 @@ def getFlatNodes():


class IZopeTree(INode):

def __init__(root_object, id_attr='', children_attr='', request=None,
request_variable='', expanded_nodes=[], set_cookie=1):
def __init__(
root_object,
id_attr="",
children_attr="",
request=None,
request_variable="",
expanded_nodes=[],
set_cookie=1,
):
"""
'root_object' is the root object of the tree.
Expand Down
2 changes: 1 addition & 1 deletion src/Products/ZopeTree/TreeObjectWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TreeObjectWrapper:

__allow_access_to_unprotected_subobjects__ = 1

def __init__(self, obj, path=''):
def __init__(self, obj, path=""):
self.path = path
self.object = obj
self.id = obj.getId()
Expand Down
62 changes: 37 additions & 25 deletions src/Products/ZopeTree/ZopeTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
"""

import zlib

import zope.interface
from ZTUtils.Tree import b2a, a2b
from ZTUtils.Tree import a2b, b2a

from Products.ZopeTree.IZopeTree import IZopeTree, INode
from Products.ZopeTree.IZopeTree import INode, IZopeTree


@zope.interface.implementer(INode)
Expand Down Expand Up @@ -48,13 +49,17 @@ def _create_children_nodes(self):
return
nodes = []
for obj in children:
node = Node(obj, self.depth+1, self._id_attr,
self._children_attr, self._expanded_nodes)
node = Node(
obj,
self.depth + 1,
self._id_attr,
self._children_attr,
self._expanded_nodes,
)
nodes.append(node)
self._children_nodes = nodes

def __init__(self, object, depth, id_attr, children_attr,
expanded_nodes=[]):
def __init__(self, object, depth, id_attr, children_attr, expanded_nodes=[]):
# attributes required by the interface
self.object = object
self.depth = depth
Expand Down Expand Up @@ -90,7 +95,7 @@ def getChildrenNodes(self):
return []
# children nodes are not created until they are explicitly requested
# through this function
if not hasattr(self, '_children_nodes'):
if not hasattr(self, "_children_nodes"):
self._create_children_nodes()
return self._children_nodes[:]

Expand All @@ -105,13 +110,13 @@ def getFlatNodes(self):
def safe_decompress(input, max_size=10240):
# this sillyness can go away in python 2.2
decomp = zlib.decompressobj()
output = ''
output = ""
while input:
fragment_size = max(1, (max_size-len(output))/1000)
fragment_size = max(1, (max_size - len(output)) / 1000)
fragment, input = input[:fragment_size], input[fragment_size:]
output += decomp.decompress(fragment)
if len(output) > max_size:
raise ValueError('Compressed input too large')
raise ValueError("Compressed input too large")
return output + decomp.flush()


Expand All @@ -120,19 +125,24 @@ class ZopeTree(Node):

__allow_access_to_unprotected_subobjects__ = 1

def __init__(self, root_object, id_attr='getId',
children_attr='objectValues', request=None,
request_variable='tree-expansion', expanded_nodes=[],
set_cookie=1):
def __init__(
self,
root_object,
id_attr="getId",
children_attr="objectValues",
request=None,
request_variable="tree-expansion",
expanded_nodes=[],
set_cookie=1,
):
tree_expansion = request.get(request_variable, "")
if tree_expansion:
if set_cookie:
# set a cookie right away
request.RESPONSE.setCookie(request_variable, tree_expansion)
expanded_nodes = self.decodeTreeExpansion(tree_expansion)

Node.__init__(self, root_object, 0, id_attr, children_attr,
expanded_nodes)
Node.__init__(self, root_object, 0, id_attr, children_attr, expanded_nodes)
self.expand()

def encodeTreeExpansion(self, expanded_nodes):
Expand All @@ -146,7 +156,7 @@ def decodeTreeExpansion(self, tree_expansion):
tree_expansion = a2b(tree_expansion)
tree_expansion = zlib.decompress(tree_expansion)
if not isinstance(tree_expansion, str):
tree_expansion = tree_expansion.decode('utf-8')
tree_expansion = tree_expansion.decode("utf-8")
return tree_expansion.split(":")

def getFlatDicts(self):
Expand All @@ -162,14 +172,16 @@ def getFlatDicts(self):
else:
# if it isn't, the next step is expanding it.
expanded_nodes += [id]
flatdicts.append({
'id': id,
'expanded': node.expanded,
'depth': node.depth,
'children': node.hasChildren(),
'tree-expansion': self.encodeTreeExpansion(expanded_nodes),
'object': node.object
})
flatdicts.append(
{
"id": id,
"expanded": node.expanded,
"depth": node.depth,
"children": node.hasChildren(),
"tree-expansion": self.encodeTreeExpansion(expanded_nodes),
"object": node.object,
}
)
if node.depth > self.maxdepth:
self.maxdepth = node.depth
return flatdicts
11 changes: 8 additions & 3 deletions src/Products/ZopeTree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
isort:skip
"""
#
# ZopeTree
#
Expand All @@ -12,7 +15,9 @@
__allow_access_to_unprotected_subobjects__ = 1
__roles__ = None

# make ZopeTree module accessible from PythonScript and ZPT
from Products.ZopeTree.ZopeTree import ZopeTree, Node # noqa
from Products.ZopeTree.TreeObjectWrapper import TreeObjectWrapper # noqa
allow_module('Products.ZopeTree')

# make ZopeTree module accessible from PythonScript and ZPT
from Products.ZopeTree.ZopeTree import Node, ZopeTree # noqa # isort:skip

allow_module("Products.ZopeTree")
Loading

0 comments on commit 63c68a1

Please sign in to comment.