Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
danbradham committed Mar 2, 2018
1 parent 5d6ad01 commit dcdac8a
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 45 deletions.
22 changes: 21 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
N/A yet...
MIT License

Copyright (c) 2018 Dan Bradham

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
9 changes: 3 additions & 6 deletions fsfs/_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ def _search_tree_dn(root, depth=10, skip_root=False, level=0, visited=None):
raise StopIteration

entries = scandir(root)
only_data = True

while True:
try:
Expand All @@ -221,7 +220,6 @@ def _search_tree_dn(root, depth=10, skip_root=False, level=0, visited=None):
visited.append(api.get_entry(root))
yield visited
else:
only_data = False
yield _search_tree_dn(
root + '/' + entry.name,
depth,
Expand Down Expand Up @@ -270,7 +268,7 @@ def search_tree(root, direction=DOWN, depth=10, skip_root=False):


def select_from_tree(root, selector, sep='/', direction=DOWN,
depth=10, skip_root=False):
depth=10, skip_root=False):
'''This method is used under the hood by the Search class, you shouldn't
need to call it manually.
Expand Down Expand Up @@ -319,9 +317,9 @@ def select_from_tree(root, selector, sep='/', direction=DOWN,
for i, entry in enumerate(branch[b_i:]):
if part in entry.name:
b_i += i + 1
break # Match Found
break # Match Found
else:
break # Match Not Found
break # Match Not Found
else:
# We made it through the for loop without encountering a break
# All parts were found
Expand Down Expand Up @@ -403,4 +401,3 @@ def one_uuid(*args, **kwargs):
return next(matches)
except StopIteration:
return

3 changes: 1 addition & 2 deletions fsfs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def set_data_decoder(data_decoder):
The default policy uses `yaml.safe_load`
'''


get_policy().set_data_decoder(data_decoder)


Expand Down Expand Up @@ -278,7 +277,7 @@ def read_blob(root, key):
'''

entry = get_entry(root)
return entry.read_blob(*keys)
return entry.read_blob(key)


def write_blob(root, key, data):
Expand Down
5 changes: 3 additions & 2 deletions fsfs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ast
import click
import re
from click import group, argument, option
from click import group, argument, option, UsageError
from fstrings import f
import fsfs

Expand Down Expand Up @@ -127,6 +127,7 @@ def one(root, direction, name, tags):
print('No entries found')
sys.exit(1)


@cli.command()
@option('--root', '-r', default=os.getcwd(), help='Directory to tag')
@argument('tags', nargs=-1, required=True)
Expand Down Expand Up @@ -175,7 +176,7 @@ def write(root, data, delkeys):
entry.write(**data)
except Exception as e:
print('Failed to write data: ')
print(dict(pairs))
print(dict(data))
print(e.message)
else:
print(f('Wrote data to {root}'))
Expand Down
5 changes: 1 addition & 4 deletions fsfs/factory.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
__all__ = ['RegistrationError', 'SimpleEntryFactory', 'EntryFactory']
from collections import defaultdict
import os
from collections import defaultdict
from fsfs import api, models, signals



class RegistrationError(Exception): pass


Expand Down Expand Up @@ -113,7 +112,6 @@ def __new__(cls, name, bases, attrs):
self._mtimes = {}
self._cache_proxies = {}


class EntryProxy(object):
'''This proxy is what actually gets returned by the factory. The
proxy looks up the Entry instance stored in the _cache and
Expand Down Expand Up @@ -236,7 +234,6 @@ def _mtime_changed(self, path):
if not os.path.isdir(path):
return False

entry = self._cache[path]
return os.path.getmtime(path) != self._mtimes.get(path, None)

def _update_cache(self, path, proxy=None):
Expand Down
4 changes: 2 additions & 2 deletions fsfs/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ def _time_since_modified(self):
'''Return the total seconds since the specified file was modified'''

return (
datetime.now()
- datetime.fromtimestamp(os.path.getmtime(self.path))
datetime.now() -
datetime.fromtimestamp(os.path.getmtime(self.path))
).total_seconds()

def _acquire_expired_lock(self):
Expand Down
12 changes: 6 additions & 6 deletions fsfs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def relink_uuid(entry):
signals.EntryRelinked.send(entry, old_root, new_root)
else:
exc = EntryNotFoundError(
'Could not locate Entry matching uuid: ' + data.uuid
+ ' Entry: ' + repr(entry)
'Could not locate Entry matching uuid: ' + data.uuid +
' Entry: ' + repr(entry)
)
signals.EntryMissing.send(entry, exc)
raise exc
Expand Down Expand Up @@ -248,8 +248,8 @@ def _read(self):
with self._lock:
mtime = os.path.getmtime(self.file)
needs_update = (
self._data is None
or self._data_mtime < mtime
self._data is None or
self._data_mtime < mtime
)

