From f5d11b750ecc982541d1f936488248f0b42d75d3 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:15:50 +0100 Subject: pep8 linting (whitespaces) W191 indentation contains tabs E221 multiple spaces before operator E222 multiple spaces after operator E225 missing whitespace around operator E271 multiple spaces after keyword W292 no newline at end of file W293 blank line contains whitespace W391 blank line at end of file --- git/objects/tree.py | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) (limited to 'git/objects/tree.py') diff --git a/git/objects/tree.py b/git/objects/tree.py index d1e827f5..92b0feca 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -23,14 +23,14 @@ __all__ = ("TreeModifier", "Tree") class TreeModifier(object): """A utility class providing methods to alter the underlying cache in a list-like fashion. - + Once all adjustments are complete, the _cache, which really is a refernce to the cache of a tree, will be sorted. Assuring it will be in a serializable state""" __slots__ = '_cache' - + def __init__(self, cache): self._cache = cache - + def _index_by_name(self, name): """:return: index of an item with name, or -1 if not found""" for i, t in enumerate(self._cache): @@ -39,7 +39,7 @@ class TreeModifier(object): # END found item # END for each item in cache return -1 - + #{ Interface def set_done(self): """Call this method once you are done modifying the tree information. @@ -49,14 +49,14 @@ class TreeModifier(object): self._cache.sort(key=lambda t: t[2]) # sort by name return self #} END interface - + #{ Mutators def add(self, sha, mode, name, force=False): """Add the given item to the tree. If an item with the given name already exists, nothing will be done, but a ValueError will be raised if the sha and mode of the existing item do not match the one you add, unless force is True - + :param sha: The 20 or 40 byte sha of the item to add :param mode: int representing the stat compatible mode of the item :param force: If True, an item with your name and information will overwrite @@ -66,7 +66,7 @@ class TreeModifier(object): raise ValueError("Name must not contain '/' characters") if (mode >> 12) not in Tree._map_id_to_type: raise ValueError("Invalid object type according to mode %o" % mode) - + sha = to_bin_sha(sha) index = self._index_by_name(name) item = (sha, mode, name) @@ -83,52 +83,52 @@ class TreeModifier(object): # END handle force # END handle name exists return self - + def add_unchecked(self, binsha, mode, name): """Add the given item to the tree, its correctness is assumed, which puts the caller into responsibility to assure the input is correct. For more information on the parameters, see ``add`` :param binsha: 20 byte binary sha""" self._cache.append((binsha, mode, name)) - + def __delitem__(self, name): """Deletes an item with the given name if it exists""" index = self._index_by_name(name) if index > -1: del(self._cache[index]) - + #} END mutators class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): """Tree objects represent an ordered list of Blobs and other Trees. - + ``Tree as a list``:: - + Access a specific blob using the tree['filename'] notation. - + You may as well access by index blob = tree[0] """ - + type = "tree" __slots__ = "_cache" - + # actual integer ids for comparison commit_id = 016 # equals stat.S_IFDIR | stat.S_IFLNK - a directory link blob_id = 010 symlink_id = 012 tree_id = 004 - + _map_id_to_type = { commit_id : Submodule, blob_id : Blob, symlink_id : Blob # tree id added once Tree is defined } - - + + def __init__(self, repo, binsha, mode=tree_id<<12, path=None): super(Tree, self).__init__(repo, binsha, mode, path) @@ -161,7 +161,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): def __div__(self, file): """Find the named object in this tree's contents :return: ``git.Blob`` or ``git.Tree`` or ``git.Submodule`` - + :raise KeyError: if given file or tree does not exist in tree""" msg = "Blob or Tree named %r not found" if '/' in file: @@ -195,7 +195,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): def trees(self): """:return: list(Tree, ...) list of trees directly below this tree""" return [ i for i in self if i.type == "tree" ] - + @property def blobs(self): """:return: list(Blob, ...) list of blobs directly below this tree""" @@ -220,26 +220,26 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): # List protocol def __getslice__(self, i, j): return list(self._iter_convert_to_object(self._cache[i:j])) - + def __iter__(self): return self._iter_convert_to_object(self._cache) - + def __len__(self): return len(self._cache) - + def __getitem__(self, item): if isinstance(item, int): info = self._cache[item] return self._map_id_to_type[info[1] >> 12](self.repo, info[0], info[1], join_path(self.path, info[2])) - + if isinstance(item, basestring): # compatability return self.__div__(item) # END index is basestring - + raise TypeError( "Invalid index type: %r" % item ) - - + + def __contains__(self, item): if isinstance(item, IndexObject): for info in self._cache: @@ -249,7 +249,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): # END for each entry # END handle item is index object # compatability - + # treat item as repo-relative path path = self.path for info in self._cache: @@ -257,10 +257,10 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): return True # END for each item return False - + def __reversed__(self): return reversed(self._iter_convert_to_object(self._cache)) - + def _serialize(self, stream): """Serialize this tree into the stream. Please note that we will assume our tree data to be in a sorted state. If this is not the case, serialization @@ -268,12 +268,12 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): by algorithms""" tree_to_stream(self._cache, stream.write) return self - + def _deserialize(self, stream): self._cache = tree_entries_from_data(stream.read()) return self - - + + # END tree # finalize map definition -- cgit v1.2.1 From be34ec23c48d6d5d8fd2ef4491981f6fb4bab8e6 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:51:04 +0100 Subject: pep8 linting (blank lines expectations) E301 expected 1 blank line, found 0 E302 expected 2 blank lines, found 1 E303 too many blank lines (n) --- git/objects/tree.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'git/objects/tree.py') diff --git a/git/objects/tree.py b/git/objects/tree.py index 92b0feca..4984823e 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -21,7 +21,9 @@ from gitdb.util import ( __all__ = ("TreeModifier", "Tree") + class TreeModifier(object): + """A utility class providing methods to alter the underlying cache in a list-like fashion. Once all adjustments are complete, the _cache, which really is a refernce to @@ -101,6 +103,7 @@ class TreeModifier(object): class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): + """Tree objects represent an ordered list of Blobs and other Trees. ``Tree as a list``:: @@ -128,7 +131,6 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): # tree id added once Tree is defined } - def __init__(self, repo, binsha, mode=tree_id<<12, path=None): super(Tree, self).__init__(repo, binsha, mode, path) @@ -190,7 +192,6 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): raise KeyError( msg % file ) # END handle long paths - @property def trees(self): """:return: list(Tree, ...) list of trees directly below this tree""" @@ -239,7 +240,6 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): raise TypeError( "Invalid index type: %r" % item ) - def __contains__(self, item): if isinstance(item, IndexObject): for info in self._cache: -- cgit v1.2.1 From 614907b7445e2ed8584c1c37df7e466e3b56170f Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 20:56:53 +0100 Subject: pep8 linting (whitespace before/after) E201 whitespace after '(' E202 whitespace before ')' E203 whitespace before ':' E225 missing whitespace around operator E226 missing whitespace around arithmetic operator E227 missing whitespace around bitwise or shift operator E228 missing whitespace around modulo operator E231 missing whitespace after ',' E241 multiple spaces after ',' E251 unexpected spaces around keyword / parameter equals --- git/objects/tree.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'git/objects/tree.py') diff --git a/git/objects/tree.py b/git/objects/tree.py index 4984823e..e4e49d1a 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -125,13 +125,13 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): tree_id = 004 _map_id_to_type = { - commit_id : Submodule, - blob_id : Blob, - symlink_id : Blob + commit_id: Submodule, + blob_id: Blob, + symlink_id: Blob # tree id added once Tree is defined } - def __init__(self, repo, binsha, mode=tree_id<<12, path=None): + def __init__(self, repo, binsha, mode=tree_id << 12, path=None): super(Tree, self).__init__(repo, binsha, mode, path) @classmethod @@ -170,13 +170,13 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): tree = self item = self tokens = file.split('/') - for i,token in enumerate(tokens): + for i, token in enumerate(tokens): item = tree[token] if item.type == 'tree': tree = item else: # safety assertion - blobs are at the end of the path - if i != len(tokens)-1: + if i != len(tokens) - 1: raise KeyError(msg % file) return item # END handle item type @@ -189,18 +189,18 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): if info[2] == file: # [2] == name return self._map_id_to_type[info[1] >> 12](self.repo, info[0], info[1], join_path(self.path, info[2])) # END for each obj - raise KeyError( msg % file ) + raise KeyError(msg % file) # END handle long paths @property def trees(self): """:return: list(Tree, ...) list of trees directly below this tree""" - return [ i for i in self if i.type == "tree" ] + return [i for i in self if i.type == "tree"] @property def blobs(self): """:return: list(Blob, ...) list of blobs directly below this tree""" - return [ i for i in self if i.type == "blob" ] + return [i for i in self if i.type == "blob"] @property def cache(self): @@ -211,9 +211,9 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): See the ``TreeModifier`` for more information on how to alter the cache""" return TreeModifier(self._cache) - def traverse( self, predicate = lambda i,d: True, - prune = lambda i,d: False, depth = -1, branch_first=True, - visit_once = False, ignore_self=1 ): + def traverse(self, predicate=lambda i, d: True, + prune=lambda i, d: False, depth=-1, branch_first=True, + visit_once=False, ignore_self=1): """For documentation, see util.Traversable.traverse Trees are set to visit_once = False to gain more performance in the traversal""" return super(Tree, self).traverse(predicate, prune, depth, branch_first, visit_once, ignore_self) @@ -238,7 +238,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): return self.__div__(item) # END index is basestring - raise TypeError( "Invalid index type: %r" % item ) + raise TypeError("Invalid index type: %r" % item) def __contains__(self, item): if isinstance(item, IndexObject): -- cgit v1.2.1 From c8e70749887370a99adeda972cc3503397b5f9a7 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sun, 16 Nov 2014 21:09:47 +0100 Subject: pep8 linting (trailing whitespace) W291 trailing whitespace --- git/objects/tree.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'git/objects/tree.py') diff --git a/git/objects/tree.py b/git/objects/tree.py index e4e49d1a..cc3699f5 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -11,12 +11,12 @@ from submodule.base import Submodule import git.diff as diff from fun import ( - tree_entries_from_data, + tree_entries_from_data, tree_to_stream ) from gitdb.util import ( - to_bin_sha, + to_bin_sha, ) __all__ = ("TreeModifier", "Tree") @@ -26,7 +26,7 @@ class TreeModifier(object): """A utility class providing methods to alter the underlying cache in a list-like fashion. - Once all adjustments are complete, the _cache, which really is a refernce to + Once all adjustments are complete, the _cache, which really is a refernce to the cache of a tree, will be sorted. Assuring it will be in a serializable state""" __slots__ = '_cache' @@ -42,10 +42,10 @@ class TreeModifier(object): # END for each item in cache return -1 - #{ Interface + #{ Interface def set_done(self): """Call this method once you are done modifying the tree information. - It may be called several times, but be aware that each call will cause + It may be called several times, but be aware that each call will cause a sort operation :return self:""" self._cache.sort(key=lambda t: t[2]) # sort by name @@ -55,8 +55,8 @@ class TreeModifier(object): #{ Mutators def add(self, sha, mode, name, force=False): """Add the given item to the tree. If an item with the given name already - exists, nothing will be done, but a ValueError will be raised if the - sha and mode of the existing item do not match the one you add, unless + exists, nothing will be done, but a ValueError will be raised if the + sha and mode of the existing item do not match the one you add, unless force is True :param sha: The 20 or 40 byte sha of the item to add @@ -87,8 +87,8 @@ class TreeModifier(object): return self def add_unchecked(self, binsha, mode, name): - """Add the given item to the tree, its correctness is assumed, which - puts the caller into responsibility to assure the input is correct. + """Add the given item to the tree, its correctness is assumed, which + puts the caller into responsibility to assure the input is correct. For more information on the parameters, see ``add`` :param binsha: 20 byte binary sha""" self._cache.append((binsha, mode, name)) @@ -108,7 +108,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): ``Tree as a list``:: - Access a specific blob using the + Access a specific blob using the tree['filename'] notation. You may as well access by index @@ -118,15 +118,15 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): type = "tree" __slots__ = "_cache" - # actual integer ids for comparison + # actual integer ids for comparison commit_id = 016 # equals stat.S_IFDIR | stat.S_IFLNK - a directory link blob_id = 010 symlink_id = 012 tree_id = 004 _map_id_to_type = { - commit_id: Submodule, - blob_id: Blob, + commit_id: Submodule, + blob_id: Blob, symlink_id: Blob # tree id added once Tree is defined } @@ -147,7 +147,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): self._cache = tree_entries_from_data(ostream.read()) else: super(Tree, self)._set_cache_(attr) - # END handle attribute + # END handle attribute def _iter_convert_to_object(self, iterable): """Iterable yields tuples of (binsha, mode, name), which will be converted @@ -158,7 +158,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): yield self._map_id_to_type[mode >> 12](self.repo, binsha, mode, path) except KeyError: raise TypeError("Unknown mode %o found in tree data for path '%s'" % (mode, path)) - # END for each item + # END for each item def __div__(self, file): """Find the named object in this tree's contents @@ -236,7 +236,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): if isinstance(item, basestring): # compatability return self.__div__(item) - # END index is basestring + # END index is basestring raise TypeError("Invalid index type: %r" % item) @@ -262,7 +262,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable): return reversed(self._iter_convert_to_object(self._cache)) def _serialize(self, stream): - """Serialize this tree into the stream. Please note that we will assume + """Serialize this tree into the stream. Please note that we will assume our tree data to be in a sorted state. If this is not the case, serialization will not generate a correct tree representation as these are assumed to be sorted by algorithms""" -- cgit v1.2.1