From d3dd3f34e6ec1d027e050cf52e51ccbc7737fb5c Mon Sep 17 00:00:00 2001 From: TheArtist Date: Fri, 11 Sep 2015 17:41:23 +0300 Subject: [PATCH 01/19] Fixed handling of directories with spaces on Windows --- bin/autojump.bat | 2 +- bin/j.bat | 2 +- bin/jc.bat | 4 ++-- bin/jco.bat | 4 ++-- bin/jo.bat | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/autojump.bat b/bin/autojump.bat index a9e359a..a8cfb8f 100644 --- a/bin/autojump.bat +++ b/bin/autojump.bat @@ -1,2 +1,2 @@ @echo off -python %~dp0\autojump %* \ No newline at end of file +python "%~dp0\autojump" %* diff --git a/bin/j.bat b/bin/j.bat index 77925c9..dbbaec8 100644 --- a/bin/j.bat +++ b/bin/j.bat @@ -17,5 +17,5 @@ if ERRORLEVEL 1 ( echo try `autojump --help` for more information ) ) else ( - python %~dp0\autojump %* + python "%~dp0\autojump" %* ) \ No newline at end of file diff --git a/bin/jc.bat b/bin/jc.bat index f0cc8db..ace52f6 100644 --- a/bin/jc.bat +++ b/bin/jc.bat @@ -2,7 +2,7 @@ echo %*|>nul findstr /rx \-.* if ERRORLEVEL 1 ( - %~dp0\j.bat %cd% %* + "%~dp0\j.bat" "%cd%" %* ) else ( - python %~dp0\autojump %* + python "%~dp0\autojump" %* ) \ No newline at end of file diff --git a/bin/jco.bat b/bin/jco.bat index efd42ff..937c839 100644 --- a/bin/jco.bat +++ b/bin/jco.bat @@ -2,7 +2,7 @@ echo %*|>nul findstr /rx \-.* if ERRORLEVEL 1 ( - %~dp0\jc.bat %cd% %* + "%~dp0\jc.bat" "%cd%" %* ) else ( - python %~dp0\autojump %* + python "%~dp0\autojump" %* ) \ No newline at end of file diff --git a/bin/jo.bat b/bin/jo.bat index 1bb2485..27f5b7b 100644 --- a/bin/jo.bat +++ b/bin/jo.bat @@ -11,5 +11,5 @@ if ERRORLEVEL 1 ( echo try `autojump --help` for more information ) ) else ( - python %~dp0\autojump %* + python "%~dp0\autojump" %* ) \ No newline at end of file From b71612eea4649fbdbce33002fb4096de2dbf0c7d Mon Sep 17 00:00:00 2001 From: TheArtist Date: Fri, 11 Sep 2015 19:36:36 +0300 Subject: [PATCH 02/19] More handling for directory with spaces on Windows --- bin/j.bat | 4 ++-- bin/jo.bat | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/j.bat b/bin/j.bat index dbbaec8..a4bfeea 100644 --- a/bin/j.bat +++ b/bin/j.bat @@ -3,7 +3,7 @@ setlocal EnableDelayedExpansion echo %*|>nul findstr /rx \-.* if ERRORLEVEL 1 ( - for /f %%i in ('python %~dp0\autojump %*') do set new_path=%%i + for /f %%i in ('python "%~dp0\autojump" %*') do set new_path=%%i if exist !new_path!\nul ( echo !new_path! pushd !new_path! @@ -18,4 +18,4 @@ if ERRORLEVEL 1 ( ) ) else ( python "%~dp0\autojump" %* -) \ No newline at end of file +) diff --git a/bin/jo.bat b/bin/jo.bat index 27f5b7b..34fe243 100644 --- a/bin/jo.bat +++ b/bin/jo.bat @@ -3,7 +3,7 @@ setlocal EnableDelayedExpansion echo %*|>nul findstr /rx \-.* if ERRORLEVEL 1 ( - for /f %%i in ('python %~dp0\autojump %*') do set new_path=%%i + for /f %%i in ('python "%~dp0\autojump" %*') do set new_path=%%i if exist !new_path!\nul ( start !new_path! ) else ( From 3e5cec67b995c61e8724ba8fe28cb0dd3469cd4c Mon Sep 17 00:00:00 2001 From: TheArtist Date: Fri, 11 Sep 2015 19:37:39 +0300 Subject: [PATCH 03/19] Autojump lua script portability fix --- bin/autojump.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/autojump.lua b/bin/autojump.lua index 37422e8..591b55d 100644 --- a/bin/autojump.lua +++ b/bin/autojump.lua @@ -1,13 +1,15 @@ +local AUTOJUMP_DIR = debug.getinfo(1, "S").source:match[[^@?(.*[\/])[^\/]-$]] .. "..\\AutoJump" +local AUTOJUMP_BIN_DIR = AUTOJUMP_DIR .. "\\bin" local AUTOJUMP_BIN = (AUTOJUMP_BIN_DIR or clink.get_env("LOCALAPPDATA") .. "\\autojump\\bin") .. "\\autojump" function autojump_add_to_database() - os.execute("python " .. AUTOJUMP_BIN .. " --add " .. clink.get_cwd() .. " 2> " .. clink.get_env("TEMP") .. "\\autojump_error.txt") + os.execute("python " .. "\"" .. AUTOJUMP_BIN .. "\"" .. " --add " .. "\"" .. clink.get_cwd() .. "\"" .. " 2> " .. clink.get_env("TEMP") .. "\\autojump_error.txt") end clink.prompt.register_filter(autojump_add_to_database, 99) function autojump_completion(word) - for line in io.popen("python " .. AUTOJUMP_BIN .. " --complete " .. word):lines() do + for line in io.popen("python " .. "\"" .. AUTOJUMP_BIN .. "\"" .. " --complete " .. word):lines() do clink.add_match(line) end return {} From 8fa8b0634935063fcb73bbf6ffdc2f17cbc00d5d Mon Sep 17 00:00:00 2001 From: "johannes@debussy" Date: Tue, 2 Feb 2016 14:15:41 +0100 Subject: [PATCH 04/19] only use colors if stdout is a terminal --- bin/autojump.bash | 6 +++++- bin/autojump.zsh | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/autojump.bash b/bin/autojump.bash index 0c49d75..a7c8fdd 100644 --- a/bin/autojump.bash +++ b/bin/autojump.bash @@ -61,7 +61,11 @@ j() { output="$(autojump ${@})" if [[ -d "${output}" ]]; then - echo -e "\\033[31m${output}\\033[0m" + if [ -t 1 ]; then # if stdout is a terminal, use colors + echo -e "\\033[31m${output}\\033[0m" + else + echo -e "${output}" + fi cd "${output}" else echo "autojump: directory '${@}' not found" diff --git a/bin/autojump.zsh b/bin/autojump.zsh index fbc0960..25d50ee 100644 --- a/bin/autojump.zsh +++ b/bin/autojump.zsh @@ -52,7 +52,11 @@ j() { setopt localoptions noautonamedirs local output="$(autojump ${@})" if [[ -d "${output}" ]]; then - echo -e "\\033[31m${output}\\033[0m" + if [ -t 1 ]; then # if stdout is a terminal, use colors + echo -e "\\033[31m${output}\\033[0m" + else + echo -e "${output}" + fi cd "${output}" else echo "autojump: directory '${@}' not found" From 14ea9513fd0e0cd1171433a0a0bac283024effdd Mon Sep 17 00:00:00 2001 From: William Ting Date: Tue, 2 Feb 2016 07:20:50 -0800 Subject: [PATCH 05/19] Update changelog for v22.3.0 --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 7a4b7df..3fe12ea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ ## Summary of release changes, see commit history for more details: ## https://github.com/joelthelion/autojump/commits/master/ +### Release v22.3.0: +- use colors only if stdout is a terminal +- updated RedHat docs +- misc bug fixes for fish and Clink versions + ### Release v22.2.2: #### Backwards Incompatible From aa366c3a4f647da68b47f0152217acb1e197eb3e Mon Sep 17 00:00:00 2001 From: graysky Date: Sun, 21 Feb 2016 05:46:40 -0500 Subject: [PATCH 06/19] bump version in script to match release --- bin/autojump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/autojump b/bin/autojump index 9660128..5595d14 100755 --- a/bin/autojump +++ b/bin/autojump @@ -60,7 +60,7 @@ from autojump_utils import sanitize from autojump_utils import take from autojump_utils import unico -VERSION = '22.2.4' +VERSION = '22.3.0' FUZZY_MATCH_THRESHOLD = 0.6 TAB_ENTRIES_COUNT = 9 TAB_SEPARATOR = '__' From a5e4b83e824d5919240fb97cbb808247cd64a82e Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 22:37:49 -0700 Subject: [PATCH 07/19] Remove unnecessary requirements-dev.txt. --- dev-requirements.txt | 4 ---- tox.ini | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 dev-requirements.txt diff --git a/dev-requirements.txt b/dev-requirements.txt deleted file mode 100644 index 2c84e24..0000000 --- a/dev-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -flake8 -mock -pytest -tox diff --git a/tox.ini b/tox.ini index 971d67a..9888afe 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,9 @@ envlist = skipsdist = True [testenv] -deps = -rdev-requirements.txt +deps = + mock + pytest commands = py.test -rsxX -q [testenv:flake8] From 5985ce604ad7a4134dc5ec223e7fbff7c341a14d Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 22:38:00 -0700 Subject: [PATCH 08/19] Add make test-fast. --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index a357f26..e59d6c9 100644 --- a/Makefile +++ b/Makefile @@ -41,3 +41,7 @@ tar: test: lint @find . -type f -iname "*.pyc" -delete tox + +test-fast: + @find . -type f -iname "*.pyc" -delete + tox -e py27 From 0b184f3bf088105ac06b86419508ccabaabb8a86 Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 22:44:27 -0700 Subject: [PATCH 09/19] Update tox. --- Makefile | 3 ++- tox.ini | 39 ++++++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index e59d6c9..99c4bac 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ docs: pandoc -s -w man docs/manpage_header.md docs/header.md docs/body.md -o docs/autojump.1 pandoc -s -w markdown docs/header.md docs/install.md docs/body.md -o README.md -lint: +flake8: @flake8 ./ --config=tox.ini release: docs @@ -41,6 +41,7 @@ tar: test: lint @find . -type f -iname "*.pyc" -delete tox + tox -e flake8 test-fast: @find . -type f -iname "*.pyc" -delete diff --git a/tox.ini b/tox.ini index 9888afe..6e227a3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,34 +1,43 @@ [tox] envlist = - py26, - py27, - py32, - py33, - py34 + py26, + py27, + py32, + py33, + py34 # ignore missing setup.py skipsdist = True [testenv] +setenv = + PYTHONDONTWRITEBYTECODE = 1 deps = mock + coverage pytest -commands = py.test -rsxX -q +commands = + coverage run --source=bin/ -m pytest -vv -rxs --tb native -s --durations 10 --strict {posargs:tests} + coverage report -m [testenv:flake8] -deps = flake8 -commands = flake8 . +deps = + flake8 + pyflakes + pep8 + mccabe +commands = + flake8 . [flake8] filename = - *.py, - autojump + *.py, + autojump ignore = - E126, - E128 -max-line-length = 79 -max-complexity = 10 + E126, + E128 +max-line-length = 131 +max-complexity = 20 show-pep8 = True [pytest] -addopts = -rsxX -q norecursedirs = .git .tox docs From ed7ec4dbddda1d7d8acccf78d74d6131413d64b8 Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 22:50:00 -0700 Subject: [PATCH 10/19] Ignore .cache. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9ab8a71..f38419e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.cache .coverage *.pyc __pycache__ From 377eadbad3fc18f66c055d22ef3dedeff8e4d874 Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 22:50:09 -0700 Subject: [PATCH 11/19] Add dev debug tools. --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 6e227a3..f2c9332 100644 --- a/tox.ini +++ b/tox.ini @@ -14,6 +14,8 @@ setenv = deps = mock coverage + ipdb + ipython pytest commands = coverage run --source=bin/ -m pytest -vv -rxs --tb native -s --durations 10 --strict {posargs:tests} From db1c32ff6e26098f0d79f68625dd8498969f709e Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 23:02:19 -0700 Subject: [PATCH 12/19] Add requirements-dev.txt back for tox. --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements-dev.txt diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..053148f --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1 @@ +tox From a9c892f7135e180cf27a3bcbf6fa32e9a485d3c7 Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 23:25:07 -0700 Subject: [PATCH 13/19] Add pre-commit. --- .pre-commit-config.yaml | 25 +++++++++++++++++++++++++ Makefile | 13 ++++++++----- tox.ini | 8 +++++++- 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..10268ec --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,25 @@ +- repo: git@github.com:pre-commit/pre-commit-hooks.git + sha: 6f2b0a27e5b9047c6c067fb3d575ba323d572793 + hooks: + - id: autopep8-wrapper + args: + - --in-place + - --aggressive + - --aggressive + - id: check-added-large-files + - id: check-ast + - id: check-case-conflict + - id: check-docstring-first + - id: debug-statements + - id: double-quote-string-fixer + - id: end-of-file-fixer + - id: fix-encoding-pragma + - id: flake8 + args: [--ignore=E731] + - id: requirements-txt-fixer + - id: trailing-whitespace +- repo: git@github.com:asottile/reorder_python_imports.git + sha: 017e2f64306853ec7f000db52b8280da27eb3b96 + hooks: + - id: reorder-python-imports + language_version: python2.7 diff --git a/Makefile b/Makefile index 99c4bac..358f22f 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,10 @@ docs: pandoc -s -w markdown docs/header.md docs/install.md docs/body.md -o README.md flake8: - @flake8 ./ --config=tox.ini + @tox -e flake8 + +pre-commit: + @tox -e pre-commit -- install -f --install-hooks release: docs # Check for tag existence @@ -38,11 +41,11 @@ tar: git archive --format=tar --prefix autojump_v$(VERSION)/ $(TAGNAME) | gzip > autojump_v$(VERSION).tar.gz sha1sum autojump_v$(VERSION).tar.gz -test: lint - @find . -type f -iname "*.pyc" -delete +test: pre-commit lint + @find . -type f -iname '*.py[co]' -delete tox tox -e flake8 -test-fast: - @find . -type f -iname "*.pyc" -delete +test-fast: pre-commit + @find . -type f -iname '*.py[co]' -delete tox -e py27 diff --git a/tox.ini b/tox.ini index f2c9332..66eba89 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ envlist = # ignore missing setup.py skipsdist = True -[testenv] +[testenv:py] setenv = PYTHONDONTWRITEBYTECODE = 1 deps = @@ -30,6 +30,12 @@ deps = commands = flake8 . +[testenv:pre-commit] +deps = + pre-commit +command = + pre-commit {posargs} + [flake8] filename = *.py, From e57956cc1c747dc31f3afeac47b4ea8936de8b78 Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 23:29:55 -0700 Subject: [PATCH 14/19] Use only pre-commit's flake8. --- .pre-commit-config.yaml | 6 +++++- Makefile | 6 +----- tox.ini | 11 ----------- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10268ec..7095d21 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,7 +15,11 @@ - id: end-of-file-fixer - id: fix-encoding-pragma - id: flake8 - args: [--ignore=E731] + args: + - --ignore=E126 + - --ignore=E128 + - --ignore=E402 + - --ignore=E731 - id: requirements-txt-fixer - id: trailing-whitespace - repo: git@github.com:asottile/reorder_python_imports.git diff --git a/Makefile b/Makefile index 358f22f..5466f00 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,6 @@ docs: pandoc -s -w man docs/manpage_header.md docs/header.md docs/body.md -o docs/autojump.1 pandoc -s -w markdown docs/header.md docs/install.md docs/body.md -o README.md -flake8: - @tox -e flake8 - pre-commit: @tox -e pre-commit -- install -f --install-hooks @@ -41,10 +38,9 @@ tar: git archive --format=tar --prefix autojump_v$(VERSION)/ $(TAGNAME) | gzip > autojump_v$(VERSION).tar.gz sha1sum autojump_v$(VERSION).tar.gz -test: pre-commit lint +test: pre-commit @find . -type f -iname '*.py[co]' -delete tox - tox -e flake8 test-fast: pre-commit @find . -type f -iname '*.py[co]' -delete diff --git a/tox.ini b/tox.ini index 66eba89..1dfb82f 100644 --- a/tox.ini +++ b/tox.ini @@ -36,16 +36,5 @@ deps = command = pre-commit {posargs} -[flake8] -filename = - *.py, - autojump -ignore = - E126, - E128 -max-line-length = 131 -max-complexity = 20 -show-pep8 = True - [pytest] norecursedirs = .git .tox docs From d52979027810a6b5a5ce758be978e2aa9b8c0f84 Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 23:33:04 -0700 Subject: [PATCH 15/19] Run pre-commit on repo. --- bin/autojump_argparse.py | 2 +- bin/autojump_data.py | 27 +++++++++---------- bin/autojump_utils.py | 7 +++-- install.py | 50 ++++++++++++++++++------------------ tests/autojump_utils_test.py | 38 +++++++++++++-------------- tools/autojump_ipython.py | 9 ++++--- uninstall.py | 42 ++++++++++++++++++------------ 7 files changed, 92 insertions(+), 83 deletions(-) diff --git a/bin/autojump_argparse.py b/bin/autojump_argparse.py index ea17c6f..920eed4 100644 --- a/bin/autojump_argparse.py +++ b/bin/autojump_argparse.py @@ -1,5 +1,5 @@ -# Author: Steven J. Bethard . # -*- coding: utf-8 -*- +# Author: Steven J. Bethard . # flake8: noqa """Command-line parsing library diff --git a/bin/autojump_data.py b/bin/autojump_data.py index 33987b3..37878ea 100644 --- a/bin/autojump_data.py +++ b/bin/autojump_data.py @@ -2,26 +2,27 @@ # -*- coding: utf-8 -*- from __future__ import print_function -from codecs import open -from collections import namedtuple import os import shutil import sys +from codecs import open +from collections import namedtuple from tempfile import NamedTemporaryFile from time import time -if sys.version_info[0] == 3: - ifilter = filter - imap = map -else: - from itertools import ifilter - from itertools import imap - from autojump_utils import create_dir -from autojump_utils import unico from autojump_utils import is_osx from autojump_utils import is_python3 from autojump_utils import move_file +from autojump_utils import unico + + +if sys.version_info[0] == 3: + ifilter = filter + imap = map +else: + from itertools import ifilter # noqa + from itertools import imap # noqa BACKUP_THRESHOLD = 24 * 60 * 60 @@ -95,7 +96,7 @@ def migrate_osx_xdg_data(config): Older versions incorrectly used Linux XDG_DATA_HOME paths on OS X. This migrates autojump files from ~/.local/share/autojump to ~/Library/autojump """ - assert is_osx(), "This function should only be run on OS X." + assert is_osx(), 'This function should only be run on OS X.' xdg_data_home = os.path.join(os.path.expanduser('~'), '.local', 'share') xdg_aj_home = os.path.join(xdg_data_home, 'autojump') @@ -125,12 +126,12 @@ def save(config, data): with open(temp.name, 'w', encoding='utf-8', errors='replace') as f: for path, weight in data.items(): - f.write(unico("%s\t%s\n" % (weight, path))) + f.write(unico('%s\t%s\n' % (weight, path))) f.flush() os.fsync(f) except IOError as ex: - print("Error saving autojump data (disk full?)" % ex, file=sys.stderr) + print('Error saving autojump data (disk full?)' % ex, file=sys.stderr) sys.exit(1) # move temp_file -> autojump.txt diff --git a/bin/autojump_utils.py b/bin/autojump_utils.py index 329e721..5d40519 100644 --- a/bin/autojump_utils.py +++ b/bin/autojump_utils.py @@ -1,16 +1,15 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - from __future__ import print_function import errno -from itertools import islice import os import platform import re import shutil import sys import unicodedata +from itertools import islice if sys.version_info[0] == 3: imap = map @@ -75,7 +74,7 @@ def get_pwd(): try: return os.getcwdu() except OSError: - print("Current directory no longer exists.", file=sys.stderr) + print('Current directory no longer exists.', file=sys.stderr) raise @@ -141,7 +140,7 @@ def move_file(src, dst): def print_entry(entry): - print_local("%.1f:\t%s" % (entry.weight, entry.path)) + print_local('%.1f:\t%s' % (entry.weight, entry.path)) def print_local(string): diff --git a/install.py b/install.py index 90ea4f9..b48dbe4 100755 --- a/install.py +++ b/install.py @@ -8,13 +8,13 @@ import shutil import sys sys.path.append('bin') -from autojump_argparse import ArgumentParser +from autojump_argparse import ArgumentParser # noqa SUPPORTED_SHELLS = ('bash', 'zsh', 'fish', 'tcsh') def cp(src, dest, dryrun=False): - print("copying file: %s -> %s" % (src, dest)) + print('copying file: %s -> %s' % (src, dest)) if not dryrun: shutil.copy(src, dest) @@ -24,18 +24,18 @@ def get_shell(): def mkdir(path, dryrun=False): - print("creating directory:", path) + print('creating directory:', path) if not dryrun and not os.path.exists(path): os.makedirs(path) def modify_autojump_sh(etc_dir, share_dir, dryrun=False): """Append custom installation path to autojump.sh""" - custom_install = "\ + custom_install = '\ \n# check custom install \ \nif [ -s %s/autojump.${shell} ]; then \ \n source %s/autojump.${shell} \ - \nfi\n" % (share_dir, share_dir) + \nfi\n' % (share_dir, share_dir) with open(os.path.join(etc_dir, 'autojump.sh'), 'a') as f: f.write(custom_install) @@ -44,8 +44,8 @@ def modify_autojump_sh(etc_dir, share_dir, dryrun=False): def modify_autojump_lua(clink_dir, bin_dir, dryrun=False): """Prepend custom AUTOJUMP_BIN_DIR definition to autojump.lua""" custom_install = "local AUTOJUMP_BIN_DIR = \"%s\"\n" % bin_dir.replace( - "\\", - "\\\\") + '\\', + '\\\\') clink_file = os.path.join(clink_dir, 'autojump.lua') with open(clink_file, 'r') as f: original = f.read() @@ -60,7 +60,7 @@ def parse_arguments(): # noqa 'autojump') else: default_user_destdir = os.path.join( - os.path.expanduser("~"), + os.path.expanduser('~'), '.autojump') default_user_prefix = '' default_user_zshshare = 'functions' @@ -73,10 +73,10 @@ def parse_arguments(): # noqa description='Installs autojump globally for root users, otherwise \ installs in current user\'s home directory.') parser.add_argument( - '-n', '--dryrun', action="store_true", default=False, + '-n', '--dryrun', action='store_true', default=False, help='simulate installation') parser.add_argument( - '-f', '--force', action="store_true", default=False, + '-f', '--force', action='store_true', default=False, help='skip root user, shell type, Python version checks') parser.add_argument( '-d', '--destdir', metavar='DIR', default=default_user_destdir, @@ -91,28 +91,28 @@ def parse_arguments(): # noqa '-c', '--clinkdir', metavar='DIR', default=default_clink_dir, help='set clink directory location to DIR (Windows only)') parser.add_argument( - '-s', '--system', action="store_true", default=False, + '-s', '--system', action='store_true', default=False, help='install system wide for all users') args = parser.parse_args() if not args.force: if sys.version_info[0] == 2 and sys.version_info[1] < 6: - print("Python v2.6+ or v3.0+ required.", file=sys.stderr) + print('Python v2.6+ or v3.0+ required.', file=sys.stderr) sys.exit(1) if args.system: if platform.system() == 'Windows': - print("System-wide installation is not supported on Windows.", + print('System-wide installation is not supported on Windows.', file=sys.stderr) sys.exit(1) elif os.geteuid() != 0: - print("Please rerun as root for system-wide installation.", + print('Please rerun as root for system-wide installation.', file=sys.stderr) sys.exit(1) if platform.system() != 'Windows' \ and get_shell() not in SUPPORTED_SHELLS: - print("Unsupported shell: %s" % os.getenv('SHELL'), + print('Unsupported shell: %s' % os.getenv('SHELL'), file=sys.stderr) sys.exit(1) @@ -125,7 +125,7 @@ def parse_arguments(): # noqa if args.system: if args.custom_install: - print("Custom paths incompatible with --system option.", + print('Custom paths incompatible with --system option.', file=sys.stderr) sys.exit(1) @@ -138,34 +138,34 @@ def parse_arguments(): # noqa def show_post_installation_message(etc_dir, share_dir, bin_dir): if platform.system() == 'Windows': - print("\nPlease manually add %s to your user path" % bin_dir) + print('\nPlease manually add %s to your user path' % bin_dir) else: if get_shell() == 'fish': aj_shell = '%s/autojump.fish' % share_dir - source_msg = "if test -f %s; . %s; end" % (aj_shell, aj_shell) + source_msg = 'if test -f %s; . %s; end' % (aj_shell, aj_shell) rcfile = '~/.config/fish/config.fish' else: aj_shell = '%s/autojump.sh' % etc_dir - source_msg = "[[ -s %s ]] && source %s" % (aj_shell, aj_shell) + source_msg = '[[ -s %s ]] && source %s' % (aj_shell, aj_shell) if platform.system() == 'Darwin' and get_shell() == 'bash': rcfile = '~/.profile' else: rcfile = '~/.%src' % get_shell() - print("\nPlease manually add the following line(s) to %s:" % rcfile) + print('\nPlease manually add the following line(s) to %s:' % rcfile) print('\n\t' + source_msg) if get_shell() == 'zsh': - print("\n\tautoload -U compinit && compinit -u") + print('\n\tautoload -U compinit && compinit -u') - print("\nPlease restart terminal(s) before running autojump.\n") + print('\nPlease restart terminal(s) before running autojump.\n') def main(args): if args.dryrun: - print("Installing autojump to %s (DRYRUN)..." % args.destdir) + print('Installing autojump to %s (DRYRUN)...' % args.destdir) else: - print("Installing autojump to %s ..." % args.destdir) + print('Installing autojump to %s ...' % args.destdir) bin_dir = os.path.join(args.destdir, args.prefix, 'bin') etc_dir = os.path.join(args.destdir, 'etc', 'profile.d') @@ -212,5 +212,5 @@ def main(args): show_post_installation_message(etc_dir, share_dir, bin_dir) -if __name__ == "__main__": +if __name__ == '__main__': sys.exit(main(parse_arguments())) diff --git a/tests/autojump_utils_test.py b/tests/autojump_utils_test.py index 4403595..fd71a20 100644 --- a/tests/autojump_utils_test.py +++ b/tests/autojump_utils_test.py @@ -7,19 +7,19 @@ import mock import pytest sys.path.append(os.path.join(os.getcwd(), 'bin')) -import autojump_utils -from autojump_utils import encode_local -from autojump_utils import first -from autojump_utils import get_tab_entry_info -from autojump_utils import has_uppercase -from autojump_utils import in_bash -from autojump_utils import is_python3 -from autojump_utils import last -from autojump_utils import sanitize -from autojump_utils import second -from autojump_utils import surround_quotes -from autojump_utils import take -from autojump_utils import unico +import autojump_utils # noqa +from autojump_utils import encode_local # noqa +from autojump_utils import first # noqa +from autojump_utils import get_tab_entry_info # noqa +from autojump_utils import has_uppercase # noqa +from autojump_utils import in_bash # noqa +from autojump_utils import is_python3 # noqa +from autojump_utils import last # noqa +from autojump_utils import sanitize # noqa +from autojump_utils import second # noqa +from autojump_utils import surround_quotes # noqa +from autojump_utils import take # noqa +from autojump_utils import unico # noqa if is_python3(): @@ -37,27 +37,27 @@ def u(string): # strings -@pytest.mark.skipif(is_python3(), reason="Unicode sucks.") +@pytest.mark.skipif(is_python3(), reason='Unicode sucks.') @mock.patch.object(sys, 'getfilesystemencoding', return_value='ascii') def test_encode_local_ascii(_): assert encode_local(u('foo')) == b'foo' -@pytest.mark.skipif(is_python3(), reason="Unicode sucks.") -@pytest.mark.xfail(reason="disabled due to pytest bug: https://bitbucket.org/hpk42/pytest/issue/534/pytest-fails-to-catch-unicodedecodeerrors") # noqa +@pytest.mark.skipif(is_python3(), reason='Unicode sucks.') +@pytest.mark.xfail(reason='disabled due to pytest bug: https://bitbucket.org/hpk42/pytest/issue/534/pytest-fails-to-catch-unicodedecodeerrors') # noqa @mock.patch.object(sys, 'getfilesystemencoding', return_value='ascii') def test_encode_local_ascii_fails(_): with pytest.raises(UnicodeDecodeError): encode_local(u('日本語')) -@pytest.mark.skipif(is_python3(), reason="Unicode sucks.") +@pytest.mark.skipif(is_python3(), reason='Unicode sucks.') @mock.patch.object(sys, 'getfilesystemencoding', return_value=None) def test_encode_local_empty(_): assert encode_local(b'foo') == u('foo') -@pytest.mark.skipif(is_python3(), reason="Unicode sucks.") +@pytest.mark.skipif(is_python3(), reason='Unicode sucks.') @mock.patch.object(sys, 'getfilesystemencoding', return_value='utf-8') def test_encode_local_unicode(_): assert encode_local(b'foo') == u('foo') @@ -86,7 +86,7 @@ def test_sanitize(): assert sanitize([r'/foo/bar/', r'/']) == [u('/foo/bar'), u('/')] -@pytest.mark.skipif(is_python3(), reason="Unicode sucks.") +@pytest.mark.skipif(is_python3(), reason='Unicode sucks.') def test_unico(): assert unico(str('blah')) == u('blah') assert unico(str('日本語')) == u('日本語') diff --git a/tools/autojump_ipython.py b/tools/autojump_ipython.py index 995fac7..4f960be 100644 --- a/tools/autojump_ipython.py +++ b/tools/autojump_ipython.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """ IPython autojump magic @@ -13,8 +14,8 @@ And copy this file into the "startup" folder of your new profile (e.g. @TODO: extend %cd to call "autojump -a" """ -from subprocess import Popen from subprocess import PIPE +from subprocess import Popen from IPython.core.magic import register_line_magic @@ -25,9 +26,9 @@ ip = get_ipython() # noqa def j(path): cmd = ['autojump'] + path.split() newpath = Popen( - cmd, - stdout=PIPE, - shell=False).communicate()[0].strip() + cmd, + stdout=PIPE, + shell=False).communicate()[0].strip() if newpath: ip.magic('cd %s' % newpath.decode('utf-8')) diff --git a/uninstall.py b/uninstall.py index 24296b6..9e9417b 100755 --- a/uninstall.py +++ b/uninstall.py @@ -1,6 +1,5 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - from __future__ import print_function import os @@ -9,7 +8,7 @@ import shutil import sys sys.path.append('bin') -from autojump_argparse import ArgumentParser +from autojump_argparse import ArgumentParser # noqa def is_empty_dir(path): @@ -28,10 +27,10 @@ def parse_arguments(): parser = ArgumentParser( description='Uninstalls autojump.') parser.add_argument( - '-n', '--dryrun', action="store_true", default=False, + '-n', '--dryrun', action='store_true', default=False, help='simulate installation') parser.add_argument( - '-u', '--userdata', action="store_true", default=False, + '-u', '--userdata', action='store_true', default=False, help='delete user data') parser.add_argument( '-d', '--destdir', metavar='DIR', @@ -61,7 +60,7 @@ def remove_custom_installation(args, dryrun=False): if not os.path.exists(share_dir): return - print("\nFound custom installation...") + print('\nFound custom installation...') rm(os.path.join(bin_dir, 'autojump'), dryrun) rm(os.path.join(bin_dir, 'autojump_data.py'), dryrun) rm(os.path.join(bin_dir, 'autojump_utils.py'), dryrun) @@ -94,18 +93,27 @@ def remove_system_installation(dryrun=False): default_zshshare = '/usr/share/zsh/site-functions' bin_dir = os.path.join(default_destdir, default_prefix, 'bin') - doc_dir = os.path.join(default_destdir, default_prefix, 'share', 'man', 'man1') + doc_dir = os.path.join( + default_destdir, + default_prefix, + 'share', + 'man', + 'man1') etc_dir = os.path.join(default_destdir, 'etc', 'profile.d') - share_dir = os.path.join(default_destdir, default_prefix, 'share', 'autojump') + share_dir = os.path.join( + default_destdir, + default_prefix, + 'share', + 'autojump') zshshare_dir = os.path.join(default_destdir, default_zshshare) if not os.path.exists(share_dir): return - print("\nFound system installation...") + print('\nFound system installation...') if os.geteuid() != 0: - print("Please rerun as root for system-wide uninstall, skipping...", + print('Please rerun as root for system-wide uninstall, skipping...', file=sys.stderr) return @@ -142,7 +150,7 @@ def remove_user_data(dryrun=False): 'autojump')) if os.path.exists(data_home): - print("\nFound user data...") + print('\nFound user data...') rmdir(data_home, dryrun) @@ -152,10 +160,10 @@ def remove_user_installation(dryrun=False): 'autojump') clink_dir = os.path.join(os.getenv('LOCALAPPDATA', ''), 'clink') else: - default_destdir = os.path.join(os.path.expanduser("~"), '.autojump') + default_destdir = os.path.join(os.path.expanduser('~'), '.autojump') if os.path.exists(default_destdir): - print("\nFound user installation...") + print('\nFound user installation...') rmdir(default_destdir, dryrun) if platform.system() == 'Windows' and os.path.exists(clink_dir): rm(os.path.join(clink_dir, 'autojump.lua'), dryrun) @@ -163,23 +171,23 @@ def remove_user_installation(dryrun=False): def rm(path, dryrun): if os.path.exists(path): - print("deleting file:", path) + print('deleting file:', path) if not dryrun: os.remove(path) def rmdir(path, dryrun): if os.path.exists(path): - print("deleting directory:", path) + print('deleting directory:', path) if not dryrun: shutil.rmtree(path) def main(args): if args.dryrun: - print("Uninstalling autojump (DRYRUN)...") + print('Uninstalling autojump (DRYRUN)...') else: - print("Uninstalling autojump...") + print('Uninstalling autojump...') remove_user_installation(args.dryrun) remove_system_installation(args.dryrun) @@ -188,5 +196,5 @@ def main(args): remove_user_data(args.dryrun) -if __name__ == "__main__": +if __name__ == '__main__': sys.exit(main(parse_arguments())) From 25ef9c6a3c9714dc4880d4823a72c31c9d8f1292 Mon Sep 17 00:00:00 2001 From: William Ting Date: Thu, 28 Apr 2016 23:47:20 -0700 Subject: [PATCH 16/19] Fix pre-commit's flake8 options. --- .pre-commit-config.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7095d21..a9f7501 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,10 +16,9 @@ - id: fix-encoding-pragma - id: flake8 args: - - --ignore=E126 - - --ignore=E128 - - --ignore=E402 - - --ignore=E731 + - --max-complexity=10 + - --ignore=E126,E128,E731 + - --exclude=bin/autojump_argparse.py - id: requirements-txt-fixer - id: trailing-whitespace - repo: git@github.com:asottile/reorder_python_imports.git From 9cf647bc6df6df94820b4ab36f6241e3993eabef Mon Sep 17 00:00:00 2001 From: William Ting Date: Fri, 29 Apr 2016 00:37:54 -0700 Subject: [PATCH 17/19] Increase line length to 130. --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a9f7501..e26ac79 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,6 +17,7 @@ - id: flake8 args: - --max-complexity=10 + - --max-line-length=130 - --ignore=E126,E128,E731 - --exclude=bin/autojump_argparse.py - id: requirements-txt-fixer From 9a6e2869b12961156e7797522536632c71ff1268 Mon Sep 17 00:00:00 2001 From: William Ting Date: Wed, 11 May 2016 20:40:00 -0700 Subject: [PATCH 18/19] Tabs to spaces. --- bin/autojump.bash | 10 +++++----- bin/autojump.zsh | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/autojump.bash b/bin/autojump.bash index a7c8fdd..379e529 100644 --- a/bin/autojump.bash +++ b/bin/autojump.bash @@ -61,11 +61,11 @@ j() { output="$(autojump ${@})" if [[ -d "${output}" ]]; then - if [ -t 1 ]; then # if stdout is a terminal, use colors - echo -e "\\033[31m${output}\\033[0m" - else - echo -e "${output}" - fi + if [ -t 1 ]; then # if stdout is a terminal, use colors + echo -e "\\033[31m${output}\\033[0m" + else + echo -e "${output}" + fi cd "${output}" else echo "autojump: directory '${@}' not found" diff --git a/bin/autojump.zsh b/bin/autojump.zsh index 25d50ee..92c31d7 100644 --- a/bin/autojump.zsh +++ b/bin/autojump.zsh @@ -52,11 +52,11 @@ j() { setopt localoptions noautonamedirs local output="$(autojump ${@})" if [[ -d "${output}" ]]; then - if [ -t 1 ]; then # if stdout is a terminal, use colors - echo -e "\\033[31m${output}\\033[0m" - else - echo -e "${output}" - fi + if [ -t 1 ]; then # if stdout is a terminal, use colors + echo -e "\\033[31m${output}\\033[0m" + else + echo -e "${output}" + fi cd "${output}" else echo "autojump: directory '${@}' not found" From ecd272e97992a7b13ff6fdf22595c02972cad571 Mon Sep 17 00:00:00 2001 From: William Ting Date: Sun, 19 Jun 2016 11:24:44 -0700 Subject: [PATCH 19/19] Bump version to v22.3.1. --- bin/autojump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/autojump b/bin/autojump index 5595d14..ff99163 100755 --- a/bin/autojump +++ b/bin/autojump @@ -60,7 +60,7 @@ from autojump_utils import sanitize from autojump_utils import take from autojump_utils import unico -VERSION = '22.3.0' +VERSION = '22.3.1' FUZZY_MATCH_THRESHOLD = 0.6 TAB_ENTRIES_COUNT = 9 TAB_SEPARATOR = '__'