diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index fc7a708..5ffa075 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -56,4 +56,4 @@ jobs: ./scripts/flake8.sh - name: Test with pytest run: | - pytest \ No newline at end of file + pytest diff --git a/examples/family_tree.py b/examples/family_tree.py index d8b956d..fa2293d 100644 --- a/examples/family_tree.py +++ b/examples/family_tree.py @@ -5,7 +5,7 @@ # __author__ = "chenxm" -from treelib import Tree, Node +from treelib import Tree def create_family_tree(): diff --git a/examples/folder_tree.py b/examples/folder_tree.py index 0e942e8..695d6ef 100644 --- a/examples/folder_tree.py +++ b/examples/folder_tree.py @@ -105,7 +105,7 @@ def get_parentid(current_depth, root, dir): search_string = os.path.join(root, dir) pos2 = search_string.rfind("/") pos1 = search_string.rfind("/", 0, pos2) - parent_dir = search_string[pos1 + 1 : pos2] + parent_dir = search_string[pos1 + 1 : pos2] # noqa: E203 parentid = ( str(current_depth - 1) + "_" @@ -130,10 +130,8 @@ def crawler(): global FILECOUNT for root, dirs, files in os.walk(rootPath): - # +++ DIRECTORIES +++ for dir in dirs: - # calculating current depth current_depth = os.path.join(root, dir).count("/") - start_depth @@ -155,7 +153,6 @@ def crawler(): # +++ FILES +++ for filename in fnmatch.filter(files, pattern): - if dir in folder_blacklist: continue diff --git a/examples/recursive_dirtree_generator.py b/examples/recursive_dirtree_generator.py index 776c193..986cd1a 100644 --- a/examples/recursive_dirtree_generator.py +++ b/examples/recursive_dirtree_generator.py @@ -11,12 +11,21 @@ import random import hashlib from string import digits, letters +import sys + MAX_FILES_PER_DIR = 10 +def range2(stop): + if sys.version_info[0] < 3: + return xrange(stop) # noqa: F821 + else: + return range(stop) + + def get_random_string(length): - return "".join(random.choice(digits + letters) for _ in range(length)) + return "".join(random.choice(digits + letters) for _ in range2(length)) def build_recursive_tree(tree, base, depth, width): @@ -32,7 +41,7 @@ def build_recursive_tree(tree, base, depth, width): """ if depth >= 0: depth -= 1 - for i in xrange(width): + for i in range2(width): directory = Directory() tree.create_node( "{0}".format(directory.name), @@ -52,7 +61,7 @@ class Directory(object): def __init__(self): self._name = get_random_string(64) self._files = [ - File() for _ in xrange(MAX_FILES_PER_DIR) + File() for _ in range2(MAX_FILES_PER_DIR) ] # Each directory contains 1000 files @property diff --git a/scripts/flake8.sh b/scripts/flake8.sh index 9e05f3e..b93226d 100755 --- a/scripts/flake8.sh +++ b/scripts/flake8.sh @@ -1,3 +1,3 @@ #!/bin/bash flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics -flake8 . --count --exit-zero --max-line-length=127 --statistics +flake8 . --count --max-line-length=127 --exclude docs/source/conf.py --statistics diff --git a/setup.py b/setup.py index 559a1a7..910e467 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -__version__ = "1.6.3" +__version__ = "1.6.4" setup( diff --git a/tests/test_plugins.py b/tests/test_plugins.py index 05fde9d..0f04fbf 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -7,7 +7,7 @@ import unittest from treelib import Tree -from treelib.plugins import * +from treelib.plugins import export_to_dot class DotExportCase(unittest.TestCase): diff --git a/tests/test_tree.py b/tests/test_tree.py index 308b6c5..b0cd934 100644 --- a/tests/test_tree.py +++ b/tests/test_tree.py @@ -6,10 +6,6 @@ import os -try: - from StringIO import StringIO as BytesIO -except ImportError: - from io import BytesIO import unittest from treelib import Tree, Node from treelib.tree import NodeIDAbsentError, LoopError @@ -304,7 +300,6 @@ def test_paste_tree(self): ) def test_merge(self): - # merge on empty initial tree t1 = Tree(identifier="t1") t2 = self.get_t2() @@ -381,7 +376,6 @@ def test_merge(self): ) def test_paste(self): - # paste under root t1 = self.get_t1() t2 = self.get_t2() @@ -545,7 +539,7 @@ def test_print_backend(self): def test_show(self): if sys.version_info[0] < 3: - reload(sys) + reload(sys) # noqa: F821 sys.setdefaultencoding("utf-8") sys.stdout = open(os.devnull, "w") # stops from printing to console diff --git a/treelib/__init__.py b/treelib/__init__.py index d7e6ec7..4902412 100644 --- a/treelib/__init__.py +++ b/treelib/__init__.py @@ -35,5 +35,5 @@ >>> from __future__ import unicode_literals """ -from .tree import Tree -from .node import Node +from .tree import Tree # noqa: F401 +from .node import Node # noqa: F401 diff --git a/treelib/tree.py b/treelib/tree.py index 285b8c0..f3101ca 100644 --- a/treelib/tree.py +++ b/treelib/tree.py @@ -881,7 +881,9 @@ def show( former two use the same backend to generate a string of tree structure in a text graph. - * Version >= 1.2.7a*: you can also specify the ``line_type`` parameter, such as 'ascii' (default), 'ascii-ex', 'ascii-exr', 'ascii-em', 'ascii-emv', 'ascii-emh') to the change graphical form. + * Version >= 1.2.7a*: you can also specify the ``line_type`` parameter, + such as 'ascii' (default), 'ascii-ex', 'ascii-exr', 'ascii-em', 'ascii-emv', + 'ascii-emh') to the change graphical form. :param nid: the reference node to start expanding. :param level: the node level in the tree (root as level 0). @@ -959,7 +961,7 @@ def size(self, level=None): if self.level(node.identifier) == level ] ) - except: + except Exception: raise TypeError( "level should be an integer instead of '%s'" % type(level) ) @@ -1063,21 +1065,33 @@ def to_json(self, with_data=False, sort=True, reverse=False): """To format the tree in JSON format.""" return json.dumps(self.to_dict(with_data=with_data, sort=sort, reverse=reverse)) - def to_graphviz(self, filename=None, shape="circle", graph="digraph", - filter=None, key=None, reverse=False, sorting=True): + def to_graphviz( + self, + filename=None, + shape="circle", + graph="digraph", + filter=None, + key=None, + reverse=False, + sorting=True, + ): """Exports the tree in the dot format of the graphviz software""" nodes, connections = [], [] if self.nodes: - - for n in self.expand_tree(mode=self.WIDTH, filter=filter, key=key, - reverse=reverse, sorting=sorting): + for n in self.expand_tree( + mode=self.WIDTH, + filter=filter, + key=key, + reverse=reverse, + sorting=sorting, + ): nid = self[n].identifier state = '"{0}" [label="{1}", shape={2}]'.format(nid, self[n].tag, shape) nodes.append(state) for c in self.children(nid): cid = c.identifier - edge = '->' if graph == 'digraph' else '--' + edge = "->" if graph == "digraph" else "--" connections.append(('"{0}" ' + edge + ' "{1}"').format(nid, cid)) # write nodes and connections to dot format