From a8057ed1db433767b51f05d1536f0d21c7c1a10e Mon Sep 17 00:00:00 2001 From: William Ting Date: Sat, 28 Dec 2013 11:34:13 -0600 Subject: [PATCH] linter cleanup --- Makefile | 4 ++-- bin/autojump | 34 ++++++++++++++++++---------------- bin/data.py | 16 ++++++++++++---- setup.cfg | 3 +-- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 9a06039..24b201d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION = $(shell grep -oE "[0-9]+\.[0-9]+\.[0-9]+" bin/autojump) TAGNAME = release-v$(VERSION) -.PHONY: docs install uninstall tar +.PHONY: docs install uninstall lint tar install: install.sh @@ -14,7 +14,7 @@ docs: pandoc -s -w markdown docs/header.md docs/install.md docs/development.md docs/body.md -o README.md lint: - flake8 ./ + @flake8 ./ --config=setup.cfg release: docs # Check for tag existence diff --git a/bin/autojump b/bin/autojump index 0a509f5..c1929fa 100755 --- a/bin/autojump +++ b/bin/autojump @@ -2,21 +2,21 @@ # -*- coding: utf-8 -*- """ Copyright © 2008-2012 Joel Schaerer - Copyright © 2012-2013 William Ting + Copyright © 2012-2014 William Ting - * This program is free software; you can redistribute it and/or modify + * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. - * This program is distributed in the hope that it will be useful, + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ from __future__ import print_function @@ -93,9 +93,12 @@ def set_defaults(): def parse_arguments(): - """Evaluate arguments and run appropriate logic, returning an error code.""" + """ + Evaluate arguments and run appropriate logic, returning an error code. + """ parser = ArgumentParser( - description='Automatically jump to directory passed as an argument.', + description='Automatically jump to directory passed as an \ + argument.', epilog="Please see autojump(1) man pages for full documentation.") parser.add_argument( 'directory', metavar='DIRECTORY', nargs='*', default='', @@ -131,8 +134,9 @@ def add_path(data, path, increment=10): """ Add a new path or increment an existing one. - os.path.realpath() is not used because users prefer to have short, symlinked - paths with duplicate entries in the database than a single canonical path. + os.path.realpath() is not used because users prefer to have short, + symlinked paths with duplicate entries in the database than a single + canonical path. """ path = decode(path).rstrip(os.sep) if path == os.path.expanduser('~'): @@ -182,7 +186,6 @@ def find_matches(entries, needles): exists, chain( match_consecutive(needles, data, ignore_case), - match_quicksilver(needles, data, ignore_case), match_fuzzy(needles, data, ignore_case), match_anywhere(needles, data, ignore_case), # default return value so calling shell functions have an @@ -289,14 +292,11 @@ def match_fuzzy(needles, haystack, ignore_case=False): match_percent = lambda entry: SequenceMatcher( a=needle, b=end_dir(entry.path)).ratio() - meets_threshold = lambda entry: match_percent(entry) >= FUZZY_MATCH_THRESHOLD + meets_threshold = lambda entry: match_percent(entry) >= \ + FUZZY_MATCH_THRESHOLD return ifilter(meets_threshold, haystack) -def match_quicksilver(needles, haystack, ignore_case=False): - return [] - - def purge_missing_paths(entries): """Remove non-existent paths from a list of entries.""" exists = lambda entry: os.path.exists(entry.path) @@ -348,6 +348,8 @@ def main(args): print_stats(load(config), config['data_path']) else: if not args.directory: + # default return value so calling shell functions have an + # argument to `cd` to print(encode_local('.')) return 0 diff --git a/bin/data.py b/bin/data.py index c0e519a..833782a 100644 --- a/bin/data.py +++ b/bin/data.py @@ -72,7 +72,9 @@ def load(config): 'r', encoding='utf-8', errors='replace') as f: return dict( - imap(tupleize, ifilter(correct_length, imap(parse, f)))) + imap( + tupleize, + ifilter(correct_length, imap(parse, f)))) except (IOError, EOFError): return load_backup(config) @@ -116,12 +118,17 @@ def save(config, data): # atomically save by writing to temporary file and moving to destination try: # write to temp file - with open(config['tmp_path'], 'w', encoding='utf-8', errors='replace') as f: + with open( + config['tmp_path'], + 'w', + encoding='utf-8', + errors='replace') as f: for path, weight in data.items(): if is_python3(): f.write(("%s\t%s\n" % (weight, path))) else: - f.write((unicode("%s\t%s\n" % (weight, path)).encode('utf-8'))) + f.write(unicode( + "%s\t%s\n" % (weight, path)).encode('utf-8')) f.flush() os.fsync(f) @@ -131,7 +138,8 @@ def save(config, data): # create backup file if it doesn't exist or is older than BACKUP_THRESHOLD if not os.path.exists(config['backup_path']) or \ - (time() - os.path.getmtime(config['backup_path']) > BACKUP_THRESHOLD): + (time() - os.path.getmtime(config['backup_path']) + > BACKUP_THRESHOLD): move_file(config['data_path'], config['backup_path']) # move temp_file -> autojump.txt diff --git a/setup.cfg b/setup.cfg index 597c6d5..2f7b36a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,6 +2,5 @@ filename = *.py,autojump exclude = argparse.py,autojump_ipython.py ignore = E126 -max-line-length = 85 +max-line-length = 79 max-complexity = 10 -hang-closing = 1