From 1210c3fbd35c0a94725fded04a92f3e06ec27f0b Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 6 Jan 2017 18:10:50 +0100 Subject: pyflakes + pep8 cleanup --- check | 5 +++++ lesana/__init__.py | 4 ++++ lesana/collection.py | 4 +++- lesana/command.py | 29 ++++++++++++----------------- setup.py | 6 +++--- tests/test_collection.py | 3 +-- 6 files changed, 28 insertions(+), 23 deletions(-) create mode 100755 check diff --git a/check b/check new file mode 100755 index 0000000..501b336 --- /dev/null +++ b/check @@ -0,0 +1,5 @@ +#!/bin/sh + +nosetests3 --with-coverage --cover-erase --cover-package=lesana +pyflakes3 . +pep8 . diff --git a/lesana/__init__.py b/lesana/__init__.py index 64fbd80..008f5ac 100644 --- a/lesana/__init__.py +++ b/lesana/__init__.py @@ -1 +1,5 @@ from .collection import Collection, Entry + +# prevent spurious warnings from pyflakes +assert Collection +assert Entry diff --git a/lesana/collection.py b/lesana/collection.py index b648230..81b7a66 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -265,7 +265,9 @@ class Collection(object): if git_available: repo = git.Repo.init(c_dir, bare=False) else: - logging.warning("python3-git not available, could not initalise the git repository.") + logging.warning( + "python3-git not available, could not initalise " + + "the git repository.") repo = None # Add .lesana directory to .gitignore and add it to the # staging diff --git a/lesana/command.py b/lesana/command.py index 0f8ca9a..9101e8e 100644 --- a/lesana/command.py +++ b/lesana/command.py @@ -2,12 +2,6 @@ import logging import os import subprocess -try: - import git - git_available = True -except ImportError: - git_available = False - import guacamole from . import Collection, Entry @@ -37,7 +31,9 @@ def edit_file_in_external_editor(filepath): except FileNotFoundError as e: if 'sensible-editor' in e.strerror: logging.debug( - "Could not open file {} with editor: sensible-editor".format(filepath) + "Could not open file {} with editor: sensible-editor".format( + filepath + ) ) else: logging.warning("Could not open file {}".format(filepath)) @@ -61,14 +57,13 @@ def edit_file_in_external_editor(filepath): return True - - class New(guacamole.Command): arguments = [ (['--collection', '-c'], dict( help='The collection to work on (default .)' )), ] + def register_arguments(self, parser): for arg in self.arguments: parser.add_argument(*arg[0], **arg[1]) @@ -95,11 +90,11 @@ class Edit(guacamole.Command): help='uid of an entry to edit', )), ] + def register_arguments(self, parser): for arg in self.arguments: parser.add_argument(*arg[0], **arg[1]) - def invoked(self, ctx): collection = Collection(ctx.args.collection) entry = collection.entry_from_uid(ctx.args.uid) @@ -123,11 +118,11 @@ class Index(guacamole.Command): nargs='*' )), ] + def register_arguments(self, parser): for arg in self.arguments: parser.add_argument(*arg[0], **arg[1]) - def invoked(self, ctx): collection = Collection(ctx.args.collection) if ctx.args.files: @@ -155,11 +150,11 @@ class Search(guacamole.Command): nargs='+' )), ] + def register_arguments(self, parser): for arg in self.arguments: parser.add_argument(*arg[0], **arg[1]) - def invoked(self, ctx): # TODO: implement "searching" for everything if ctx.args.offset: @@ -175,11 +170,11 @@ class Search(guacamole.Command): offset = ctx.args.offset or 0 pagesize = ctx.args.pagesize or 12 collection = Collection(ctx.args.collection) - #TODO: pass the entries to a proper template + # TODO: pass the entries to a proper template for entry in collection.search( - ' '.join(ctx.args.query), - offset, - pagesize): + ' '.join(ctx.args.query), + offset, + pagesize): print(entry) @@ -195,11 +190,11 @@ class Init(guacamole.Command): dest='git' )), ] + def register_arguments(self, parser): for arg in self.arguments: parser.add_argument(*arg[0], **arg[1]) - def invoked(self, ctx): Collection.init( ctx.args.collection, diff --git a/setup.py b/setup.py index 4748954..30121f7 100644 --- a/setup.py +++ b/setup.py @@ -5,9 +5,9 @@ setup( packages=find_packages(), scripts=['scripts/lesana'], - install_requires = [ + install_requires=[ 'guacamole', - #'xapian >= 1.4', + # 'xapian >= 1.4', 'ruamel.yaml', 'jinja2', ], @@ -15,7 +15,7 @@ setup( package_data={ '': ['*.yaml'] }, - test_suite = 'tests', + test_suite='tests', # Metadata author="Elena ``of Valhalla'' Grandi", diff --git a/tests/test_collection.py b/tests/test_collection.py index 8e8e5f1..d8190ca 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -47,7 +47,7 @@ class testCollectionLoading(unittest.TestCase): def test_no_index_for_one_entry(self): # This loads a collection where some of the entries have no # "index" field - with self.assertLogs(level=logging.WARNING) as cm: + with self.assertLogs(level=logging.WARNING): self.collection = lesana.Collection('tests/data/wrong') self.collection.update_cache() self.assertIsNotNone(self.collection.settings) @@ -85,7 +85,6 @@ class testEntries(unittest.TestCase): def tearDown(self): shutil.rmtree(os.path.join(self.collection.basedir, '.lesana')) - def test_simple(self): fname = '085682ed-6792-499d-a3ab-9aebd683c011.yaml' with open(os.path.join(self.basepath, fname)) as fp: -- cgit v1.2.3