From 0d7694819b764662dc497eaa5f84a93d72a4e8e2 Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Thu, 25 May 2017 20:22:00 +0100 Subject: [PATCH 1/3] Remove unused variables and imports pipenv/cli.py:24:1: F401 '.utils.recase_file' imported but unused pipenv/cli.py:466:5: F841 local variable 'p' is assigned to but never used pipenv/utils.py:13:5: F401 'html.parser.HTMLParser' imported but unused pipenv/utils.py:246:25: F841 local variable 'e' is assigned to but never used tests/test_pipenv.py:9:1: F401 'pipenv.cli.which_pip' imported but unused --- pipenv/cli.py | 4 ++-- pipenv/utils.py | 7 +------ tests/test_pipenv.py | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 184b3f98..2896be33 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -22,7 +22,7 @@ from requests.packages.urllib3.exceptions import InsecureRequestWarning from .project import Project from .utils import (convert_deps_from_pip, convert_deps_to_pip, is_required_version, - proper_case, pep423_name, split_vcs, recase_file) + proper_case, pep423_name, split_vcs) from .__version__ import __version__ from . import pep508checker, progress from .environments import PIPENV_COLORBLIND, PIPENV_NOSPIN, PIPENV_SHELL_COMPAT, PIPENV_VENV_IN_PROJECT @@ -463,7 +463,7 @@ def do_lock(no_hashes=True): names_map = do_download_dependencies(dev=True, only=True, bare=True) # Load the Pipfile and generate a lockfile. - p = project._pipfile + project._pipfile lockfile = project._lockfile # Pip freeze development dependencies. diff --git a/pipenv/utils.py b/pipenv/utils.py index 995c5217..ced5030d 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -7,11 +7,6 @@ import requests import requirements import six -try: - from HTMLParser import HTMLParser -except ImportError: - from html.parser import HTMLParser - # List of version control systems we support. VCS_LIST = ('git', 'svn', 'hg', 'bzr') @@ -243,7 +238,7 @@ def walk_up(bottom): # get files in current dir try: names = os.listdir(bottom) - except Exception as e: + except Exception: return dirs, nondirs = [], [] diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index 82f98ecd..237b3e29 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -7,7 +7,7 @@ import delegator import toml from pipenv.cli import (activate_virtualenv, ensure_proper_casing, - parse_download_fname, parse_install_output, pip_install, pip_download, which_pip) + parse_download_fname, parse_install_output, pip_install, pip_download) from pipenv.project import Project From c5e7ac933d6035bfc238d05a130bf50285a65e7c Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Thu, 25 May 2017 20:24:52 +0100 Subject: [PATCH 2/3] Whitespace cleanup for flake8 pipenv/cli.py:264:1: W293 blank line contains whitespace pipenv/cli.py:546:1: E302 expected 2 blank lines, found 1 pipenv/environments.py:31:25: W292 no newline at end of file pipenv/progress.py:171:23: W292 no newline at end of file pipenv/utils.py:20:1: E302 expected 2 blank lines, found 1 pipenv/utils.py:206:6: E114 indentation is not a multiple of four (comment) tests/test_project.py:8:1: E302 expected 2 blank lines, found 1 tests/test_utils.py:7:1: E302 expected 2 blank lines, found 1 tests/test_utils.py:75:5: E303 too many blank lines (2) tests/test_utils.py:113:5: E303 too many blank lines (2) tests/test_utils.py:124:5: E303 too many blank lines (2) tests/test_utils.py:135:5: E303 too many blank lines (2) --- pipenv/cli.py | 3 ++- pipenv/environments.py | 2 +- pipenv/progress.py | 2 +- pipenv/utils.py | 3 ++- tests/test_project.py | 1 + tests/test_utils.py | 5 +---- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 2896be33..cf9f5b45 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -261,7 +261,7 @@ def do_install_dependencies(dev=False, only=False, bare=False, requirements=Fals # pip install: for dep in progress.bar(hashed_deps): - + c = pip_install(dep, ignore_hashes=ignore_hashes, allow_global=allow_global) if c.return_code != 0: @@ -543,6 +543,7 @@ def do_activate_virtualenv(bare=False): else: click.echo(activate_virtualenv()) + def do_purge(bare=False, downloads=False, allow_global=False): """Executes the purge functionality.""" diff --git a/pipenv/environments.py b/pipenv/environments.py index 25e13b43..f4cd81aa 100644 --- a/pipenv/environments.py +++ b/pipenv/environments.py @@ -28,4 +28,4 @@ if PIPENV_VENV_IN_PROJECT: # Disable spinner on windows. if os.name == 'nt': - PIPENV_NOSPIN = True \ No newline at end of file + PIPENV_NOSPIN = True diff --git a/pipenv/progress.py b/pipenv/progress.py index 1d1fff55..b590bda9 100644 --- a/pipenv/progress.py +++ b/pipenv/progress.py @@ -168,4 +168,4 @@ def mill(it, label='', hide=None, expected_size=None, every=1): if not hide: STREAM.write('\n') - STREAM.flush() \ No newline at end of file + STREAM.flush() diff --git a/pipenv/utils.py b/pipenv/utils.py index ced5030d..f933d7ce 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -12,6 +12,7 @@ VCS_LIST = ('git', 'svn', 'hg', 'bzr') requests = requests.session() + def format_toml(data): """Pretty-formats a given toml string.""" data = data.split('\n') @@ -198,7 +199,7 @@ def split_vcs(split_file): elif 'default' in split_file or 'develop' in split_file: sections = ('default', 'develop') - # For each vcs entry in a given section, move it to section-vcs. + # For each vcs entry in a given section, move it to section-vcs. for section in sections: entries = split_file.get(section, {}) vcs_dict = dict((k, entries.pop(k)) for k in list(entries.keys()) if is_vcs(entries[k])) diff --git a/tests/test_project.py b/tests/test_project.py index f5a78e43..9ab5b1fc 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -5,6 +5,7 @@ import delegator import pipenv.project + class TestProject(): def test_project(self): diff --git a/tests/test_utils.py b/tests/test_utils.py index 654478e0..49e0a021 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,6 +4,7 @@ import pytest import pipenv.utils + class TestUtils: """Test utility functions in pipenv""" @@ -71,7 +72,6 @@ class TestUtils: deps = pipenv.utils.convert_deps_to_pip(deps, r=False) assert deps[0] == 'django==1.10' - def test_convert_from_pip(self): # requests @@ -109,7 +109,6 @@ class TestUtils: dep = pipenv.utils.convert_deps_from_pip(dep) assert 'pipenv requires an #egg fragment for vcs' in str(e) - @pytest.mark.parametrize('version, specified_ver, expected', [ ('*', '*', True), ('2.1.6', '==2.1.4', False), @@ -120,7 +119,6 @@ class TestUtils: def test_is_required_version(self, version, specified_ver, expected): assert pipenv.utils.is_required_version(version, specified_ver) is expected - @pytest.mark.parametrize('entry, expected', [ ({'git': 'package.git', 'ref': 'v0.0.1'}, True), ({'hg': 'https://package.com/package', 'ref': 'v1.2.3'}, True), @@ -131,7 +129,6 @@ class TestUtils: def test_is_vcs(self, entry, expected): assert pipenv.utils.is_vcs(entry) is expected - def test_split_vcs(self): pipfile_dict = { 'packages': { From 58a10908aba9621501bcbeec9e8362221ee5af75 Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Thu, 25 May 2017 20:31:33 +0100 Subject: [PATCH 3/3] Add flake8 to the Travis run flake8 would have caught the regression in #371 and output: `pipenv/cli.py:257:19: F821 undefined name 'hashed_deps_path'` Whilst in an ideal world there would be 100% test coverage, linters help fill in the gaps, plus spot potential unused variable/imports cleanup. I'm happy to disable more of the style/whitespace pep8 rules if needed - the priority is having the pyflakes subset run in CI. --- .travis.yml | 2 ++ Pipfile | 1 + Pipfile.lock | 54 ++++++++++++++++++++++++++++++++++----------------- pipenv/cli.py | 2 +- setup.cfg | 14 +++++++++++++ 5 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 setup.cfg diff --git a/.travis.yml b/.travis.yml index 5300eefb..c5d31e83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,4 +16,6 @@ install: - "pipenv install --dev" # command to run tests script: + # flake8 has dropped support for Python 2.6. + - if [[ "$TRAVIS_PYTHON_VERSION" != "2.6" ]]; then pipenv run flake8; fi - pipenv run pytest tests diff --git a/Pipfile b/Pipfile index b683ecce..3f997b15 100644 --- a/Pipfile +++ b/Pipfile @@ -1,4 +1,5 @@ [dev-packages] +flake8 = ">=3.3.0,<4" pytest = "*" mock = "*" "delegator.py" = ">=0.0.10" diff --git a/Pipfile.lock b/Pipfile.lock index 2578aa3a..6d1638fe 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "8cba5434b2ba425d05649334b063af088196a5208a5a7c9ae52be9e1467824b8" + "sha256": "d099a1995f5e9122193bde9a54f4ca624afb2abdf0cf75e76b1930464966ea86" }, "requires": { "python_version": "2.7" @@ -17,7 +17,7 @@ "appdirs": { "version": "==1.4.3" }, - "backports.shutil_get_terminal_size": { + "backports.shutil-get-terminal-size": { "version": "==1.0.0" }, "packaging": { @@ -52,39 +52,45 @@ } }, "develop": { - "Babel": { - "version": "==2.4.0" - }, - "Jinja2": { - "version": "==2.9.6" - }, - "MarkupSafe": { - "version": "==1.0" - }, - "Pygments": { - "version": "==2.2.0" - }, - "Sphinx": { - "version": "==1.5.5" - }, "alabaster": { "version": "==0.7.10" }, "appdirs": { "version": "==1.4.3" }, + "babel": { + "version": "==2.4.0" + }, + "configparser": { + "version": "==3.5.0" + }, "delegator.py": { "version": "==0.0.10" }, "docutils": { "version": "==0.13.1" }, + "enum34": { + "version": "==1.1.6" + }, + "flake8": { + "version": "==3.3.0" + }, "funcsigs": { "version": "==1.0.2" }, "imagesize": { "version": "==0.7.1" }, + "jinja2": { + "version": "==2.9.6" + }, + "markupsafe": { + "version": "==1.0" + }, + "mccabe": { + "version": "==0.6.1" + }, "mock": { "version": "==2.0.0" }, @@ -103,11 +109,20 @@ "py": { "version": "==1.4.33" }, + "pycodestyle": { + "version": "==2.3.1" + }, + "pyflakes": { + "version": "==1.5.0" + }, + "pygments": { + "version": "==2.2.0" + }, "pyparsing": { "version": "==2.2.0" }, "pytest": { - "version": "==3.0.7" + "version": "==3.1.0" }, "pytz": { "version": "==2017.2" @@ -124,6 +139,9 @@ "snowballstemmer": { "version": "==1.2.1" }, + "sphinx": { + "version": "==1.5.5" + }, "toml": { "version": "==0.9.2" } diff --git a/pipenv/cli.py b/pipenv/cli.py index cf9f5b45..7c103207 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -51,7 +51,7 @@ if PIPENV_COLORBLIND: # Disable spinner, for cleaner build logs (the unworthy). if PIPENV_NOSPIN: - @contextlib.contextmanager + @contextlib.contextmanager # noqa: F811 def spinner(): yield diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..2979c981 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,14 @@ +[flake8] +exclude = .git,__pycache__,docs/,pipenv/vendor/,get-pipenv.py +ignore = + # The default ignore list: + E121,E123,E126,E226,E24,E704, + # Our additions: + # E127: continuation line over-indented for visual indent + # E128: continuation line under-indented for visual indent + # E129: visually indented line with same indent as next logical line + # E222: multiple spaces after operator + # E231: missing whitespace after ',' + # E402: module level import not at top of file + # E501: line too long + E127,E128,E129,E222,E231,E402,E501