if needs_update:
Expand Down Expand Up @@ -636,7 +636,7 @@ def move(self, dest):
# Update uuids and send EntryCreated signals
old_path = self.path
new_path = dest
self._set_path(dest) # Update this Entry's path
self._set_path(dest) # Update this Entry's path
signals.EntryMoved.send(self, old_path, new_path)
for child in self.children():
new_child_path = child.path
Expand All @@ -652,7 +652,7 @@ def delete(self, remove_root=False):
'''

self.data.delete()
for child in reversed(self.children):
for child in reversed(self.children()):
child.delete()

if remove_root:
Expand Down
2 changes: 1 addition & 1 deletion fsfs/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _teardown_entry_factory(self, entry_factory):
setup_method()

def set_entry_factory(self, entry_factory):
if self._entry_factory and not entry_factory is self._entry_factory:
if self._entry_factory and entry_factory is not self._entry_factory:
self._teardown_entry_factory(self._entry_factory)

self._entry_factory = entry_factory
Expand Down
12 changes: 8 additions & 4 deletions fsfs/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

class Channel(object):
'''Manages and sends signals by string identifier. Supports fuzzy signal
subscriptions using fnmatch with \*. So you could connect to "new.\*" to
subscriptions using fnmatch with *. So you could connect to "new.*" to
subscribe to all signals that start with "new.".
Examples:
Expand Down Expand Up @@ -328,8 +328,12 @@ def __init__(self, identifier, channel=None):

def __repr__(self):
return (
self.__class__.__name__ + '(channel={channel}, identifier={identifier})'
).format(channel=self.channel, identifier=repr(self.identifier))
'{}(channel={}, identifier={!r})'
).format(
self.__class__.__name__,
self.channel,
self.identifier
)

def __call__(self, *args, **kwargs):
channel = kwargs.pop('channel', self.channel)
Expand Down Expand Up @@ -359,7 +363,7 @@ def send(self, *args, **kwargs):
channel = kwargs.pop('channel', self.channel)
return channel.send(self.identifier, *args, **kwargs)

def clear(self):
def clear(self, **kwargs):
channel = kwargs.pop('channel', self.channel)
return channel.clear(self.identifier)

Expand Down
3 changes: 2 additions & 1 deletion fsfs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def copy_file(src, dest, buffer_size=DEFAULT_BUFFER):
'''Copy operations can be optimized by setting the buffer size for read
operations and that's just what copy_file does. copy_file has a default
buffer size of 256 KB, which increases the speed of file copying in most
cases. For smaller files the buffer size is reduced to the file size or a minimum of MINIMUM_BUFFER (1 KB).
cases. For smaller files the buffer size is reduced to the file size or a
minimum of MINIMUM_BUFFER (1 KB).
See also:
http://blogs.blumetech.com/blumetechs-tech-blog/2011/05/faster-python-file-copy.html
Expand Down
14 changes: 5 additions & 9 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
from invoke import task, Failure
from invoke import task, Failure, run
import os
from os.path import join, dirname
import shutil
import fsfs


def modify_about(**values):
Expand Down Expand Up @@ -36,9 +38,6 @@ def get_tags():
def increment(major=False, minor=False, patch=True):
'''Increment package version'''

print('Incrementing package version by {}.{}.{}'.format(
int(major), int(minor), int(version)
))
import fsfs
cmajor, cminor, cpatch = fsfs.__version__.split('.')

Expand All @@ -52,6 +51,7 @@ def increment(major=False, minor=False, patch=True):
patch = str(int(cpatch) + 1)
version = cmajor + '.' + cminor + '.' + patch

print('Incrementing package version by {}'.format(version))
modify_about(__version__=version)
print('Changed version to:', version)

Expand All @@ -60,10 +60,6 @@ def increment(major=False, minor=False, patch=True):
def decrement(major=False, minor=False, patch=True):
'''Decrement package version...'''

print('Decrementing package version by {}.{}.{}'.format(
int(major), int(minor), int(version)
))
import fsfs
cmajor, cminor, cpatch = fsfs.__version__.split('.')

if major:
Expand All @@ -76,6 +72,7 @@ def decrement(major=False, minor=False, patch=True):
patch = str(int(cpatch) - 1)
version = cmajor + '.' + cminor + '.' + patch

print('Decrementing package version by {}'.format(version))
modify_about(__version__=version)
print('Changed version to:', version)

Expand Down Expand Up @@ -167,4 +164,3 @@ def publish(ctx, tag=None, remote=None, branch=None, where=None):
tag(ctx, tag)
push(ctx, remote, branch)
upload(ctx, where)

16 changes: 9 additions & 7 deletions test_fsfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def fake_name(used=[]):

while True:
name = ''.join(
choice(string.ascii_uppercase + string.digits)
for _ in range(8)
)
choice(string.ascii_uppercase + string.digits)
for _ in range(8)
)

if name in used:
continue
Expand Down Expand Up @@ -141,10 +141,12 @@ def create(self, name=None, sequences=8, shots=20, assets=20):
)
fsfs.tag(shot_path, 'shot')

perms = [zip(asset, self.variants)
for asset in itertools.permutations(
self.assets, len(self.variants)
)]
perms = [
zip(asset, self.variants)
for asset in itertools.permutations(
self.assets, len(self.variants)
)
]
variants = [a + '_' + b for (a, b) in itertools.chain(*perms)]
assets = max([len(assets), len(variants)])
asset_names = sample(variants, assets)
Expand Down

0 comments on commit dcdac8a

Please sign in to comment.