From 7c460061af140a9e19a1b1a757272851f597b38b Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 24 Jan 2019 11:03:30 +0300 Subject: [PATCH] Prevent to uninstall stdlib and dev packages --- piptools/_compat/__init__.py | 2 ++ piptools/_compat/pip_compat.py | 2 ++ piptools/sync.py | 5 ++--- tests/test_sync.py | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/piptools/_compat/__init__.py b/piptools/_compat/__init__.py index 1fa380529..e4ac71711 100644 --- a/piptools/_compat/__init__.py +++ b/piptools/_compat/__init__.py @@ -29,4 +29,6 @@ PyPI, install_req_from_line, install_req_from_editable, + stdlib_pkgs, + DEV_PKGS, ) diff --git a/piptools/_compat/pip_compat.py b/piptools/_compat/pip_compat.py index 187c6ea12..82ccb8b60 100644 --- a/piptools/_compat/pip_compat.py +++ b/piptools/_compat/pip_compat.py @@ -36,6 +36,8 @@ def do_import(module_path, subimport=None, old_path=None): cmdoptions = do_import('cli.cmdoptions', old_path='cmdoptions') get_installed_distributions = do_import('utils.misc', 'get_installed_distributions', old_path='utils') PyPI = do_import('models.index', 'PyPI') +stdlib_pkgs = do_import('utils.compat', 'stdlib_pkgs', old_path='compat') +DEV_PKGS = do_import('commands.freeze', 'DEV_PKGS') # pip 18.1 has refactored InstallRequirement constructors use by pip-tools. if pkg_resources.parse_version(pip.__version__) < pkg_resources.parse_version('18.1'): diff --git a/piptools/sync.py b/piptools/sync.py index f4f1a23f8..619ada06d 100644 --- a/piptools/sync.py +++ b/piptools/sync.py @@ -4,6 +4,7 @@ import tempfile from subprocess import check_call +from piptools._compat import stdlib_pkgs, DEV_PKGS from . import click from .exceptions import IncompatibleRequirements, UnsupportedConstraint from .utils import flat_map, format_requirement, key_from_ireq, key_from_req, get_hashes_from_ireq @@ -14,9 +15,7 @@ 'pip-tools', 'pip-review', 'pkg-resources', - 'setuptools', - 'wheel', -] +] + list(stdlib_pkgs) + list(DEV_PKGS) def dependency_tree(installed_keys, root_key): diff --git a/tests/test_sync.py b/tests/test_sync.py index 72b1e046e..51d7efd69 100644 --- a/tests/test_sync.py +++ b/tests/test_sync.py @@ -111,7 +111,8 @@ def test_diff_should_uninstall(fake_dist): def test_diff_should_not_uninstall(fake_dist): ignored = ('pip==7.1.0', 'pip-tools==1.1.1', 'pip-review==1.1.1', - 'pkg-resources==0.0.0', 'setuptools==34.0.0', 'wheel==0.29.0') + 'pkg-resources==0.0.0', 'setuptools==34.0.0', 'wheel==0.29.0', + 'python==3.0', 'distribute==0.1', 'wsgiref==0.1', 'argparse==0.1') installed = [fake_dist(pkg) for pkg in ignored] reqs = []