From 95326372933b07ee4e50debefe4ec93ea69c28ec Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Fri, 22 Dec 2017 14:21:20 -0500 Subject: [PATCH 1/5] Skip search for requirements.txt when provided - Fixes #1197 --- pipenv/cli.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 16678415..57f921a7 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -297,7 +297,7 @@ def import_from_code(path='.'): return [] -def ensure_pipfile(validate=True): +def ensure_pipfile(validate=True, skip_requirements=False): """Creates a Pipfile for the project, if it doesn't exist.""" global USING_DEFAULT_PYTHON @@ -306,8 +306,8 @@ def ensure_pipfile(validate=True): if project.pipfile_is_empty: # If there's a requirements file, but no Pipfile... - if project.requirements_exists: - click.echo(crayons.normal(u'requirements.txt found, instead of Pipfile! Converting…', bold=True)) + if project.requirements_exists and not skip_requirements: + click.echo(crayons.normal(u'Requirements.txt found, instead of Pipfile! Converting…', bold=True)) # Create a Pipfile... python = which('python') if not USING_DEFAULT_PYTHON else False @@ -601,7 +601,7 @@ def ensure_virtualenv(three=None, python=None, site_packages=False): ensure_virtualenv(three=three, python=python, site_packages=site_packages) -def ensure_project(three=None, python=None, validate=True, system=False, warn=True, site_packages=False, deploy=False): +def ensure_project(three=None, python=None, validate=True, system=False, warn=True, site_packages=False, deploy=False, skip_requirements=False): """Ensures both Pipfile and virtualenv exist for the project.""" if not project.pipfile_exists: @@ -639,7 +639,7 @@ def ensure_project(three=None, python=None, validate=True, system=False, warn=Tr sys.exit(1) # Ensure the Pipfile exists. - ensure_pipfile(validate=validate) + ensure_pipfile(validate=validate, skip_requirements=skip_requirements) def ensure_proper_casing(pfile): @@ -1765,10 +1765,13 @@ def install( if PIPENV_USE_SYSTEM: system = True + # Don't search for requirements.txt files if the user provides one + skip_requirements = True if requirements else False + concurrent = (not sequential) # Ensure that virtualenv is available. - ensure_project(three=three, python=python, system=system, warn=True, deploy=deploy) + ensure_project(three=three, python=python, system=system, warn=True, deploy=deploy, skip_requirements=skip_requirements) # Load the --pre settings from the Pipfile. if not pre: From a94018f8377ad82324c02de90996315c91d5af1e Mon Sep 17 00:00:00 2001 From: Markus Kaiserswerth Date: Thu, 4 Jan 2018 12:13:53 +0100 Subject: [PATCH 2/5] pipenv update fails if freeze output contains comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the output of ``pip freeze`` contains comments (e. g. a line like ``## !! Could not determine repository location``), then the ``pipenv update`` command fails when it tries to parse the requirements: ``python (project-cIS5-zzV) bash-3.2$ pipenv update -d Updating all dependencies from Pipfile… Traceback (most recent call last): File "/.local/bin/pipenv", line 11, in sys.exit(cli()) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 722, in __call__ return self.main(*args, **kwargs) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 697, in main rv = self.invoke(ctx) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 895, in invoke return ctx.invoke(self.callback, **ctx.params) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/core.py", line 535, in invoke return callback(*args, **kwargs) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func return f(get_current_context(), *args, **kwargs) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/cli.py", line 2559, in update do_purge() File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/cli.py", line 1230, in do_purge dep = convert_deps_from_pip(package) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/utils.py", line 624, in convert_deps_from_pip req = get_requirement(dep) File "/.local/venvs/pipenv/lib/python3.6/site-packages/pipenv/utils.py", line 311, in get_requirement req = [r for r in requirements.parse(dep)][0] IndexError: list index out of range `` It tries to make sense of the ``##`` "requirement", which fails. This commit adds a simple fix to ignore comments in the ``pip freeze`` output. --- pipenv/cli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 57f921a7..005e9fbe 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -1212,7 +1212,9 @@ def do_purge(bare=False, downloads=False, allow_global=False, verbose=False): return freeze = delegator.run('"{0}" freeze'.format(which_pip(allow_global=allow_global))).out - installed = freeze.split() + + # Remove comments from the output, if any. + installed = [line for line in freeze.splitlines() if not line.lstrip().startswith('#')] # Remove setuptools and friends from installed, if present. for package_name in BAD_PACKAGES: From e8253feda47ac720004cd5c795701b3e1af2bb5b Mon Sep 17 00:00:00 2001 From: emmanuel valette Date: Thu, 11 Jan 2018 16:44:16 +0100 Subject: [PATCH 3/5] replace netloc by hostname when adding trusted-host arg to pip --- pipenv/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pipenv/utils.py b/pipenv/utils.py index 90a774e9..80ffc85d 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -439,7 +439,7 @@ def prepare_pip_source_args(sources, pip_args=None): # Trust the host if it's not verified. if not sources[0].get('verify_ssl', True): - pip_args.extend(['--trusted-host', urlparse(sources[0]['url']).netloc.split(':')[0]]) + pip_args.extend(['--trusted-host', urlparse(sources[0]['url']).hostname]) # Add additional sources as extra indexes. if len(sources) > 1: @@ -448,7 +448,7 @@ def prepare_pip_source_args(sources, pip_args=None): # Trust the host if it's not verified. if not source.get('verify_ssl', True): - pip_args.extend(['--trusted-host', urlparse(source['url']).netloc.split(':')[0]]) + pip_args.extend(['--trusted-host', urlparse(source['url']).hostname]) return pip_args From cea46f18c7a17af88d6232dd25a71c3647ec6155 Mon Sep 17 00:00:00 2001 From: cclauss Date: Sun, 14 Jan 2018 07:44:23 +0100 Subject: [PATCH 4/5] missing comma in __all__ tuple? --- pipenv/patched/crayons.py | 2 +- pipenv/utils.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pipenv/patched/crayons.py b/pipenv/patched/crayons.py index ef97e786..7c9ff0d2 100644 --- a/pipenv/patched/crayons.py +++ b/pipenv/patched/crayons.py @@ -18,7 +18,7 @@ PY3 = sys.version_info[0] >= 3 __all__ = ( 'red', 'green', 'yellow', 'blue', - 'black', 'magenta', 'cyan', 'white', 'normal' + 'black', 'magenta', 'cyan', 'white', 'normal', 'clean', 'disable', ) diff --git a/pipenv/utils.py b/pipenv/utils.py index 80ffc85d..90a774e9 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -439,7 +439,7 @@ def prepare_pip_source_args(sources, pip_args=None): # Trust the host if it's not verified. if not sources[0].get('verify_ssl', True): - pip_args.extend(['--trusted-host', urlparse(sources[0]['url']).hostname]) + pip_args.extend(['--trusted-host', urlparse(sources[0]['url']).netloc.split(':')[0]]) # Add additional sources as extra indexes. if len(sources) > 1: @@ -448,7 +448,7 @@ def prepare_pip_source_args(sources, pip_args=None): # Trust the host if it's not verified. if not source.get('verify_ssl', True): - pip_args.extend(['--trusted-host', urlparse(source['url']).hostname]) + pip_args.extend(['--trusted-host', urlparse(source['url']).netloc.split(':')[0]]) return pip_args From 1db269847fa92a8f23ae60bdb1b3d0324aa7df2c Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sat, 27 Jan 2018 20:43:41 -0500 Subject: [PATCH 5/5] Fix capitalization --- pipenv/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 005e9fbe..44a251bc 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -307,7 +307,7 @@ def ensure_pipfile(validate=True, skip_requirements=False): # If there's a requirements file, but no Pipfile... if project.requirements_exists and not skip_requirements: - click.echo(crayons.normal(u'Requirements.txt found, instead of Pipfile! Converting…', bold=True)) + click.echo(crayons.normal(u'requirements.txt found, instead of Pipfile! Converting…', bold=True)) # Create a Pipfile... python = which('python') if not USING_DEFAULT_PYTHON else False