From 98f7f42742826af16032e2bb5d3537ee4c952feb Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 17 Jun 2019 01:34:37 -0400 Subject: [PATCH] Fix toml parsing and resolver comparisons Signed-off-by: Dan Ryan --- README.md | 4 +- pipenv/core.py | 107 +++++++++++++---------- pipenv/environment.py | 1 - pipenv/resolver.py | 5 +- tests/integration/test_install_twists.py | 5 +- 5 files changed, 67 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 74067d58..ea2bf074 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,7 @@ Pipenv: Python Development Workflow for Humans [![image](https://img.shields.io/pypi/v/pipenv.svg)](https://python.org/pypi/pipenv) [![image](https://img.shields.io/pypi/l/pipenv.svg)](https://python.org/pypi/pipenv) -[![image](https://badge.buildkite.com/79c7eccf056b17c3151f3c4d0e4c4b8b724539d84f1e037b9b.svg?branch=master)](https://code.kennethreitz.org/source/pipenv/) -[![Azure Pipelines build status (Linux)](https://dev.azure.com/pypa/pipenv/_apis/build/status/pipenv%20CI%20(Linux)?branchName=master&label=Linux)](https://dev.azure.com/pypa/pipenv/_build/latest?definitionId=13&branchName=master) -[![Azure Pipelines build status (Windows)](https://dev.azure.com/pypa/pipenv/_apis/build/status/pipenv%20CI%20(Windows)?branchName=master&label=Windows)](https://dev.azure.com/pypa/pipenv/_build/latest?definitionId=12&branchName=master) +[![Azure Pipelines Build Status](https://dev.azure.com/pypa/pipenv/_apis/build/status/Pipenv%20CI?branchName=master)](https://dev.azure.com/pypa/pipenv/_build/latest?definitionId=16&branchName=master) [![image](https://img.shields.io/pypi/pyversions/pipenv.svg)](https://python.org/pypi/pipenv) [![image](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/kennethreitz) diff --git a/pipenv/core.py b/pipenv/core.py index f2c11aae..abc2b8ac 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -26,7 +26,7 @@ from .environments import ( PIPENV_CACHE_DIR, PIPENV_COLORBLIND, PIPENV_DEFAULT_PYTHON_VERSION, PIPENV_DONT_USE_PYENV, PIPENV_HIDE_EMOJIS, PIPENV_MAX_SUBPROCESS, PIPENV_PYUP_API_KEY, PIPENV_SHELL_FANCY, PIPENV_SKIP_VALIDATION, - PIPENV_YES, SESSION_IS_INTERACTIVE, PIP_EXISTS_ACTION + PIPENV_YES, SESSION_IS_INTERACTIVE, PIP_EXISTS_ACTION, PIPENV_RESOLVE_VCS ) from .project import Project, SourceNotFound from .utils import ( @@ -1812,7 +1812,6 @@ def do_outdated(pypi_mirror=None): (pkg.project_name, pkg.parsed_version, pkg.latest_version) for pkg in project.environment.get_outdated_packages() } - reverse_deps = project.environment.reverse_dependencies() for result in installed_packages: dep = Requirement.from_line(str(result.as_requirement())) packages.update(dep.as_pipfile()) @@ -1842,18 +1841,15 @@ def do_outdated(pypi_mirror=None): version = None if name_in_pipfile: version = get_version(project.packages[name_in_pipfile]) - reverse_deps = reverse_deps.get(name_in_pipfile) - if isinstance(reverse_deps, Mapping) and "required" in reverse_deps: - required = " {0} required".format(reverse_deps["required"]) if version: pipfile_version_text = " ({0} set in Pipfile)".format(version) else: pipfile_version_text = " (Unpinned in Pipfile)" click.echo( crayons.yellow( - "Skipped Update of Package {0!s}: {1!s} installed,{2!s}{3!s}, " - "{4!s} available.".format( - package, old_version, required, pipfile_version_text, new_version + "Skipped Update of Package {0!s}: {1!s} installed{2!s}, " + "{3!s} available.".format( + package, old_version, pipfile_version_text, new_version ) ), err=True ) @@ -2083,6 +2079,7 @@ def do_install( os.environ["PIP_USER"] = vistir.compat.fs_str("0") if "PYTHONHOME" in os.environ: del os.environ["PYTHONHOME"] + sp.text = "Resolving {0}...".format(pkg_line) try: pkg_requirement = Requirement.from_line(pkg_line) except ValueError as e: @@ -2091,30 +2088,45 @@ def do_install( sys.exit(1) if index_url: pkg_requirement.index = index_url + deps = [] + if pkg_requirement.is_vcs and PIPENV_RESOLVE_VCS: + deps = pkg_requirement.req.dependencies + to_install = [pkg_requirement,] + no_deps = False + sp.text = "Installing..." try: - c = pip_install( - pkg_requirement, - ignore_hashes=True, - allow_global=system, - selective_upgrade=selective_upgrade, - no_deps=False, - pre=pre, - requirements_dir=requirements_directory, - index=index_url, - extra_indexes=extra_index_url, - pypi_mirror=pypi_mirror, - ) - if not c.ok: - sp.write_err(vistir.compat.fs_str( - "{0}: {1}".format( - crayons.red("WARNING"), - "Failed installing package {0}".format(pkg_line) - ), - )) - sp.write_err(vistir.compat.fs_str( - "Error text: {0}".format(c.out) - )) - raise RuntimeError(c.err) + if deps: + to_install.extend([ + Requirement.from_line(d) for d in list(deps[0].values()) + ]) + no_deps = True + for dep in to_install: + sp.text = "Installing {0}...".format(dep.name) + c = pip_install( + dep, + ignore_hashes=True, + allow_global=system, + selective_upgrade=selective_upgrade, + no_deps=no_deps, + pre=pre, + requirements_dir=requirements_directory, + index=index_url, + extra_indexes=extra_index_url, + pypi_mirror=pypi_mirror, + ) + if not c.ok: + sp.write_err(vistir.compat.fs_str( + "{0}: {1}".format( + crayons.red("WARNING"), + "Failed installing package {0}".format(pkg_line) + ), + )) + sp.write_err(vistir.compat.fs_str( + "Error text: {0}".format(c.out) + )) + raise RuntimeError(c.err) + if environments.is_verbose(): + click.echo(crayons.blue(format_pip_output(c.out))) except (ValueError, RuntimeError) as e: sp.write_err(vistir.compat.fs_str( "{0}: {1}".format(crayons.red("WARNING"), e), @@ -2124,7 +2136,7 @@ def do_install( )) sys.exit(1) # Warn if --editable wasn't passed. - if pkg_requirement.is_vcs and not pkg_requirement.editable: + if pkg_requirement.is_vcs and not pkg_requirement.editable and not PIPENV_RESOLVE_VCS: sp.write_err( "{0}: You installed a VCS dependency in non-editable mode. " "This will work fine, but sub-dependencies will not be resolved by {1}." @@ -2134,24 +2146,23 @@ def do_install( crayons.red("$ pipenv lock"), ) ) - click.echo(crayons.blue(format_pip_output(c.out))) - # Ensure that package was successfully installed. - if c.return_code != 0: + # Ensure that package was successfully installed. + if c.return_code != 0: + sp.write_err(vistir.compat.fs_str( + "{0} An error occurred while installing {1}!".format( + crayons.red("Error: ", bold=True), crayons.green(pkg_line) + ), + )) + sp.write_err(vistir.compat.fs_str(crayons.blue(format_pip_error(c.err)))) + if "setup.py egg_info" in c.err: sp.write_err(vistir.compat.fs_str( - "{0} An error occurred while installing {1}!".format( - crayons.red("Error: ", bold=True), crayons.green(pkg_line) - ), + "This is likely caused by a bug in {0}. " + "Report this to its maintainers.".format( + crayons.green(pkg_requirement.name) + ) )) - sp.write_err(vistir.compat.fs_str(crayons.blue(format_pip_error(c.err)))) - if "setup.py egg_info" in c.err: - sp.write_err(vistir.compat.fs_str( - "This is likely caused by a bug in {0}. " - "Report this to its maintainers.".format( - crayons.green(pkg_requirement.name) - ) - )) - sp.fail(environments.PIPENV_SPINNER_FAIL_TEXT.format("Installation Failed")) - sys.exit(1) + sp.fail(environments.PIPENV_SPINNER_FAIL_TEXT.format("Installation Failed")) + sys.exit(1) sp.write(vistir.compat.fs_str( u"{0} {1} {2} {3}{4}".format( crayons.normal(u"Adding", bold=True), diff --git a/pipenv/environment.py b/pipenv/environment.py index 379f2f11..a8489d95 100644 --- a/pipenv/environment.py +++ b/pipenv/environment.py @@ -248,7 +248,6 @@ class Environment(object): "prefix='{1}');paths['platlib'] = distutils.sysconfig.get_python_lib(" "plat_specific=1, prefix='{1}');print(json.dumps(paths))" ) - vistir.misc.echo("command: {0}".format(py_command.format(install_scheme, prefix)), fg="white", style="bold", err=True) command = [self.python, "-c", py_command.format(install_scheme, prefix)] c = vistir.misc.run( command, return_object=True, block=True, nospin=True, write_to_stdout=False diff --git a/pipenv/resolver.py b/pipenv/resolver.py index 20a0796f..1219cc24 100644 --- a/pipenv/resolver.py +++ b/pipenv/resolver.py @@ -97,6 +97,7 @@ class Entry(object): def __init__(self, name, entry_dict, project, resolver, reverse_deps=None, dev=False): super(Entry, self).__init__() + from pipenv.vendor.requirementslib.models.utils import tomlkit_value_to_python self.name = name if isinstance(entry_dict, dict): self.entry_dict = self.clean_initial_dict(entry_dict) @@ -106,7 +107,9 @@ class Entry(object): section = "develop" if dev else "default" pipfile_section = "dev-packages" if dev else "packages" self.dev = dev - self.pipfile = project.parsed_pipfile.get(pipfile_section, {}) + self.pipfile = tomlkit_value_to_python( + project.parsed_pipfile.get(pipfile_section, {}) + ) self.lockfile = project.lockfile_content.get(section, {}) self.pipfile_dict = self.pipfile.get(self.pipfile_name, {}) if self.dev and self.name in project.lockfile_content.get("default", {}): diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index d5dfecc1..38be0a57 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -375,14 +375,15 @@ def test_multiple_editable_packages_should_not_race(PipenvInstance, pypi, testsr @pytest.mark.outdated +@pytest.mark.py3_only def test_outdated_should_compare_postreleases_without_failing(PipenvInstance): with PipenvInstance(chdir=True) as p: - c = p.pipenv("install Shapely==1.6.4") + c = p.pipenv("install ibm-db-sa-py3==0.3.0") assert c.return_code == 0 c = p.pipenv("update --outdated") assert c.return_code == 0 assert "Skipped Update" in c.out - p._pipfile.update("shapely", "*") + p._pipfile.update("ibm-db-sa-py3", "*") c = p.pipenv("update --outdated") assert c.return_code != 0 assert "out-of-date" in c.out