From d89da7f03208077177ec42b9502d1c56b7f41460 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 17 Sep 2018 01:16:01 -0400 Subject: [PATCH 01/26] Add initial tests Signed-off-by: Dan Ryan --- tests/actions/__init__.py | 0 tests/actions/test_add.py | 20 ++++++++++++++++++++ tests/actions/test_clean.py | 18 ++++++++++++++++++ tests/actions/test_freeze.py | 21 +++++++++++++++++++++ tests/actions/test_init.py | 19 +++++++++++++++++++ tests/actions/test_install.py | 0 tests/actions/test_lock.py | 0 tests/actions/test_remove.py | 0 tests/actions/test_sync.py | 0 tests/actions/test_upgrade.py | 0 tests/cli/__init__.py | 0 tests/cli/test_add.py | 1 + tests/cli/test_clean.py | 0 tests/cli/test_freeze.py | 0 tests/cli/test_init.py | 1 + tests/cli/test_install.py | 0 tests/cli/test_lock.py | 0 tests/cli/test_remove.py | 0 tests/cli/test_sync.py | 0 tests/cli/test_upgrade.py | 0 tests/conftest.py | 21 +++++++++++++++++++++ tests/integration/__init__.py | 0 22 files changed, 101 insertions(+) create mode 100644 tests/actions/__init__.py create mode 100644 tests/actions/test_add.py create mode 100644 tests/actions/test_clean.py create mode 100644 tests/actions/test_freeze.py create mode 100644 tests/actions/test_init.py create mode 100644 tests/actions/test_install.py create mode 100644 tests/actions/test_lock.py create mode 100644 tests/actions/test_remove.py create mode 100644 tests/actions/test_sync.py create mode 100644 tests/actions/test_upgrade.py create mode 100644 tests/cli/__init__.py create mode 100644 tests/cli/test_add.py create mode 100644 tests/cli/test_clean.py create mode 100644 tests/cli/test_freeze.py create mode 100644 tests/cli/test_init.py create mode 100644 tests/cli/test_install.py create mode 100644 tests/cli/test_lock.py create mode 100644 tests/cli/test_remove.py create mode 100644 tests/cli/test_sync.py create mode 100644 tests/cli/test_upgrade.py create mode 100644 tests/conftest.py create mode 100644 tests/integration/__init__.py diff --git a/tests/actions/__init__.py b/tests/actions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/actions/test_add.py b/tests/actions/test_add.py new file mode 100644 index 0000000..e7cd883 --- /dev/null +++ b/tests/actions/test_add.py @@ -0,0 +1,20 @@ +# -*- coding=utf-8 -*- +import passa.actions.init +import passa.actions.add +import passa.cli.options +import passa.models.projects + + +def test_add_one(project_directory): + project = passa.cli.options.Project(project_directory.strpath) + retcode = passa.actions.add.add_packages(["pytz"], project=project) + assert not retcode + assert 'pytz' in project.lockfile.default + + +def test_add_one_with_deps(project_directory): + project = passa.cli.options.Project(project_directory.strpath) + retcode = passa.actions.add.add_packages(["requests"], project=project) + assert not retcode + assert 'requests' in project.lockfile.default + assert 'idna' in project.lockfile.default diff --git a/tests/actions/test_clean.py b/tests/actions/test_clean.py new file mode 100644 index 0000000..3062ef5 --- /dev/null +++ b/tests/actions/test_clean.py @@ -0,0 +1,18 @@ +# -*- coding=utf-8 -*- +from passa.actions.add import add_packages +from passa.cli.options import Project +import vistir + + +def test_clean_subset(project_directory): + with vistir.contextmanagers.cd(project_directory.strpath): + project = Project(project_directory.strpath) + retcode = add_packages(["requests"], project=project) + assert not retcode + packages = ["requests", "chardet", "certifi", "idna"] + assert all(pkg in project.lockfile.default for pkg in packages) + import passa.actions.clean + pass + # clean_retcode = passa.actions.clean.clean(project=project) + # assert not clean_retcode + # assert project.lockfile.default._data == {} diff --git a/tests/actions/test_freeze.py b/tests/actions/test_freeze.py new file mode 100644 index 0000000..53d34f9 --- /dev/null +++ b/tests/actions/test_freeze.py @@ -0,0 +1,21 @@ +# -*- coding=utf-8 -*- +import passa.actions.add +import passa.actions.freeze +import passa.cli.options +import passa.models.projects + + +def test_freeze(project_directory): + project = passa.cli.options.Project(project_directory.strpath) + retcode = passa.actions.add.add_packages(["requests"], project=project) + assert not retcode + packages = ["requests", "chardet", "certifi", "idna"] + assert all(pkg in project.lockfile.default for pkg in packages) + freeze_file = project_directory.join("requirements.txt") + freeze_retcode = passa.actions.freeze.freeze( + project=project, include_hashes=False, target=freeze_file.strpath + ) + assert not freeze_retcode + lines = [line.strip() for line in freeze_file.readlines() if line.strip() != ''] + for pkg in packages: + assert any(line.startswith(pkg) for line in lines) diff --git a/tests/actions/test_init.py b/tests/actions/test_init.py new file mode 100644 index 0000000..2f12530 --- /dev/null +++ b/tests/actions/test_init.py @@ -0,0 +1,19 @@ +# -*- coding=utf-8 -*- + +import pytest + +import passa.actions.init +import passa.cli.options + + +def test_init(tmpdir): + init_retcode = passa.actions.init.init_project(root=tmpdir.strpath) + assert init_retcode == 0 + project = passa.cli.options.Project(tmpdir.strpath) + assert project.pipfile.packages._data == {} + assert project.pipfile.dev_packages._data == {} + + +def test_init_exists(project_directory): + with pytest.raises(RuntimeError, match=r'.* is already a Pipfile project'): + passa.actions.init.init_project(root=project_directory.strpath) diff --git a/tests/actions/test_install.py b/tests/actions/test_install.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/actions/test_lock.py b/tests/actions/test_lock.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/actions/test_remove.py b/tests/actions/test_remove.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/actions/test_sync.py b/tests/actions/test_sync.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/actions/test_upgrade.py b/tests/actions/test_upgrade.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cli/__init__.py b/tests/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cli/test_add.py b/tests/cli/test_add.py new file mode 100644 index 0000000..a6bcbda --- /dev/null +++ b/tests/cli/test_add.py @@ -0,0 +1 @@ +# -*- coding=utf-8 -*- diff --git a/tests/cli/test_clean.py b/tests/cli/test_clean.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cli/test_freeze.py b/tests/cli/test_freeze.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cli/test_init.py b/tests/cli/test_init.py new file mode 100644 index 0000000..a6bcbda --- /dev/null +++ b/tests/cli/test_init.py @@ -0,0 +1 @@ +# -*- coding=utf-8 -*- diff --git a/tests/cli/test_install.py b/tests/cli/test_install.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cli/test_lock.py b/tests/cli/test_lock.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cli/test_remove.py b/tests/cli/test_remove.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cli/test_sync.py b/tests/cli/test_sync.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/cli/test_upgrade.py b/tests/cli/test_upgrade.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..577c942 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,21 @@ +# -*- coding=utf-8 -*- +import pytest + + +DEFAULT_PIPFILE_CONTENTS = """ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[packages] + +[dev-packages] +""".strip() + + +@pytest.fixture(scope="function") +def project_directory(tmpdir_factory): + project_dir = tmpdir_factory.mktemp("passa-project") + project_dir.join("Pipfile").write(DEFAULT_PIPFILE_CONTENTS) + return project_dir diff --git a/tests/integration/__init__.py b/tests/integration/__init__.py new file mode 100644 index 0000000..e69de29 From 901faf9c97f9f736fb25230c23166d93b7288e24 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 18 Sep 2018 05:23:23 -0400 Subject: [PATCH 02/26] Clean up options and add virtualenv module Signed-off-by: Dan Ryan --- src/passa/actions/add.py | 2 +- src/passa/actions/clean.py | 4 +- src/passa/actions/remove.py | 2 +- src/passa/cli/add.py | 7 +- src/passa/cli/clean.py | 9 +- src/passa/cli/options.py | 77 +++++++++-- src/passa/cli/remove.py | 6 +- src/passa/cli/sync.py | 4 +- src/passa/cli/upgrade.py | 4 +- src/passa/models/projects.py | 1 + src/passa/models/synchronizers.py | 85 ++++++++---- src/passa/models/virtualenv.py | 212 ++++++++++++++++++++++++++++++ 12 files changed, 364 insertions(+), 49 deletions(-) create mode 100644 src/passa/models/virtualenv.py diff --git a/src/passa/actions/add.py b/src/passa/actions/add.py index 6338466..3efc4dc 100644 --- a/src/passa/actions/add.py +++ b/src/passa/actions/add.py @@ -48,7 +48,7 @@ def add_packages(packages=[], editables=[], project=None, dev=False, sync=False, syncer = Synchronizer( project, default=default, develop=develop, - clean_unneeded=clean, + clean_unneeded=clean ) success = sync(syncer) if not success: diff --git a/src/passa/actions/clean.py b/src/passa/actions/clean.py index 3570e4d..8c6ae17 100644 --- a/src/passa/actions/clean.py +++ b/src/passa/actions/clean.py @@ -3,11 +3,11 @@ from __future__ import absolute_import, print_function, unicode_literals -def clean(project, dev=False): +def clean(project, default=True, dev=False, sync=True): from passa.models.synchronizers import Cleaner from passa.operations.sync import clean - cleaner = Cleaner(project, default=True, develop=dev) + cleaner = Cleaner(project, default=default, develop=dev, sync=sync) success = clean(cleaner) if not success: diff --git a/src/passa/actions/remove.py b/src/passa/actions/remove.py index 158f5e6..17ba1c7 100644 --- a/src/passa/actions/remove.py +++ b/src/passa/actions/remove.py @@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, unicode_literals -def remove(project=None, only="default", packages=[], clean=True): +def remove(project=None, only="default", packages=[], clean=True, sync=False): from passa.models.lockers import PinReuseLocker from passa.operations.lock import lock diff --git a/src/passa/cli/add.py b/src/passa/cli/add.py index d5596cd..2635b98 100644 --- a/src/passa/cli/add.py +++ b/src/passa/cli/add.py @@ -4,14 +4,14 @@ from ..actions.add import add_packages from ._base import BaseCommand -from .options import package_group +from .options import package_group, clean_group class Command(BaseCommand): name = "add" description = "Add packages to project." - arguments = [package_group] + arguments = [package_group, clean_group] def run(self, options): if not options.editables and not options.packages: @@ -20,7 +20,8 @@ def run(self, options): packages=options.packages, editables=options.editables, project=options.project, - dev=options.dev + dev=options.dev, + clean=options.clean ) diff --git a/src/passa/cli/clean.py b/src/passa/cli/clean.py index e23d5ee..a74d814 100644 --- a/src/passa/cli/clean.py +++ b/src/passa/cli/clean.py @@ -4,17 +4,20 @@ from ..actions.clean import clean from ._base import BaseCommand -from .options import dev, no_default +from .options import dev, no_default, sync_group class Command(BaseCommand): name = "clean" description = "Uninstall unlisted packages from the environment." - arguments = [dev, no_default] + arguments = [dev, no_default, sync_group] def run(self, options): - return clean(project=options.project, default=options.default, dev=options.dev) + return clean( + project=options.project, default=options.default, dev=options.dev, + sync=options.sync + ) if __name__ == "__main__": diff --git a/src/passa/cli/options.py b/src/passa/cli/options.py index da89a3b..07782db 100644 --- a/src/passa/cli/options.py +++ b/src/passa/cli/options.py @@ -2,12 +2,15 @@ from __future__ import absolute_import import argparse +import inspect import os import sys +import six import tomlkit.exceptions import passa.models.projects +import passa.models.virtualenv import vistir @@ -20,23 +23,67 @@ def __init__(self, root, *args, **kwargs): pipfile = root.joinpath("Pipfile") if not pipfile.is_file(): raise argparse.ArgumentError( - "{0!r} is not a Pipfile project".format(root), + project, "{0!r} is not a Pipfile project".format(root.as_posix()), ) + self.venv = self.get_venv(root) try: - super(Project, self).__init__(root.as_posix(), *args, **kwargs) + super(Project, self).__init__(root.as_posix(), env_prefix=self.venv.venv_dir, + *args, **kwargs) except tomlkit.exceptions.ParseError as e: raise argparse.ArgumentError( - "failed to parse Pipfile: {0!r}".format(str(e)), + project, "failed to parse Pipfile: {0!r}".format(str(e)), ) + def get_venv(self, root): + if 'VIRTUAL_ENV' in os.environ: + return passa.models.virtualenv.VirtualEnv(os.environ['VIRTUAL_ENV']) + return passa.models.virtualenv.VirtualEnv.from_project_path(root) + def __name__(self): return "Project Root" +class OptionMeta(type): + + @property + def action_map(self): + action_map = getattr(self, '_action_map', None) + if not action_map: + self.action_map = { + name.strip("_").replace("Action", ""): obj + for name, obj in inspect.getmembers(argparse) + if name.startswith('_') and name.endswith('Action') + } + return self._action_map + + @action_map.setter + def action_map(self, action_map): + self._action_map = action_map + + +@six.add_metaclass(OptionMeta) class Option(object): def __init__(self, *args, **kwargs): - self.args = args - self.kwargs = kwargs + self.args = list(args) + self.kwargs = kwargs.copy() + if "dest" not in kwargs and not args[0].startswith("-"): + dest = list(args).pop(0) + else: + dest = kwargs.pop("dest", args[0].lstrip("-").replace("-", "_")) + action = kwargs.pop("action", None) + if not action: + if 'const' in kwargs: + action = 'store_const' + else: + action = 'store' + self.action = self.get_option(action, args, dest, **kwargs) + + @classmethod + def get_option(cls, action, option_strings, dest, *args, **kwargs): + if action: + action = action.title().replace("_", "") + return cls.action_map[action](list(option_strings), dest, *args, **kwargs) + return def add_to_parser(self, parser): parser.add_argument(*self.args, **self.kwargs) @@ -46,7 +93,7 @@ def add_to_group(self, group): class ArgumentGroup(object): - def __init__(self, name, parser=None, is_mutually_exclusive=False, required=None, options=[]): + def __init__(self, name, parser=None, is_mutually_exclusive=False, required=False, options=[]): self.name = name self.options = options self.parser = parser @@ -65,6 +112,9 @@ def add_to_parser(self, parser): self.argument_group = group self.parser = parser + def add_to_group(self, group): + self.add_to_parser(group) + project = Option( "--project", metavar="project", default=os.getcwd(), type=Project, @@ -77,7 +127,7 @@ def add_to_parser(self, parser): ) python_version = Option( - "--py-version", "--python-version", "--requires-python", metavar="python-version", + "--py-version", "--python-version", "--requires-python", metavar="python_version", dest="python_version", default=PYTHON_VERSION, type=str, help="required minor python version for the project" ) @@ -102,6 +152,11 @@ def add_to_parser(self, parser): help="do not synchronize the environment", ) +sync = Option( + "--sync", dest="sync", action="store_true", help="synchronize the environment", + default=False +) + target = Option( "-t", "--target", default=None, help="file to export into (default is to print to stdout)" @@ -132,6 +187,10 @@ def add_to_parser(self, parser): help="do not remove packages not specified in Pipfile.lock", ) +clean = Option( + "--clean", dest="clean", action="store_true", default=False, + help="remove packages not specified in Pipfile.lock", +) dev_only = Option( "--dev", dest="only", action="store_const", const="dev", help="only try to modify [dev-packages]", @@ -149,5 +208,7 @@ def add_to_parser(self, parser): include_hashes_group = ArgumentGroup("include_hashes", is_mutually_exclusive=True, options=[include_hashes, no_include_hashes]) dev_group = ArgumentGroup("dev", is_mutually_exclusive="True", options=[dev_only, default_only]) -package_group = ArgumentGroup("packages", options=[packages, editable, dev, no_sync]) new_project_group = ArgumentGroup("new-project", options=[new_project, python_version]) +clean_group = ArgumentGroup("clean", is_mutually_exclusive=True, options=[clean, no_clean]) +sync_group = ArgumentGroup("sync", is_mutually_exclusive=True, options=[sync, no_sync]) +package_group = ArgumentGroup("packages", options=[packages, editable, dev, sync_group]) diff --git a/src/passa/cli/remove.py b/src/passa/cli/remove.py index 538acbf..041c195 100644 --- a/src/passa/cli/remove.py +++ b/src/passa/cli/remove.py @@ -4,18 +4,18 @@ from ..actions.remove import remove from ._base import BaseCommand -from .options import dev_group, no_clean, packages +from .options import dev_group, clean_group, sync_group, packages class Command(BaseCommand): name = "remove" description = "Remove packages from project." - arguments = [dev_group, no_clean, packages] + arguments = [dev_group, clean_group, sync_group, packages] def run(self, options): return remove(project=options.project, only=options.only, - packages=options.packages, clean=options.clean) + packages=options.packages, clean=options.clean, sync=options.sync) if __name__ == "__main__": diff --git a/src/passa/cli/sync.py b/src/passa/cli/sync.py index a09b784..9a31fe1 100644 --- a/src/passa/cli/sync.py +++ b/src/passa/cli/sync.py @@ -4,14 +4,14 @@ from ..actions.sync import sync from ._base import BaseCommand -from .options import dev, no_clean +from .options import dev, clean_group class Command(BaseCommand): name = "sync" description = "Install Pipfile.lock into the environment." - arguments = [dev, no_clean] + arguments = [dev, clean_group] def run(self, options): return sync(project=options.project, dev=options.dev, clean=options.clean) diff --git a/src/passa/cli/upgrade.py b/src/passa/cli/upgrade.py index cf7f502..c7696c2 100644 --- a/src/passa/cli/upgrade.py +++ b/src/passa/cli/upgrade.py @@ -3,14 +3,14 @@ from ..actions.upgrade import upgrade from ._base import BaseCommand -from .options import no_clean, no_sync, packages, strategy +from .options import clean_group, sync_group, packages, strategy class Command(BaseCommand): name = "upgrade" description = "Upgrade packages in project." - arguments = [packages, strategy, no_clean, no_sync] + arguments = [packages, strategy, clean_group, sync_group] def run(self, options): return upgrade(project=options.project, strategy=options.strategy, diff --git a/src/passa/models/projects.py b/src/passa/models/projects.py index f6e037d..7ff6f31 100644 --- a/src/passa/models/projects.py +++ b/src/passa/models/projects.py @@ -84,6 +84,7 @@ def dumps(self): class Project(object): root = attr.ib() + env_prefix = attr.ib(default=None) _p = attr.ib(init=False) _l = attr.ib(init=False) diff --git a/src/passa/models/synchronizers.py b/src/passa/models/synchronizers.py index bad4905..8fc3e0a 100644 --- a/src/passa/models/synchronizers.py +++ b/src/passa/models/synchronizers.py @@ -14,15 +14,19 @@ import packaging.version import requirementslib +from .virtualenv import VirtualEnv + from ..internals._pip import uninstall, EditableInstaller, WheelInstaller -def _is_installation_local(name): +def _is_installation_local(name, venv=None): """Check whether the distribution is in the current Python installation. This is used to distinguish packages seen by a virtual environment. A venv may be able to see global packages, but we don't want to mess with them. """ + if venv: + return venv.is_installed(name) loc = os.path.normcase(pkg_resources.working_set.by_key[name].location) pre = os.path.normcase(sys.prefix) return os.path.commonprefix([loc, pre]) == pre @@ -38,12 +42,14 @@ def _is_up_to_date(distro, version): ]) -def _group_installed_names(packages): +def _group_installed_names(packages, venv=None): """Group locally installed packages based on given specifications. `packages` is a name-package mapping that are used as baseline to determine how the installed package should be grouped. + `venv` is the virtual environment object of the virtualenv being installed into. + Returns a 3-tuple of disjoint sets, all containing names of installed packages: @@ -54,8 +60,13 @@ def _group_installed_names(packages): """ groupcoll = GroupCollection(set(), set(), set(), set()) - for distro in pkg_resources.working_set: - name = distro.key + if venv: + working_set = venv.get_working_set() + else: + working_set = pkg_resources.working_set + + for dist in working_set: + name = dist.key try: package = packages[name] except KeyError: @@ -66,7 +77,7 @@ def _group_installed_names(packages): if not r.is_named: # Always mark non-named. I think pip does something similar? groupcoll.outdated.add(name) - elif not _is_up_to_date(distro, r.get_version()): + elif not _is_up_to_date(dist, r.get_version()): groupcoll.outdated.add(name) else: groupcoll.uptodate.add(name) @@ -75,11 +86,14 @@ def _group_installed_names(packages): @contextlib.contextmanager -def _remove_package(name): - if name is None or not _is_installation_local(name): +def _remove_package(name, venv=None): + if name is None or not _is_installation_local(name, venv=venv): yield None return - with uninstall(name, auto_confirm=True, verbose=False) as uninstaller: + _uninstall = uninstall + if venv: + _uninstall = venv.uninstall + with _uninstall(name, auto_confirm=True, verbose=False) as uninstaller: yield uninstaller @@ -88,19 +102,22 @@ def _get_packages(lockfile, default, develop): # Extras don't matter because they only affect dependencies, and we # don't install dependencies anyway! packages = {} - if default: - packages.update(lockfile.default._data) if develop: packages.update(lockfile.develop._data) + if default: + packages.update(lockfile.default._data) return packages -def _build_paths(): +def _build_paths(venv=None): """Prepare paths for distlib.wheel.Wheel to install into. """ - paths = sysconfig.get_paths() + if venv: + paths = venv.paths + else: + paths = sysconfig.get_paths() return { - "prefix": sys.prefix, + "prefix": sys.prefix if not venv else venv.venv_dir.as_posix(), "data": paths["data"], "scripts": paths["scripts"], "headers": paths["include"], @@ -112,12 +129,12 @@ def _build_paths(): PROTECTED_FROM_CLEAN = {"setuptools", "pip", "wheel"} -def _clean(names): +def _clean(names, venv=None): cleaned = set() for name in names: if name in PROTECTED_FROM_CLEAN: continue - with _remove_package(name) as uninst: + with _remove_package(name, venv=venv) as uninst: if uninst: cleaned.add(name) return cleaned @@ -126,18 +143,34 @@ def _clean(names): class Synchronizer(object): """Helper class to install packages from a project's lock file. """ - def __init__(self, project, default, develop, clean_unneeded): + def __init__(self, project, default, develop, clean_unneeded, venv=None): self._root = project.root # Only for repr. self.packages = _get_packages(project.lockfile, default, develop) self.sources = project.lockfile.meta.sources._data - self.paths = _build_paths() self.clean_unneeded = clean_unneeded + if not venv: + self._venv = getattr(project, "venv", None) + else: + self._venv = venv + self.paths = _build_paths(venv=self.venv) + + @property + def venv(self): + if self._venv: + return self._venv + return self.project.venv def __repr__(self): return "<{0} @ {1!r}>".format(type(self).__name__, self._root) def sync(self): - groupcoll = _group_installed_names(self.packages) + if not self.venv: + return self._sync() + with self.venv.activated(): + return self._sync() + + def _sync(self): + groupcoll = _group_installed_names(self.packages, venv=self.venv) installed = set() updated = set() @@ -146,7 +179,7 @@ def sync(self): # TODO: Show a prompt to confirm cleaning. We will need to implement a # reporter pattern for this as well. if self.clean_unneeded: - names = _clean(groupcoll.unneeded) + names = _clean(groupcoll.unneeded, venv=self.venv) cleaned.update(names) # TODO: Specify installation order? (pypa/pipenv#2274) @@ -161,7 +194,7 @@ def sync(self): continue r.markers = None if r.editable: - installer = EditableInstaller(r) + installer = EditableInstaller(r, venv=self.venv) else: installer = WheelInstaller(r, self.sources, self.paths) try: @@ -181,7 +214,7 @@ def sync(self): else: name_to_remove = None try: - with _remove_package(name_to_remove): + with _remove_package(name_to_remove, venv=self.venv): installer.install() except Exception as e: if os.environ.get("PASSA_NO_SUPPRESS_EXCEPTIONS"): @@ -201,14 +234,18 @@ def sync(self): class Cleaner(object): """Helper class to clean packages not in a project's lock file. """ - def __init__(self, project, default, develop): + def __init__(self, project, default, develop, sync=True): self._root = project.root # Only for repr. self.packages = _get_packages(project.lockfile, default, develop) + self.sync = sync + self.project = project def __repr__(self): return "<{0} @ {1!r}>".format(type(self).__name__, self._root) def clean(self): - groupcoll = _group_installed_names(self.packages) - cleaned = _clean(groupcoll.unneeded) + groupcoll = _group_installed_names(self.packages, venv=self.project.venv) + cleaned = set() + if self.sync: + cleaned = _clean(groupcoll.unneeded, venv=self.project.venv) return cleaned diff --git a/src/passa/models/virtualenv.py b/src/passa/models/virtualenv.py new file mode 100644 index 0000000..78484c2 --- /dev/null +++ b/src/passa/models/virtualenv.py @@ -0,0 +1,212 @@ +# -*- coding=utf-8 -*- + +import base64 +import contextlib +import distlib.scripts +import hashlib +import importlib +import json +import os +import re +import sys +import sysconfig + +from cached_property import cached_property + +import vistir + +from ..internals._pip import RequirementUninstaller + + +class VirtualEnv(object): + def __init__(self, venv_dir): + self.venv_dir = vistir.compat.Path(venv_dir) + + @classmethod + def from_project_path(cls, path): + path = vistir.compat.Path(path) + if path.name == 'Pipfile': + pipfile_path = path + path = path.parent + else: + pipfile_path = path / 'Pipfile' + pipfile_location = cls.normalize_path(pipfile_path) + venv_path = path / '.venv' + if venv_path.exists(): + if not venv_path.is_dir(): + possible_path = vistir.compat.Path(venv_path.read_text().strip()) + if possible_path.exists(): + return cls(possible_path.as_posix()) + else: + if venv_path.joinpath('lib').exists(): + return cls(venv_path.as_posix()) + sanitized = re.sub(r'[ $`!*@"\\\r\n\t]', "_", path.name)[0:42] + hash_ = hashlib.sha256(pipfile_location.encode()).digest()[:6] + encoded_hash = base64.urlsafe_b64encode(hash_).decode() + hash_fragment = encoded_hash[:8] + venv_name = "{0}-{1}".format(sanitized, hash_fragment) + return cls(cls.get_workon_home().joinpath(venv_name).as_posix()) + + @classmethod + def normalize_path(cls, path): + if not path: + return + if not path.is_absolute(): + try: + path = path.resolve() + except OSError: + path = path.absolute() + path = vistir.path.unicode_path("{0}".format(path)) + if os.name != "nt": + return path + + drive, tail = os.path.splitdrive(path) + # Only match (lower cased) local drives (e.g. 'c:'), not UNC mounts. + if drive.islower() and len(drive) == 2 and drive[1] == ":": + path = "{}{}".format(drive.upper(), tail) + + return vistir.path.unicode_path(path) + + @classmethod + def get_workon_home(cls): + workon_home = os.environ.get("WORKON_HOME") + if not workon_home: + if os.name == "nt": + workon_home = "~/.virtualenvs" + else: + workon_home = os.path.join( + os.environ.get("XDG_DATA_HOME", "~/.local/share"), "virtualenvs" + ) + return vistir.compat.Path(os.path.expandvars(workon_home)).expanduser() + + @cached_property + def script_basedir(self): + script_dir = os.path.basename(sysconfig.get_paths()["scripts"]) + return script_dir + + @property + def python(self): + return self.venv_dir.joinpath(self.script_basedir).joinpath("python").as_posix() + + @cached_property + def sys_path(self): + c = vistir.misc.run([self.python, "-c", "import json,sys; print(json.dumps(sys.path))"], + return_object=True, nospin=True) + assert c.returncode == 0, "failed loading virtualenv path" + path = json.loads(c.out.strip()) + return path + + @cached_property + def paths(self): + paths = {} + with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): + os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) + os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") + os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") + importlib.reload(sysconfig) + scheme, _, _ = sysconfig._get_default_scheme().partition('_') + scheme = "{0}_user".format(scheme) + paths = sysconfig.get_paths(scheme=scheme) + return paths + + @property + def scripts_dir(self): + return self.paths["scripts"] + + @cached_property + def passa_entry(self): + import pkg_resources + return pkg_resources.working_set.by_key['passa'].location + + def get_distributions(self): + import pkg_resources + importlib.reload(pkg_resources) + return pkg_resources.find_distributions(self.paths["purelib"], only=True) + + def get_working_set(self): + working_set = None + import pkg_resources + passa_entry = self.passa_entry + with self.activated(): + working_set = pkg_resources.WorkingSet(self.sys_path + [passa_entry,]) + return working_set + + @classmethod + def filter_sources(cls, requirement, sources): + if not sources or not requirement.index: + return sources + filtered_sources = [ + source for source in sources + if source.get("name") == requirement.index + ] + return filtered_sources or sources + + def install(self, req, editable=False, sources=[]): + with self.activated(): + import passa.internals._pip_shims + importlib.reload(passa.internals._pip_shms) + ireq = req.as_ireq() + if editable: + with vistir.contextmanagers.cd(ireq.setup_py_dir): + c = self.run([self.python, "setup.py", "develop", "--no-deps"], cwd=ireq.setup_py_dir) + return c.returncode + importlib.reload(distlib.scripts) + sources = self.filter_sources(req, sources) + hashes = req.hashes + wheel = passa.internals._pip_shims.build_wheel(ireq, sources, hashes) + wheel.install(self.paths, distlib.scripts.ScriptMaker(None, None)) + + @contextlib.contextmanager + def activated(self): + original_path = sys.path + original_prefix = sys.prefix + original_user_base = os.environ.get("PYTHONUSERBASE", None) + original_venv = os.environ.get("VIRTUAL_ENV", None) + passa_path = vistir.compat.Path(__file__).absolute().parent.parent.as_posix() + with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): + os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) + os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") + os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") + os.environ["VIRTUAL_ENV"] = vistir.compat.fs_str(self.venv_dir.as_posix()) + sys.path = self.sys_path + sys.prefix = self.venv_dir + sys.path.append(passa_path) + activate_this = os.path.join(self.scripts_dir, "activate_this.py") + with open(activate_this, "r") as f: + code = compile(f.read(), activate_this, "exec") + exec(code, dict(__file__=activate_this)) + try: + yield + finally: + print("Deactivating virtualenv...") + del os.environ["VIRTUAL_ENV"] + del os.environ["PYTHONUSERBASE"] + if original_user_base: + os.environ["PYTHONUSERBASE"] = original_user_base + if original_venv: + os.environ["VIRTUAL_ENV"] = original_venv + sys.path = original_path + sys.prefix = original_prefix + + def run(self, cmd, cwd=os.curdir): + c = None + with self.activated(): + script = vistir.cmdparse.Script.parse(cmd) + c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) + return c + + def is_installed(self, pkgname): + return any(d for d in self.get_distributions() if d.project_name == pkgname) + + def uninstall(self, pkgname, *args, **kwargs): + with self.activated(): + from pip_shims.shims import InstallRequirement + module_name = InstallRequirement.__module__ + del InstallRequirement + if module_name not in sys.modules: + pip_req_install = importlib.import_module(module_name) + else: + pip_req_install = sys.modules[module_name] + importlib.reload(sys.modules[module_name]) + ireq = pip_req_install.InstallRequirement.from_line(pkgname) + return RequirementUninstaller(ireq, *args, **kwargs) From 89325f50b4186d8757192b5ef5c960754920e4b2 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 18 Sep 2018 05:23:46 -0400 Subject: [PATCH 03/26] Add tests (clean is still failing) Signed-off-by: Dan Ryan --- tests/actions/test_clean.py | 30 ++++++++++++++--------------- tests/conftest.py | 38 ++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/tests/actions/test_clean.py b/tests/actions/test_clean.py index 3062ef5..95b0b14 100644 --- a/tests/actions/test_clean.py +++ b/tests/actions/test_clean.py @@ -1,18 +1,18 @@ # -*- coding=utf-8 -*- -from passa.actions.add import add_packages -from passa.cli.options import Project -import vistir -def test_clean_subset(project_directory): - with vistir.contextmanagers.cd(project_directory.strpath): - project = Project(project_directory.strpath) - retcode = add_packages(["requests"], project=project) - assert not retcode - packages = ["requests", "chardet", "certifi", "idna"] - assert all(pkg in project.lockfile.default for pkg in packages) - import passa.actions.clean - pass - # clean_retcode = passa.actions.clean.clean(project=project) - # assert not clean_retcode - # assert project.lockfile.default._data == {} +def test_clean_subset(project): + from passa.actions.add import add_packages + from passa.actions.clean import clean + retcode = add_packages(["requests"], project=project) + assert not retcode + packages = ["requests", "chardet", "certifi", "idna"] + c = project.venv.run("pip install pytz") + assert c.returncode == 0 + c = project.venv.run("python -c 'import pytz'") + assert c.returncode == 0 + clean_retcode = clean(project=project) + assert not clean_retcode + c = project.venv.run("python -c 'import pytz'") + assert c.returncode != 0 + assert all(pkg in project.lockfile.default for pkg in packages) diff --git a/tests/conftest.py b/tests/conftest.py index 577c942..e1326ca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,10 @@ # -*- coding=utf-8 -*- +import os import pytest +import passa.cli.options +import passa.models.virtualenv +import sys +import vistir DEFAULT_PIPFILE_CONTENTS = """ @@ -18,4 +23,35 @@ def project_directory(tmpdir_factory): project_dir = tmpdir_factory.mktemp("passa-project") project_dir.join("Pipfile").write(DEFAULT_PIPFILE_CONTENTS) - return project_dir + with vistir.contextmanagers.cd(project_dir.strpath): + yield project_dir + + +@pytest.fixture(scope="function") +def virtualenv(tmpdir_factory): + venv_dir = tmpdir_factory.mktemp("passa-testenv") + print("Creating virtualenv {0!r}".format(venv_dir.strpath)) + c = vistir.misc.run([sys.executable, "-m", "virtualenv", venv_dir.strpath], + return_object=True, block=True, nospin=True) + if c.returncode == 0: + print("Virtualenv created...") + return venv_dir + raise RuntimeError("Failed creating virtualenv for testing...{0!r}".format(c.err.strip())) + + +class _Project(passa.cli.options.Project): + def __init__(self, root, venv=None): + self.path = os.path.abspath(root) + self.venv = venv + super(_Project, self).__init__(self.path) + + +@pytest.fixture +def tmpvenv(virtualenv): + return passa.models.virtualenv.VirtualEnv(virtualenv) + + +@pytest.fixture(scope="function") +def project(project_directory, tmpvenv): + with tmpvenv.activated(): + yield _Project(project_directory, tmpvenv) From fec65fc68f21628faf49b239e426bd2380b5d0db Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 18 Sep 2018 18:32:56 -0400 Subject: [PATCH 04/26] Wheel installation into virtualenv works Signed-off-by: Dan Ryan --- src/passa/models/virtualenv.py | 69 +++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/src/passa/models/virtualenv.py b/src/passa/models/virtualenv.py index 78484c2..54d5682 100644 --- a/src/passa/models/virtualenv.py +++ b/src/passa/models/virtualenv.py @@ -8,6 +8,7 @@ import json import os import re +import six import sys import sysconfig @@ -96,6 +97,19 @@ def sys_path(self): path = json.loads(c.out.strip()) return path + @cached_property + def system_paths(self): + paths = {} + importlib.reload(sysconfig) + paths = sysconfig.get_paths() + return paths + + @cached_property + def sys_prefix(self): + c = self.run_py(["-c", "'import sys; print(sys.prefix)'"]) + sys_prefix = vistir.misc.to_text(c.out).strip() + return sys_prefix + @cached_property def paths(self): paths = {} @@ -141,19 +155,45 @@ def filter_sources(cls, requirement, sources): ] return filtered_sources or sources + @cached_property + def python_version(self): + with self.activated(): + importlib.reload(sysconfig) + py_version = sysconfig.get_python_version() + return py_version + + def get_setup_install_args(self, pkgname, setup_py, develop=False): + headers = vistir.compat.Path(self.sys_prefix) / "include" / "site" + headers = headers / "python{0}".format(self.python_version) / pkgname + install_arg = "install" if not develop else "develop" + return [ + self.python, "-u", "-c", SETUPTOOLS_SHIM % setup_py, install_arg, + "--single-version-externally-managed", "root={0}".format(), + "--install-headers={0}".format(headers.as_posix()), + "--install-purelib={0}".format(self.paths["purelib"]), + "--install-platlib={0}".format(self.paths["platlib"]), + "--install-scripts={0}".format(self.scripts_dir), + "--install-data={0}".format(self.paths["data"]), + ] + def install(self, req, editable=False, sources=[]): with self.activated(): - import passa.internals._pip_shims - importlib.reload(passa.internals._pip_shms) + import passa.internals._pip + install_options = ["--prefix={0}".format(self.venv_dir),] + importlib.reload(passa.internals._pip) ireq = req.as_ireq() if editable: - with vistir.contextmanagers.cd(ireq.setup_py_dir): - c = self.run([self.python, "setup.py", "develop", "--no-deps"], cwd=ireq.setup_py_dir) + with vistir.contextmanagers.cd(ireq.setup_py_dir, ireq.setup_py): + c = self.run( + install_options + self.get_setup_install_args( + req.name, develop=editable + ), cwd=ireq.setup_py_dir + ) return c.returncode importlib.reload(distlib.scripts) sources = self.filter_sources(req, sources) hashes = req.hashes - wheel = passa.internals._pip_shims.build_wheel(ireq, sources, hashes) + wheel = passa.internals._pip.build_wheel(ireq, sources, hashes) wheel.install(self.paths, distlib.scripts.ScriptMaker(None, None)) @contextlib.contextmanager @@ -195,6 +235,16 @@ def run(self, cmd, cwd=os.curdir): c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) return c + def run_py(self, cmd, cwd=os.curdir): + c = None + if isinstance(cmd, six.string_types): + script = vistir.cmdparse.Script.parse("{0} {1}".format(self.python, cmd)) + else: + script = vistir.cmdparse.Script.parse([self.python,] + list(cmd)) + with self.activated(): + c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) + return c + def is_installed(self, pkgname): return any(d for d in self.get_distributions() if d.project_name == pkgname) @@ -210,3 +260,12 @@ def uninstall(self, pkgname, *args, **kwargs): importlib.reload(sys.modules[module_name]) ireq = pip_req_install.InstallRequirement.from_line(pkgname) return RequirementUninstaller(ireq, *args, **kwargs) + + +SETUPTOOLS_SHIM = ( + "import setuptools, tokenize;__file__=%r;" + "f=getattr(tokenize, 'open', open)(__file__);" + "code=f.read().replace('\\r\\n', '\\n');" + "f.close();" + "exec(compile(code, __file__, 'exec'))" +) From da3afc67b5bdf14b41d005d18b7b76ac02b30f2d Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 18 Sep 2018 18:33:15 -0400 Subject: [PATCH 05/26] Update setup.cfg Signed-off-by: Dan Ryan --- setup.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.cfg b/setup.cfg index 98ea198..4daf9ee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,6 +45,7 @@ install_requires = resolvelib>=0.2.1,!=1.0.0.dev0 requirementslib>=1.1.1 six + virtualenv vistir[spinner]>=0.1.4 [options.extras_require] @@ -52,6 +53,7 @@ pack = invoke parver tests = + cached-property pytest-xdist pytest-timeout pytest-cov From 258d51e2a44b7942ad8680e09aea7fc30f81cc70 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Wed, 19 Sep 2018 01:19:33 -0400 Subject: [PATCH 06/26] Implement working versions of clean and install inside virtualenvs Signed-off-by: Dan Ryan --- src/passa/models/synchronizers.py | 2 +- src/passa/models/virtualenv.py | 91 ++++++++++++++++++++++++------- 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/src/passa/models/synchronizers.py b/src/passa/models/synchronizers.py index 8fc3e0a..33fcfc3 100644 --- a/src/passa/models/synchronizers.py +++ b/src/passa/models/synchronizers.py @@ -135,7 +135,7 @@ def _clean(names, venv=None): if name in PROTECTED_FROM_CLEAN: continue with _remove_package(name, venv=venv) as uninst: - if uninst: + if uninst.paths: cleaned.add(name) return cleaned diff --git a/src/passa/models/virtualenv.py b/src/passa/models/virtualenv.py index 54d5682..c179e3c 100644 --- a/src/passa/models/virtualenv.py +++ b/src/passa/models/virtualenv.py @@ -12,12 +12,11 @@ import sys import sysconfig +import passa.internals._pip from cached_property import cached_property import vistir -from ..internals._pip import RequirementUninstaller - class VirtualEnv(object): def __init__(self, venv_dir): @@ -100,7 +99,7 @@ def sys_path(self): @cached_property def system_paths(self): paths = {} - importlib.reload(sysconfig) + six.moves.reload_module(sysconfig) paths = sysconfig.get_paths() return paths @@ -117,7 +116,7 @@ def paths(self): os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") - importlib.reload(sysconfig) + six.moves.reload_module(sysconfig) scheme, _, _ = sysconfig._get_default_scheme().partition('_') scheme = "{0}_user".format(scheme) paths = sysconfig.get_paths(scheme=scheme) @@ -134,15 +133,15 @@ def passa_entry(self): def get_distributions(self): import pkg_resources - importlib.reload(pkg_resources) + six.moves.reload_module(pkg_resources) return pkg_resources.find_distributions(self.paths["purelib"], only=True) def get_working_set(self): working_set = None import pkg_resources passa_entry = self.passa_entry - with self.activated(): - working_set = pkg_resources.WorkingSet(self.sys_path + [passa_entry,]) + monkeypatch = self.monkeypatch_dist + working_set = pkg_resources.WorkingSet(self.sys_path + [passa_entry, monkeypatch]) return working_set @classmethod @@ -158,10 +157,26 @@ def filter_sources(cls, requirement, sources): @cached_property def python_version(self): with self.activated(): - importlib.reload(sysconfig) + six.moves.reload_module(sysconfig) py_version = sysconfig.get_python_version() return py_version + @classmethod + def safe_import(cls, name): + module = None + if name not in sys.modules: + module = importlib.import_module(name) + else: + module = sys.modules[name] + six.moves.reload_module(module) + return module + + @cached_property + def monkeypatch_dist(self): + pkg_resources = self.safe_import("pkg_resources") + monkey_patch = pkg_resources.get_distribution('recursive-monkey-patch').location + return monkey_patch + def get_setup_install_args(self, pkgname, setup_py, develop=False): headers = vistir.compat.Path(self.sys_prefix) / "include" / "site" headers = headers / "python{0}".format(self.python_version) / pkgname @@ -178,9 +193,8 @@ def get_setup_install_args(self, pkgname, setup_py, develop=False): def install(self, req, editable=False, sources=[]): with self.activated(): - import passa.internals._pip install_options = ["--prefix={0}".format(self.venv_dir),] - importlib.reload(passa.internals._pip) + six.moves.reload_module(passa.internals._pip) ireq = req.as_ireq() if editable: with vistir.contextmanagers.cd(ireq.setup_py_dir, ireq.setup_py): @@ -190,7 +204,7 @@ def install(self, req, editable=False, sources=[]): ), cwd=ireq.setup_py_dir ) return c.returncode - importlib.reload(distlib.scripts) + six.moves.reload_module(distlib.scripts) sources = self.filter_sources(req, sources) hashes = req.hashes wheel = passa.internals._pip.build_wheel(ireq, sources, hashes) @@ -203,6 +217,7 @@ def activated(self): original_user_base = os.environ.get("PYTHONUSERBASE", None) original_venv = os.environ.get("VIRTUAL_ENV", None) passa_path = vistir.compat.Path(__file__).absolute().parent.parent.as_posix() + monkeypatch_dist = self.monkeypatch_dist with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") @@ -210,11 +225,15 @@ def activated(self): os.environ["VIRTUAL_ENV"] = vistir.compat.fs_str(self.venv_dir.as_posix()) sys.path = self.sys_path sys.prefix = self.venv_dir - sys.path.append(passa_path) + import site + # sys.path.append(passa_path) activate_this = os.path.join(self.scripts_dir, "activate_this.py") with open(activate_this, "r") as f: code = compile(f.read(), activate_this, "exec") exec(code, dict(__file__=activate_this)) + site.addsitedir(passa_path) + site.addsitedir(monkeypatch_dist) + pkg_resources = self.safe_import("pkg_resources") try: yield finally: @@ -227,6 +246,7 @@ def activated(self): os.environ["VIRTUAL_ENV"] = original_venv sys.path = original_path sys.prefix = original_prefix + six.moves.reload_module(pkg_resources) def run(self, cmd, cwd=os.curdir): c = None @@ -248,18 +268,42 @@ def run_py(self, cmd, cwd=os.curdir): def is_installed(self, pkgname): return any(d for d in self.get_distributions() if d.project_name == pkgname) + def get_monkeypatched_pathset(self): + import recursive_monkey_patch + from pip_shims.shims import req_install + req_uninstall_name = "{0}.req_uninstall".format(req_install.__package__) + if req_uninstall_name not in sys.modules: + req_uninstall = importlib.import_module(req_uninstall_name) + else: + req_uninstall = sys.modules[req_uninstall_name] + six.moves.reload_module(req_uninstall) + recursive_monkey_patch.monkey_patch(PatchedUninstaller, req_uninstall.UninstallPathSet) + return req_uninstall.UninstallPathSet + + @contextlib.contextmanager def uninstall(self, pkgname, *args, **kwargs): + auto_confirm = kwargs.pop("auto_confirm", True) + verbose = kwargs.pop("verbose", False) with self.activated(): - from pip_shims.shims import InstallRequirement - module_name = InstallRequirement.__module__ - del InstallRequirement - if module_name not in sys.modules: - pip_req_install = importlib.import_module(module_name) + pathset_base = self.get_monkeypatched_pathset() + dist = next( + iter(filter(lambda d: d.project_name == pkgname, self.get_working_set())), + None + ) + pathset = pathset_base.from_dist(dist) + print(pathset.paths) + if pathset is not None: + pathset.remove(auto_confirm=auto_confirm, verbose=True) + try: + yield pathset + except Exception as e: + if pathset is not None: + pathset.rollback() else: - pip_req_install = sys.modules[module_name] - importlib.reload(sys.modules[module_name]) - ireq = pip_req_install.InstallRequirement.from_line(pkgname) - return RequirementUninstaller(ireq, *args, **kwargs) + if pathset is not None: + pathset.commit() + if pathset is None: + return SETUPTOOLS_SHIM = ( @@ -269,3 +313,8 @@ def uninstall(self, pkgname, *args, **kwargs): "f.close();" "exec(compile(code, __file__, 'exec'))" ) + + +class PatchedUninstaller(object): + def _permitted(self, path): + return True From 9262a4debe95a0bf11284e8c69925fb16b70ac32 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Thu, 20 Sep 2018 01:15:03 -0400 Subject: [PATCH 07/26] Fix cleaning working set and messaging Signed-off-by: Dan Ryan --- src/passa/actions/clean.py | 3 +- src/passa/actions/init.py | 2 +- src/passa/models/synchronizers.py | 11 +++- src/passa/models/virtualenv.py | 103 ++++++++++++++---------------- src/passa/operations/sync.py | 4 +- 5 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/passa/actions/clean.py b/src/passa/actions/clean.py index 8c6ae17..9006f22 100644 --- a/src/passa/actions/clean.py +++ b/src/passa/actions/clean.py @@ -13,4 +13,5 @@ def clean(project, default=True, dev=False, sync=True): if not success: return 1 - print("Cleaned project at", project.root) + if sync: + print("Cleaned project at", project.root) diff --git a/src/passa/actions/init.py b/src/passa/actions/init.py index 1d9f592..bbab009 100644 --- a/src/passa/actions/init.py +++ b/src/passa/actions/init.py @@ -42,7 +42,7 @@ def init_project(root=None, python_version=None): index_urls = [parsed.index_url] + parsed.extra_index_urls sources = get_sources(index_urls, parsed.trusted_hosts) data = { - "sources": sources, + "source": sources, "packages": {}, "dev-packages": {}, } diff --git a/src/passa/models/synchronizers.py b/src/passa/models/synchronizers.py index 33fcfc3..9c8aa9c 100644 --- a/src/passa/models/synchronizers.py +++ b/src/passa/models/synchronizers.py @@ -234,7 +234,7 @@ def _sync(self): class Cleaner(object): """Helper class to clean packages not in a project's lock file. """ - def __init__(self, project, default, develop, sync=True): + def __init__(self, project, default, develop, sync=True, verbose=False): self._root = project.root # Only for repr. self.packages = _get_packages(project.lockfile, default, develop) self.sync = sync @@ -243,9 +243,18 @@ def __init__(self, project, default, develop, sync=True): def __repr__(self): return "<{0} @ {1!r}>".format(type(self).__name__, self._root) + def print(self, packages): + if not self.sync: + message = "Would clean: {0}" + else: + message = "Cleaned: {0}" + print(message.format(", ".join(sorted(set(packages))))) + def clean(self): groupcoll = _group_installed_names(self.packages, venv=self.project.venv) cleaned = set() if self.sync: cleaned = _clean(groupcoll.unneeded, venv=self.project.venv) + else: + return groupcoll.unneeded return cleaned diff --git a/src/passa/models/virtualenv.py b/src/passa/models/virtualenv.py index c179e3c..a4f3954 100644 --- a/src/passa/models/virtualenv.py +++ b/src/passa/models/virtualenv.py @@ -6,6 +6,7 @@ import hashlib import importlib import json +import posixpath import os import re import six @@ -20,6 +21,7 @@ class VirtualEnv(object): def __init__(self, venv_dir): + self.recursive_monkey_patch = self.safe_import("recursive_monkey_patch") self.venv_dir = vistir.compat.Path(venv_dir) @classmethod @@ -79,6 +81,26 @@ def get_workon_home(cls): ) return vistir.compat.Path(os.path.expandvars(workon_home)).expanduser() + @classmethod + def filter_sources(cls, requirement, sources): + if not sources or not requirement.index: + return sources + filtered_sources = [ + source for source in sources + if source.get("name") == requirement.index + ] + return filtered_sources or sources + + @classmethod + def safe_import(cls, name): + module = None + if name not in sys.modules: + module = importlib.import_module(name) + else: + module = sys.modules[name] + six.moves.reload_module(module) + return module + @cached_property def script_basedir(self): script_dir = os.path.basename(sysconfig.get_paths()["scripts"]) @@ -93,13 +115,16 @@ def sys_path(self): c = vistir.misc.run([self.python, "-c", "import json,sys; print(json.dumps(sys.path))"], return_object=True, nospin=True) assert c.returncode == 0, "failed loading virtualenv path" - path = json.loads(c.out.strip()) + path = [ + path for path in json.loads(c.out.strip()) + if posixpath.normpath(path).startswith(posixpath.normpath(str(self.venv_dir))) + ] return path @cached_property def system_paths(self): paths = {} - six.moves.reload_module(sysconfig) + sysconfig = self.safe_import("sysconfig") paths = sysconfig.get_paths() return paths @@ -116,7 +141,7 @@ def paths(self): os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") - six.moves.reload_module(sysconfig) + sysconfig = self.safe_import("sysconfig") scheme, _, _ = sysconfig._get_default_scheme().partition('_') scheme = "{0}_user".format(scheme) paths = sysconfig.get_paths(scheme=scheme) @@ -128,55 +153,27 @@ def scripts_dir(self): @cached_property def passa_entry(self): - import pkg_resources + pkg_resources = self.safe_import("pkg_resources") return pkg_resources.working_set.by_key['passa'].location def get_distributions(self): - import pkg_resources - six.moves.reload_module(pkg_resources) + pkg_resources = self.safe_import("pkg_resources") return pkg_resources.find_distributions(self.paths["purelib"], only=True) def get_working_set(self): working_set = None import pkg_resources passa_entry = self.passa_entry - monkeypatch = self.monkeypatch_dist - working_set = pkg_resources.WorkingSet(self.sys_path + [passa_entry, monkeypatch]) + working_set = pkg_resources.WorkingSet(self.sys_path + [passa_entry]) return working_set - @classmethod - def filter_sources(cls, requirement, sources): - if not sources or not requirement.index: - return sources - filtered_sources = [ - source for source in sources - if source.get("name") == requirement.index - ] - return filtered_sources or sources - @cached_property def python_version(self): with self.activated(): - six.moves.reload_module(sysconfig) + sysconfig = self.safe_import("sysconfig") py_version = sysconfig.get_python_version() return py_version - @classmethod - def safe_import(cls, name): - module = None - if name not in sys.modules: - module = importlib.import_module(name) - else: - module = sys.modules[name] - six.moves.reload_module(module) - return module - - @cached_property - def monkeypatch_dist(self): - pkg_resources = self.safe_import("pkg_resources") - monkey_patch = pkg_resources.get_distribution('recursive-monkey-patch').location - return monkey_patch - def get_setup_install_args(self, pkgname, setup_py, develop=False): headers = vistir.compat.Path(self.sys_prefix) / "include" / "site" headers = headers / "python{0}".format(self.python_version) / pkgname @@ -194,7 +191,7 @@ def get_setup_install_args(self, pkgname, setup_py, develop=False): def install(self, req, editable=False, sources=[]): with self.activated(): install_options = ["--prefix={0}".format(self.venv_dir),] - six.moves.reload_module(passa.internals._pip) + passa_pip = self.safe_import("passa.internals._pip") ireq = req.as_ireq() if editable: with vistir.contextmanagers.cd(ireq.setup_py_dir, ireq.setup_py): @@ -204,11 +201,11 @@ def install(self, req, editable=False, sources=[]): ), cwd=ireq.setup_py_dir ) return c.returncode - six.moves.reload_module(distlib.scripts) + distlib_scripts = self.safe_import("distlib.scripts") sources = self.filter_sources(req, sources) hashes = req.hashes - wheel = passa.internals._pip.build_wheel(ireq, sources, hashes) - wheel.install(self.paths, distlib.scripts.ScriptMaker(None, None)) + wheel = passa_pip.build_wheel(ireq, sources, hashes) + wheel.install(self.paths, distlib_scripts.ScriptMaker(None, None)) @contextlib.contextmanager def activated(self): @@ -217,22 +214,20 @@ def activated(self): original_user_base = os.environ.get("PYTHONUSERBASE", None) original_venv = os.environ.get("VIRTUAL_ENV", None) passa_path = vistir.compat.Path(__file__).absolute().parent.parent.as_posix() - monkeypatch_dist = self.monkeypatch_dist with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): - os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") - os.environ["VIRTUAL_ENV"] = vistir.compat.fs_str(self.venv_dir.as_posix()) - sys.path = self.sys_path - sys.prefix = self.venv_dir - import site - # sys.path.append(passa_path) activate_this = os.path.join(self.scripts_dir, "activate_this.py") with open(activate_this, "r") as f: code = compile(f.read(), activate_this, "exec") exec(code, dict(__file__=activate_this)) + os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) + os.environ["VIRTUAL_ENV"] = vistir.compat.fs_str(self.venv_dir.as_posix()) + sys.path = self.sys_path + sys.prefix = self.venv_dir + site = self.safe_import("site") site.addsitedir(passa_path) - site.addsitedir(monkeypatch_dist) + sys.modules["recursive_monkey_patch"] = self.recursive_monkey_patch pkg_resources = self.safe_import("pkg_resources") try: yield @@ -269,15 +264,12 @@ def is_installed(self, pkgname): return any(d for d in self.get_distributions() if d.project_name == pkgname) def get_monkeypatched_pathset(self): - import recursive_monkey_patch from pip_shims.shims import req_install req_uninstall_name = "{0}.req_uninstall".format(req_install.__package__) - if req_uninstall_name not in sys.modules: - req_uninstall = importlib.import_module(req_uninstall_name) - else: - req_uninstall = sys.modules[req_uninstall_name] - six.moves.reload_module(req_uninstall) - recursive_monkey_patch.monkey_patch(PatchedUninstaller, req_uninstall.UninstallPathSet) + req_uninstall = self.safe_import(req_uninstall_name) + self.recursive_monkey_patch.monkey_patch( + PatchedUninstaller, req_uninstall.UninstallPathSet + ) return req_uninstall.UninstallPathSet @contextlib.contextmanager @@ -291,9 +283,8 @@ def uninstall(self, pkgname, *args, **kwargs): None ) pathset = pathset_base.from_dist(dist) - print(pathset.paths) if pathset is not None: - pathset.remove(auto_confirm=auto_confirm, verbose=True) + pathset.remove(auto_confirm=auto_confirm, verbose=verbose) try: yield pathset except Exception as e: diff --git a/src/passa/operations/sync.py b/src/passa/operations/sync.py index 3014e8d..45502a4 100644 --- a/src/passa/operations/sync.py +++ b/src/passa/operations/sync.py @@ -16,8 +16,8 @@ def sync(syncer): def clean(cleaner): - print("Cleaning") + print("Cleaning...") cleaned = cleaner.clean() if cleaned: - print("Uninstalled: {}".format(", ".join(sorted(cleaned)))) + cleaner.print(cleaned) return True From 575b6d73433921f04e46fccdef3914650794d774 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Thu, 27 Sep 2018 19:52:41 -0400 Subject: [PATCH 08/26] Fix tests Signed-off-by: Dan Ryan --- tests/actions/test_clean.py | 8 ++++---- tests/conftest.py | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/actions/test_clean.py b/tests/actions/test_clean.py index 95b0b14..c56d06d 100644 --- a/tests/actions/test_clean.py +++ b/tests/actions/test_clean.py @@ -1,17 +1,17 @@ # -*- coding=utf-8 -*- +import passa.actions.add +import passa.actions.clean def test_clean_subset(project): - from passa.actions.add import add_packages - from passa.actions.clean import clean - retcode = add_packages(["requests"], project=project) + retcode = passa.actions.add.add_packages(["requests"], project=project) assert not retcode packages = ["requests", "chardet", "certifi", "idna"] c = project.venv.run("pip install pytz") assert c.returncode == 0 c = project.venv.run("python -c 'import pytz'") assert c.returncode == 0 - clean_retcode = clean(project=project) + clean_retcode = passa.actions.clean.clean(project=project) assert not clean_retcode c = project.venv.run("python -c 'import pytz'") assert c.returncode != 0 diff --git a/tests/conftest.py b/tests/conftest.py index e1326ca..1aaf419 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,9 @@ # -*- coding=utf-8 -*- import os import pytest +import passa import passa.cli.options -import passa.models.virtualenv +import mork.virtualenv import sys import vistir @@ -41,17 +42,20 @@ def virtualenv(tmpdir_factory): class _Project(passa.cli.options.Project): def __init__(self, root, venv=None): - self.path = os.path.abspath(root) + self.path = root.strpath self.venv = venv super(_Project, self).__init__(self.path) @pytest.fixture def tmpvenv(virtualenv): - return passa.models.virtualenv.VirtualEnv(virtualenv) + return mork.virtualenv.VirtualEnv(virtualenv.strpath) @pytest.fixture(scope="function") def project(project_directory, tmpvenv): - with tmpvenv.activated(): + venv_working_set = tmpvenv.initial_working_set + passa_dist = venv_working_set.by_key["passa"] + resolved = tmpvenv.resolve_dist(passa_dist, venv_working_set) + with tmpvenv.activated(extra_dists=list(resolved)): yield _Project(project_directory, tmpvenv) From 2eedd3c38cd8d48db207f793ed6bf3046ee411ea Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Thu, 27 Sep 2018 19:58:07 -0400 Subject: [PATCH 09/26] Update tox and add mork, installer and virtualenv dependencies Signed-off-by: Dan Ryan --- docs/requirements.txt | 2 ++ setup.cfg | 4 ++++ tox.ini | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 docs/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..8213302 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,2 @@ +sphinx +sphinx_rtd_theme diff --git a/setup.cfg b/setup.cfg index 4daf9ee..ace8c27 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,6 +39,8 @@ install_requires = appdirs distlib packaging + packagebuilder + installer pip-shims>=0.1.2 plette[validation]>=0.2.2 requests @@ -52,6 +54,8 @@ install_requires = pack = invoke parver +virtualenv = + mork tests = cached-property pytest-xdist diff --git a/tox.ini b/tox.ini index 2bc8e1d..d436e33 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,7 @@ setenv = LC_ALL = en_US.UTF-8 deps = coverage - -e .[tests] + -e .[tests,virtualenv] commands = coverage run --parallel -m pytest --timeout 300 [] install_command = python -m pip install {opts} {packages} usedevelop = True @@ -23,7 +23,7 @@ commands = [testenv:docs] deps = -r{toxinidir}/docs/requirements.txt - -e .[tests] + -e .[tests,virtualenv] commands = sphinx-build -d {envtmpdir}/doctrees -b html docs docs/build/html sphinx-build -d {envtmpdir}/doctrees -b man docs docs/build/man From f707d5529727bb9b0df91a8a87e5f9e87f5e0f83 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Fri, 28 Sep 2018 01:48:24 -0400 Subject: [PATCH 10/26] Swap to mork implementation for testing Signed-off-by: Dan Ryan --- src/passa/cli/options.py | 6 +- src/passa/models/synchronizers.py | 10 +- src/passa/models/virtualenv.py | 311 ------------------------------ tests/conftest.py | 7 +- 4 files changed, 12 insertions(+), 322 deletions(-) delete mode 100644 src/passa/models/virtualenv.py diff --git a/src/passa/cli/options.py b/src/passa/cli/options.py index 07782db..3abcadb 100644 --- a/src/passa/cli/options.py +++ b/src/passa/cli/options.py @@ -10,7 +10,7 @@ import tomlkit.exceptions import passa.models.projects -import passa.models.virtualenv +import mork import vistir @@ -36,8 +36,8 @@ def __init__(self, root, *args, **kwargs): def get_venv(self, root): if 'VIRTUAL_ENV' in os.environ: - return passa.models.virtualenv.VirtualEnv(os.environ['VIRTUAL_ENV']) - return passa.models.virtualenv.VirtualEnv.from_project_path(root) + return mork.VirtualEnv(os.environ['VIRTUAL_ENV']) + return mork.VirtualEnv.from_project_path(root) def __name__(self): return "Project Root" diff --git a/src/passa/models/synchronizers.py b/src/passa/models/synchronizers.py index 9c8aa9c..78b3bf7 100644 --- a/src/passa/models/synchronizers.py +++ b/src/passa/models/synchronizers.py @@ -1,6 +1,6 @@ # -*- coding=utf-8 -*- -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, unicode_literals, print_function import collections import contextlib @@ -14,8 +14,6 @@ import packaging.version import requirementslib -from .virtualenv import VirtualEnv - from ..internals._pip import uninstall, EditableInstaller, WheelInstaller @@ -135,7 +133,7 @@ def _clean(names, venv=None): if name in PROTECTED_FROM_CLEAN: continue with _remove_package(name, venv=venv) as uninst: - if uninst.paths: + if uninst: cleaned.add(name) return cleaned @@ -244,11 +242,13 @@ def __repr__(self): return "<{0} @ {1!r}>".format(type(self).__name__, self._root) def print(self, packages): + message = "" if not self.sync: message = "Would clean: {0}" else: message = "Cleaned: {0}" - print(message.format(", ".join(sorted(set(packages))))) + packages = ", ".join(sorted(set(packages))) if packages else "" + print(message.format(packages)) def clean(self): groupcoll = _group_installed_names(self.packages, venv=self.project.venv) diff --git a/src/passa/models/virtualenv.py b/src/passa/models/virtualenv.py deleted file mode 100644 index a4f3954..0000000 --- a/src/passa/models/virtualenv.py +++ /dev/null @@ -1,311 +0,0 @@ -# -*- coding=utf-8 -*- - -import base64 -import contextlib -import distlib.scripts -import hashlib -import importlib -import json -import posixpath -import os -import re -import six -import sys -import sysconfig - -import passa.internals._pip -from cached_property import cached_property - -import vistir - - -class VirtualEnv(object): - def __init__(self, venv_dir): - self.recursive_monkey_patch = self.safe_import("recursive_monkey_patch") - self.venv_dir = vistir.compat.Path(venv_dir) - - @classmethod - def from_project_path(cls, path): - path = vistir.compat.Path(path) - if path.name == 'Pipfile': - pipfile_path = path - path = path.parent - else: - pipfile_path = path / 'Pipfile' - pipfile_location = cls.normalize_path(pipfile_path) - venv_path = path / '.venv' - if venv_path.exists(): - if not venv_path.is_dir(): - possible_path = vistir.compat.Path(venv_path.read_text().strip()) - if possible_path.exists(): - return cls(possible_path.as_posix()) - else: - if venv_path.joinpath('lib').exists(): - return cls(venv_path.as_posix()) - sanitized = re.sub(r'[ $`!*@"\\\r\n\t]', "_", path.name)[0:42] - hash_ = hashlib.sha256(pipfile_location.encode()).digest()[:6] - encoded_hash = base64.urlsafe_b64encode(hash_).decode() - hash_fragment = encoded_hash[:8] - venv_name = "{0}-{1}".format(sanitized, hash_fragment) - return cls(cls.get_workon_home().joinpath(venv_name).as_posix()) - - @classmethod - def normalize_path(cls, path): - if not path: - return - if not path.is_absolute(): - try: - path = path.resolve() - except OSError: - path = path.absolute() - path = vistir.path.unicode_path("{0}".format(path)) - if os.name != "nt": - return path - - drive, tail = os.path.splitdrive(path) - # Only match (lower cased) local drives (e.g. 'c:'), not UNC mounts. - if drive.islower() and len(drive) == 2 and drive[1] == ":": - path = "{}{}".format(drive.upper(), tail) - - return vistir.path.unicode_path(path) - - @classmethod - def get_workon_home(cls): - workon_home = os.environ.get("WORKON_HOME") - if not workon_home: - if os.name == "nt": - workon_home = "~/.virtualenvs" - else: - workon_home = os.path.join( - os.environ.get("XDG_DATA_HOME", "~/.local/share"), "virtualenvs" - ) - return vistir.compat.Path(os.path.expandvars(workon_home)).expanduser() - - @classmethod - def filter_sources(cls, requirement, sources): - if not sources or not requirement.index: - return sources - filtered_sources = [ - source for source in sources - if source.get("name") == requirement.index - ] - return filtered_sources or sources - - @classmethod - def safe_import(cls, name): - module = None - if name not in sys.modules: - module = importlib.import_module(name) - else: - module = sys.modules[name] - six.moves.reload_module(module) - return module - - @cached_property - def script_basedir(self): - script_dir = os.path.basename(sysconfig.get_paths()["scripts"]) - return script_dir - - @property - def python(self): - return self.venv_dir.joinpath(self.script_basedir).joinpath("python").as_posix() - - @cached_property - def sys_path(self): - c = vistir.misc.run([self.python, "-c", "import json,sys; print(json.dumps(sys.path))"], - return_object=True, nospin=True) - assert c.returncode == 0, "failed loading virtualenv path" - path = [ - path for path in json.loads(c.out.strip()) - if posixpath.normpath(path).startswith(posixpath.normpath(str(self.venv_dir))) - ] - return path - - @cached_property - def system_paths(self): - paths = {} - sysconfig = self.safe_import("sysconfig") - paths = sysconfig.get_paths() - return paths - - @cached_property - def sys_prefix(self): - c = self.run_py(["-c", "'import sys; print(sys.prefix)'"]) - sys_prefix = vistir.misc.to_text(c.out).strip() - return sys_prefix - - @cached_property - def paths(self): - paths = {} - with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): - os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) - os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") - os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") - sysconfig = self.safe_import("sysconfig") - scheme, _, _ = sysconfig._get_default_scheme().partition('_') - scheme = "{0}_user".format(scheme) - paths = sysconfig.get_paths(scheme=scheme) - return paths - - @property - def scripts_dir(self): - return self.paths["scripts"] - - @cached_property - def passa_entry(self): - pkg_resources = self.safe_import("pkg_resources") - return pkg_resources.working_set.by_key['passa'].location - - def get_distributions(self): - pkg_resources = self.safe_import("pkg_resources") - return pkg_resources.find_distributions(self.paths["purelib"], only=True) - - def get_working_set(self): - working_set = None - import pkg_resources - passa_entry = self.passa_entry - working_set = pkg_resources.WorkingSet(self.sys_path + [passa_entry]) - return working_set - - @cached_property - def python_version(self): - with self.activated(): - sysconfig = self.safe_import("sysconfig") - py_version = sysconfig.get_python_version() - return py_version - - def get_setup_install_args(self, pkgname, setup_py, develop=False): - headers = vistir.compat.Path(self.sys_prefix) / "include" / "site" - headers = headers / "python{0}".format(self.python_version) / pkgname - install_arg = "install" if not develop else "develop" - return [ - self.python, "-u", "-c", SETUPTOOLS_SHIM % setup_py, install_arg, - "--single-version-externally-managed", "root={0}".format(), - "--install-headers={0}".format(headers.as_posix()), - "--install-purelib={0}".format(self.paths["purelib"]), - "--install-platlib={0}".format(self.paths["platlib"]), - "--install-scripts={0}".format(self.scripts_dir), - "--install-data={0}".format(self.paths["data"]), - ] - - def install(self, req, editable=False, sources=[]): - with self.activated(): - install_options = ["--prefix={0}".format(self.venv_dir),] - passa_pip = self.safe_import("passa.internals._pip") - ireq = req.as_ireq() - if editable: - with vistir.contextmanagers.cd(ireq.setup_py_dir, ireq.setup_py): - c = self.run( - install_options + self.get_setup_install_args( - req.name, develop=editable - ), cwd=ireq.setup_py_dir - ) - return c.returncode - distlib_scripts = self.safe_import("distlib.scripts") - sources = self.filter_sources(req, sources) - hashes = req.hashes - wheel = passa_pip.build_wheel(ireq, sources, hashes) - wheel.install(self.paths, distlib_scripts.ScriptMaker(None, None)) - - @contextlib.contextmanager - def activated(self): - original_path = sys.path - original_prefix = sys.prefix - original_user_base = os.environ.get("PYTHONUSERBASE", None) - original_venv = os.environ.get("VIRTUAL_ENV", None) - passa_path = vistir.compat.Path(__file__).absolute().parent.parent.as_posix() - with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): - os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") - os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") - activate_this = os.path.join(self.scripts_dir, "activate_this.py") - with open(activate_this, "r") as f: - code = compile(f.read(), activate_this, "exec") - exec(code, dict(__file__=activate_this)) - os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.venv_dir.as_posix()) - os.environ["VIRTUAL_ENV"] = vistir.compat.fs_str(self.venv_dir.as_posix()) - sys.path = self.sys_path - sys.prefix = self.venv_dir - site = self.safe_import("site") - site.addsitedir(passa_path) - sys.modules["recursive_monkey_patch"] = self.recursive_monkey_patch - pkg_resources = self.safe_import("pkg_resources") - try: - yield - finally: - print("Deactivating virtualenv...") - del os.environ["VIRTUAL_ENV"] - del os.environ["PYTHONUSERBASE"] - if original_user_base: - os.environ["PYTHONUSERBASE"] = original_user_base - if original_venv: - os.environ["VIRTUAL_ENV"] = original_venv - sys.path = original_path - sys.prefix = original_prefix - six.moves.reload_module(pkg_resources) - - def run(self, cmd, cwd=os.curdir): - c = None - with self.activated(): - script = vistir.cmdparse.Script.parse(cmd) - c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) - return c - - def run_py(self, cmd, cwd=os.curdir): - c = None - if isinstance(cmd, six.string_types): - script = vistir.cmdparse.Script.parse("{0} {1}".format(self.python, cmd)) - else: - script = vistir.cmdparse.Script.parse([self.python,] + list(cmd)) - with self.activated(): - c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) - return c - - def is_installed(self, pkgname): - return any(d for d in self.get_distributions() if d.project_name == pkgname) - - def get_monkeypatched_pathset(self): - from pip_shims.shims import req_install - req_uninstall_name = "{0}.req_uninstall".format(req_install.__package__) - req_uninstall = self.safe_import(req_uninstall_name) - self.recursive_monkey_patch.monkey_patch( - PatchedUninstaller, req_uninstall.UninstallPathSet - ) - return req_uninstall.UninstallPathSet - - @contextlib.contextmanager - def uninstall(self, pkgname, *args, **kwargs): - auto_confirm = kwargs.pop("auto_confirm", True) - verbose = kwargs.pop("verbose", False) - with self.activated(): - pathset_base = self.get_monkeypatched_pathset() - dist = next( - iter(filter(lambda d: d.project_name == pkgname, self.get_working_set())), - None - ) - pathset = pathset_base.from_dist(dist) - if pathset is not None: - pathset.remove(auto_confirm=auto_confirm, verbose=verbose) - try: - yield pathset - except Exception as e: - if pathset is not None: - pathset.rollback() - else: - if pathset is not None: - pathset.commit() - if pathset is None: - return - - -SETUPTOOLS_SHIM = ( - "import setuptools, tokenize;__file__=%r;" - "f=getattr(tokenize, 'open', open)(__file__);" - "code=f.read().replace('\\r\\n', '\\n');" - "f.close();" - "exec(compile(code, __file__, 'exec'))" -) - - -class PatchedUninstaller(object): - def _permitted(self, path): - return True diff --git a/tests/conftest.py b/tests/conftest.py index 1aaf419..0ba621b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -54,8 +54,9 @@ def tmpvenv(virtualenv): @pytest.fixture(scope="function") def project(project_directory, tmpvenv): - venv_working_set = tmpvenv.initial_working_set - passa_dist = venv_working_set.by_key["passa"] - resolved = tmpvenv.resolve_dist(passa_dist, venv_working_set) + import pkg_resources + passa_dist = pkg_resources.get_distribution(pkg_resources.Requirement('passa')) + # passa_dist = tmpvenv.initial_working_set.by_key["passa"] + resolved = tmpvenv.resolve_dist(passa_dist, tmpvenv.base_working_set) with tmpvenv.activated(extra_dists=list(resolved)): yield _Project(project_directory, tmpvenv) From d7f6a11ab06948f6a604b64a88dc86ef3dfff0df Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sun, 30 Sep 2018 16:53:47 -0400 Subject: [PATCH 11/26] Update CI configs Signed-off-by: Dan Ryan --- .gitignore | 114 ++++++++++++++++++++++++++++++++--- .travis.yml | 11 ++-- appveyor.yml | 4 +- tests/actions/test_remove.py | 0 tests/actions/test_sync.py | 0 tests/conftest.py | 6 +- tox.ini | 7 ++- 7 files changed, 122 insertions(+), 20 deletions(-) delete mode 100644 tests/actions/test_remove.py delete mode 100644 tests/actions/test_sync.py diff --git a/.gitignore b/.gitignore index b858aca..741f1b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,114 @@ -.env -.venv -__pycache__ - /build /dist /docs/_build /pack +htmlcov/ +.pytest_cache/ +.vscode/ + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so -*.egg-info +# Distribution / packaging +.Python +develop-eggs/ +downloads/ +eggs/ +.eggs/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST -*.py[co] +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ .pytest_cache/ -.vscode/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json diff --git a/.travis.yml b/.travis.yml index 8e38f96..3acd3a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,8 @@ matrix: fast_finish: true install: - - "python -m pip install --upgrade pip pytest-timeout" - - "python -m pip install --upgrade -e .[tests]" + - "python -m pip install --upgrade pip setuptools pytest-timeout" + - "python -m pip install --upgrade -e .[tests,virtualenv]" script: - "python -m pytest -v -n 8 tests/" @@ -24,7 +24,7 @@ jobs: - stage: packaging python: "3.6" install: - - "python -m pip install --upgrade pip" + - "python -m pip install --upgrade pip setuptools" - "python -m pip install --upgrade check-manifest readme-renderer" script: - "python setup.py check -m -r -s" @@ -38,8 +38,7 @@ jobs: - stage: coverage python: "3.6" install: - - "python -m pip install --upgrade pip" - - "python -m pip install --upgrade -e .[tests]" - - "python -m pip install --upgrade pytest-timeout pytest-xdist pytest-cov" + - "python -m pip install --upgrade pip setuptools pytest-timeout pytest-cov pytest-xdist" + - "python -m pip install --upgrade -e .[tests,virtualenv]" script: - "pytest -n auto --timeout 300 --cov=passa --cov-report=term-missing --cov-report=xml --cov-report=html tests" diff --git a/appveyor.yml b/appveyor.yml index 3216d26..a9ecca6 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,8 +5,8 @@ branches: install: - "SET PATH=C:\\Python36-x64;%PATH%" - "python --version" - - "python -m pip install --upgrade pip" - - "python -m pip install --upgrade -e .[pack,tests]" + - "python -m pip install --upgrade pip setuptools pytest-timeout pytest-xdist" + - "python -m pip install --upgrade -e .[pack,tests,virtualenv]" build_script: - "python -m invoke pack" diff --git a/tests/actions/test_remove.py b/tests/actions/test_remove.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/actions/test_sync.py b/tests/actions/test_sync.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/conftest.py b/tests/conftest.py index 0ba621b..ec02ca9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -53,10 +53,10 @@ def tmpvenv(virtualenv): @pytest.fixture(scope="function") -def project(project_directory, tmpvenv): +def project(project_directory, tmpvenv, tmpdir): import pkg_resources passa_dist = pkg_resources.get_distribution(pkg_resources.Requirement('passa')) - # passa_dist = tmpvenv.initial_working_set.by_key["passa"] resolved = tmpvenv.resolve_dist(passa_dist, tmpvenv.base_working_set) - with tmpvenv.activated(extra_dists=list(resolved)): + with vistir.contextmanagers.temp_environ(), tmpvenv.activated(extra_dists=list(resolved)): + os.environ["PACKAGEBUILDER_CACHE_DIR"] = tmpdir.strpath yield _Project(project_directory, tmpvenv) diff --git a/tox.ini b/tox.ini index d436e33..6428cef 100644 --- a/tox.ini +++ b/tox.ini @@ -8,9 +8,13 @@ setenv = LC_ALL = en_US.UTF-8 deps = coverage + setuptools + pytest + pytest-timeout + pytest-sugar -e .[tests,virtualenv] commands = coverage run --parallel -m pytest --timeout 300 [] -install_command = python -m pip install {opts} {packages} +install_command = python -m pip install --upgrade {opts} {packages} usedevelop = True [testenv:coverage-report] @@ -23,7 +27,6 @@ commands = [testenv:docs] deps = -r{toxinidir}/docs/requirements.txt - -e .[tests,virtualenv] commands = sphinx-build -d {envtmpdir}/doctrees -b html docs docs/build/html sphinx-build -d {envtmpdir}/doctrees -b man docs docs/build/man From 8f56a899271d98c4bbdc18a7b18d586ac3da94e9 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sun, 30 Sep 2018 16:54:16 -0400 Subject: [PATCH 12/26] Add deprecation warning ignores to test runners Signed-off-by: Dan Ryan --- setup.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.cfg b/setup.cfg index ace8c27..194cc04 100644 --- a/setup.cfg +++ b/setup.cfg @@ -102,6 +102,9 @@ strict = true addopts = -ra testpaths = tests/ norecursedirs = .* build dist news tasks docs +filterwarnings = + ignore::DeprecationWarning + ignore::PendingDeprecationWarning [build-system] requires = ["setuptools", "wheel"] From 6aa33166404e125a7e8ee4cc258a1fc9674aeeac Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sun, 30 Sep 2018 16:55:49 -0400 Subject: [PATCH 13/26] Add project fixtures, venv support Signed-off-by: Dan Ryan --- src/passa/actions/add.py | 2 +- src/passa/actions/install.py | 1 + src/passa/actions/lock.py | 3 +- src/passa/actions/remove.py | 1 + src/passa/cli/options.py | 2 +- src/passa/internals/_pip.py | 163 +++++++++++++++++++++++----- src/passa/internals/_pip_shims.py | 9 ++ src/passa/internals/dependencies.py | 11 +- src/passa/models/synchronizers.py | 12 +- tests/conftest.py | 77 +++++++++---- 10 files changed, 219 insertions(+), 62 deletions(-) diff --git a/src/passa/actions/add.py b/src/passa/actions/add.py index 3efc4dc..49e4bce 100644 --- a/src/passa/actions/add.py +++ b/src/passa/actions/add.py @@ -48,7 +48,7 @@ def add_packages(packages=[], editables=[], project=None, dev=False, sync=False, syncer = Synchronizer( project, default=default, develop=develop, - clean_unneeded=clean + clean_unneeded=clean, venv=getattr(project, "venv", None) ) success = sync(syncer) if not success: diff --git a/src/passa/actions/install.py b/src/passa/actions/install.py index 1728dae..9872584 100644 --- a/src/passa/actions/install.py +++ b/src/passa/actions/install.py @@ -30,3 +30,4 @@ def install(project=None, check=True, dev=False, clean=True): return 1 print("Synchronized project at", project.root) + return 0 diff --git a/src/passa/actions/lock.py b/src/passa/actions/lock.py index 7c09469..f661c82 100644 --- a/src/passa/actions/lock.py +++ b/src/passa/actions/lock.py @@ -11,7 +11,8 @@ def lock(project=None): locker = BasicLocker(project) success = lock(locker) if not success: - return + return 1 project._l.write() print("Written to project at", project.root) + return 0 diff --git a/src/passa/actions/remove.py b/src/passa/actions/remove.py index 17ba1c7..92f6168 100644 --- a/src/passa/actions/remove.py +++ b/src/passa/actions/remove.py @@ -36,3 +36,4 @@ def remove(project=None, only="default", packages=[], clean=True, sync=False): return 1 print("Cleaned project at", project.root) + return 0 diff --git a/src/passa/cli/options.py b/src/passa/cli/options.py index 3abcadb..eafa71d 100644 --- a/src/passa/cli/options.py +++ b/src/passa/cli/options.py @@ -25,7 +25,7 @@ def __init__(self, root, *args, **kwargs): raise argparse.ArgumentError( project, "{0!r} is not a Pipfile project".format(root.as_posix()), ) - self.venv = self.get_venv(root) + self.venv = kwargs.pop("venv", self.get_venv(root)) try: super(Project, self).__init__(root.as_posix(), env_prefix=self.venv.venv_dir, *args, **kwargs) diff --git a/src/passa/internals/_pip.py b/src/passa/internals/_pip.py index 2aa143a..da52fc6 100644 --- a/src/passa/internals/_pip.py +++ b/src/passa/internals/_pip.py @@ -9,16 +9,21 @@ import os import distlib.database +import distlib.metadata import distlib.scripts import distlib.wheel import packaging.utils import pip_shims import setuptools.dist import six +import sys +import sysconfig import vistir from ..models.caches import CACHE_DIR -from ._pip_shims import VCS_SUPPORT, build_wheel as _build_wheel, unpack_url +from ._pip_shims import ( + SETUPTOOLS_SHIM, VCS_SUPPORT, build_wheel as _build_wheel, unpack_url +) from .utils import filter_sources @@ -282,6 +287,7 @@ class NoopInstaller(object): arguments, and should be called in that order to prepare an installation operation, and to actually install things. """ + def prepare(self): pass @@ -289,39 +295,121 @@ def install(self): pass -class EditableInstaller(NoopInstaller): - """Installer to handle editable. - """ - def __init__(self, requirement): - ireq = requirement.as_ireq() - self.working_directory = ireq.setup_py_dir - self.setup_py = ireq.setup_py - - def install(self): - with vistir.cd(self.working_directory), _suppress_distutils_logs(): - # Access from Setuptools to ensure things are patched correctly. - setuptools.dist.distutils.core.run_setup( - self.setup_py, ["develop", "--no-deps"], - ) - - -class WheelInstaller(NoopInstaller): - """Installer by building a wheel. +class VenvInstaller(NoopInstaller): + """Virtualenv-capable installer""" - The wheel is built during `prepare()`, and installed in `install()`. - """ - def __init__(self, requirement, sources, paths): + def __init__(self, requirement, sources=None, paths=None, venv=None): self.ireq = requirement.as_ireq() self.sources = filter_sources(requirement, sources) self.hashes = requirement.hashes or None self.paths = paths - self.wheel = None + self.venv = venv + self.built = None + self.python = sys.executable if not self.venv else self.venv.python + self.py_version = self.venv.python_version if self.venv else sysconfig.get_python_version() + self.metadata = None + self.is_wheel = False + + @property + def src_dir(self): + build_dir = os.environ.get("PASSA_BUILD_DIR", None) + if not build_dir: + build_dir = vistir.path.create_tracked_tempdir("passa-build-dir") + return build_dir + + @property + def setup_dir(self): + if not self.built: + return self.ireq.setup_py_dir + return vistir.compat.Path(self.built.path).parent + + @property + def installation_args(self): + install_arg = "install" if not self.ireq.editable else "develop" + setup_path = self.setup_dir.joinpath("setup.py") + install_keys = ["headers", "purelib", "platlib", "scripts", "data"] + install_args = [ + self.python, "-u", "-c", SETUPTOOLS_SHIM % setup_path.as_posix(), install_arg, + "--single-version-externally-managed", "--no-deps", + "--prefix={0}".format(self.paths["prefix"]) + ] + for key in install_keys: + install_args.append("--install-{0}={1}".format(key, self.paths[key])) + return install_args + + def build_wheel(self): + self.built = build_wheel(self.ireq, self.sources, self.hashes) + self.metadata = read_wheel_metadata(self.built) + self.is_wheel = True + + def build_sdist(self): + finder = _get_finder(self.sources) + self.ireq.populate_link(finder, True, False) + self.ireq.ensure_has_source_dir(self.src_dir) + self.built = get_sdist(self.ireq) + self.metadata = read_sdist_metadata(self.built) + + def install_wheel(self): + scripts = distlib.scripts.ScriptMaker(None, None) + self.built.install(self.paths, scripts) + + def install_sdist(self): + with vistir.cd(self.setup_dir.as_posix()), _suppress_distutils_logs(): + c = vistir.misc.run(self.installation_args, return_object=True, block=True, + nospin=True) + if c.returncode != 0: + err_text = "{0!r}: {1!r}".format(c.err, c.out) + raise RuntimeError("Failed to install package: {0!r}".format(err_text)) + return def prepare(self): - self.wheel = build_wheel(self.ireq, self.sources, self.hashes) + pass def install(self): - self.wheel.install(self.paths, distlib.scripts.ScriptMaker(None, None)) + if self.venv: + with self.venv.activated(): + self._install() + else: + self._install() + + +class SdistInstaller(VenvInstaller): + """Installer for SDists""" + def __init__(self, *args, **kwargs): + super(SdistInstaller, self).__init__(*args, **kwargs) + + def prepare(self): + try: + self.build_wheel() + except WheelBuildError: + self.build_sdist() + if not self.built or not self.metadata: + raise + + def _install(self): + if self.is_wheel: + self.install_wheel() + else: + self.install_sdist() + + +class Installer(SdistInstaller): + """Installer to handle editable. + """ + def __init__(self, *args, **kwargs): + super(Installer, self).__init__(*args, **kwargs) + + @property + def src_dir(self): + build_dir = os.environ.get("PIP_SRC", None) + venv = os.environ.get("VIRTUAL_ENV", None) + if venv: + src_dir = os.path.join(venv, "src") + if os.path.exists(src_dir): + build_dir = src_dir + if not build_dir: + build_dir = vistir.path.create_tracked_tempdir("passa-build-dir") + return build_dir def _iter_egg_info_directories(root, name): @@ -389,9 +477,28 @@ def _find_egg_info(ireq): return top_egg_info -def read_sdist_metadata(ireq): +def get_sdist(ireq): egg_info_dir = _find_egg_info(ireq) if not egg_info_dir: return None - distribution = distlib.database.EggInfoDistribution(egg_info_dir) - return distribution.metadata + return distlib.database.EggInfoDistribution(egg_info_dir) + + +def read_sdist_metadata(sdist): + if not getattr(sdist, "metadata", None): + sdist = get_sdist(sdist) + if not sdist: + return None + return sdist.metadata + + +def read_wheel_metadata(wheel): + metadata = None + try: + metadata = wheel.metadata + except distlib.metadata.MetadataConflictError: + import zipfile + metadata = wheel.get_wheel_metadata( + zipfile.ZipFile(os.path.join(wheel.dirname, wheel.filename)) + ) + return metadata diff --git a/src/passa/internals/_pip_shims.py b/src/passa/internals/_pip_shims.py index b2c7b6e..243675d 100644 --- a/src/passa/internals/_pip_shims.py +++ b/src/passa/internals/_pip_shims.py @@ -59,3 +59,12 @@ def _unpack_url_pre10(*args, **kwargs): if PIP_VERSION < VERSION_10: build_wheel = _build_wheel_pre10 unpack_url = _unpack_url_pre10 + + +SETUPTOOLS_SHIM = ( + "import setuptools, tokenize;__file__=%r;" + "f=getattr(tokenize, 'open', open)(__file__);" + "code=f.read().replace('\\r\\n', '\\n');" + "f.close();" + "exec(compile(code, __file__, 'exec'))" +) diff --git a/src/passa/internals/dependencies.py b/src/passa/internals/dependencies.py index 410a5e6..b163b85 100644 --- a/src/passa/internals/dependencies.py +++ b/src/passa/internals/dependencies.py @@ -14,7 +14,9 @@ import six from ..models.caches import DependencyCache, RequiresPythonCache -from ._pip import WheelBuildError, build_wheel, read_sdist_metadata +from ._pip import ( + WheelBuildError, build_wheel, get_sdist, read_wheel_metadata, read_sdist_metadata +) from .markers import contains_extra, get_contained_extras, get_without_extra from .utils import get_pinned_version, is_pinned @@ -225,17 +227,18 @@ def _get_dependencies_from_pip(ireq, sources): """ extras = ireq.extras or () try: - wheel = build_wheel(ireq, sources) + built = build_wheel(ireq, sources) except WheelBuildError: # XXX: This depends on a side effect of `build_wheel`. This block is # reached when it fails to build an sdist, where the sdist would have # been downloaded, extracted into `ireq.source_dir`, and partially # built (hopefully containing .egg-info). - metadata = read_sdist_metadata(ireq) + built = get_sdist(ireq) + metadata = read_sdist_metadata(built) if not metadata: raise else: - metadata = wheel.metadata + metadata = read_wheel_metadata(built) requirements = _read_requirements(metadata, extras) requires_python = _read_requires_python(metadata) return requirements, requires_python diff --git a/src/passa/models/synchronizers.py b/src/passa/models/synchronizers.py index 78b3bf7..2ade9c5 100644 --- a/src/passa/models/synchronizers.py +++ b/src/passa/models/synchronizers.py @@ -8,13 +8,14 @@ import sys import sysconfig +import distlib.wheel import pkg_resources import packaging.markers import packaging.version import requirementslib -from ..internals._pip import uninstall, EditableInstaller, WheelInstaller +from ..internals._pip import uninstall, Installer def _is_installation_local(name, venv=None): @@ -191,10 +192,7 @@ def _sync(self): if markers and not packaging.markers.Marker(markers).evaluate(): continue r.markers = None - if r.editable: - installer = EditableInstaller(r, venv=self.venv) - else: - installer = WheelInstaller(r, self.sources, self.paths) + installer = Installer(r, sources=self.sources, paths=self.paths, venv=self.venv) try: installer.prepare() except Exception as e: @@ -242,13 +240,11 @@ def __repr__(self): return "<{0} @ {1!r}>".format(type(self).__name__, self._root) def print(self, packages): - message = "" if not self.sync: message = "Would clean: {0}" else: message = "Cleaned: {0}" - packages = ", ".join(sorted(set(packages))) if packages else "" - print(message.format(packages)) + print(message.format(", ".join(sorted(set(packages))))) def clean(self): groupcoll = _group_installed_names(self.packages, venv=self.project.venv) diff --git a/tests/conftest.py b/tests/conftest.py index ec02ca9..2726762 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,11 +2,16 @@ import os import pytest import passa +import passa.models.projects import passa.cli.options -import mork.virtualenv +import mork +import pkg_resources +import plette import sys import vistir +from collections import deque + DEFAULT_PIPFILE_CONTENTS = """ [[source]] @@ -20,12 +25,18 @@ """.strip() -@pytest.fixture(scope="function") -def project_directory(tmpdir_factory): - project_dir = tmpdir_factory.mktemp("passa-project") - project_dir.join("Pipfile").write(DEFAULT_PIPFILE_CONTENTS) - with vistir.contextmanagers.cd(project_dir.strpath): - yield project_dir +@pytest.fixture(scope="session") +def working_set_extension(): + dists = set() + passa_dist = pkg_resources.get_distribution(pkg_resources.Requirement('passa')) + dists.add(passa_dist) + requirements = deque(passa_dist.requires(extras=('tests', 'virtualenv'))) + while requirements: + req = requirements.popleft() + dist = pkg_resources.working_set.find(req) + dists.add(dist) + requirements.extend(dist.requires()) + return dists @pytest.fixture(scope="function") @@ -41,22 +52,50 @@ def virtualenv(tmpdir_factory): class _Project(passa.cli.options.Project): - def __init__(self, root, venv=None): - self.path = root.strpath + def __init__(self, root, venv=None, working_set_extension=[]): + self.path = root self.venv = venv - super(_Project, self).__init__(self.path) + self.working_set_extension = working_set_extension + super(_Project, self).__init__(self.path, venv=venv) + self.pipfile_instance = vistir.compat.Path(self.pipfile_location) + self.lockfile_instance = vistir.compat.Path(self.lockfile_location) + + def reload(self): + self._p = passa.models.projects.ProjectFile.read( + os.path.join(self.path, "Pipfile"), + plette.Pipfile, + ) + self._l = passa.models.projects.ProjectFile.read( + os.path.join(self.path, "Pipfile.lock"), + plette.Lockfile, + invalid_ok=True, + ) + +@pytest.fixture(scope="function") +def project_directory(tmpdir_factory): + project_dir = tmpdir_factory.mktemp("passa-project") + project_dir.join("Pipfile").write(DEFAULT_PIPFILE_CONTENTS) + with vistir.contextmanagers.cd(project_dir.strpath): + yield project_dir @pytest.fixture -def tmpvenv(virtualenv): - return mork.virtualenv.VirtualEnv(virtualenv.strpath) +def tmpvenv(virtualenv, tmpdir): + venv_srcdir = virtualenv.join("src").mkdir() + venv = mork.virtualenv.VirtualEnv(virtualenv.strpath) + venv.run(["pip", "install", "--upgrade", "mork", "setuptools"]) + with vistir.contextmanagers.temp_environ(): + os.environ["PACKAGEBUILDER_CACHE_DIR"] = tmpdir.strpath + os.environ["PIP_QUIET"] = "1" + os.environ["PIP_SRC"] = venv_srcdir.strpath + venv.is_installed = lambda x: any(d for d in venv.get_distributions() if d.project_name == x) + yield venv @pytest.fixture(scope="function") -def project(project_directory, tmpvenv, tmpdir): - import pkg_resources - passa_dist = pkg_resources.get_distribution(pkg_resources.Requirement('passa')) - resolved = tmpvenv.resolve_dist(passa_dist, tmpvenv.base_working_set) - with vistir.contextmanagers.temp_environ(), tmpvenv.activated(extra_dists=list(resolved)): - os.environ["PACKAGEBUILDER_CACHE_DIR"] = tmpdir.strpath - yield _Project(project_directory, tmpvenv) +def project(project_directory, working_set_extension, tmpvenv): + # resolved = tmpvenv.resolve_dist(passa_dist, tmpvenv.base_working_set) + with tmpvenv.activated(extra_dists=list(working_set_extension)): + project = _Project(project_directory.strpath, venv=tmpvenv, working_set_extension=working_set_extension) + project.is_installed = lambda x: any(d for d in tmpvenv.get_working_set() if d.project_name == x) + yield project From e49eaebee4e4f391544be6057c279c7148577bb9 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sun, 30 Sep 2018 16:56:09 -0400 Subject: [PATCH 14/26] Add clean, install and lock tests Signed-off-by: Dan Ryan --- tests/actions/test_clean.py | 4 +- tests/actions/test_install.py | 96 +++++++++++++++++++++++++++++++++++ tests/actions/test_lock.py | 53 +++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) diff --git a/tests/actions/test_clean.py b/tests/actions/test_clean.py index c56d06d..2160301 100644 --- a/tests/actions/test_clean.py +++ b/tests/actions/test_clean.py @@ -3,16 +3,18 @@ import passa.actions.clean -def test_clean_subset(project): +def test_clean(project): retcode = passa.actions.add.add_packages(["requests"], project=project) assert not retcode packages = ["requests", "chardet", "certifi", "idna"] c = project.venv.run("pip install pytz") assert c.returncode == 0 + assert project.venv.is_installed("pytz") c = project.venv.run("python -c 'import pytz'") assert c.returncode == 0 clean_retcode = passa.actions.clean.clean(project=project) assert not clean_retcode + assert not project.venv.is_installed("pytz") c = project.venv.run("python -c 'import pytz'") assert c.returncode != 0 assert all(pkg in project.lockfile.default for pkg in packages) diff --git a/tests/actions/test_install.py b/tests/actions/test_install.py index e69de29..bb205e6 100644 --- a/tests/actions/test_install.py +++ b/tests/actions/test_install.py @@ -0,0 +1,96 @@ +# -*- coding=utf-8 -*- + +import passa.actions.install +import passa.actions.add +import passa.cli.options +import passa.models.projects +import pytest + + +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_install_one(project, is_dev): + add_kwargs = { + "project": project, + "packages": ["pytz",], + "editables": [], + "dev": is_dev, + "sync": False, + "clean": False + } + retcode = passa.actions.add.add_packages(**add_kwargs) + assert not retcode + lockfile_section = "default" if not is_dev else "develop" + assert 'pytz' in project.lockfile._data[lockfile_section].keys() + install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) + assert install == 0 + assert project.venv.is_installed("pytz") or project.is_installed("pytz") + + +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_install_one_with_deps(project, is_dev): + add_kwargs = { + "project": project, + "packages": ["requests",], + "editables": [], + "dev": is_dev, + "sync": False, + "clean": False + } + retcode = passa.actions.add.add_packages(**add_kwargs) + assert not retcode + lockfile_section = "default" if not is_dev else "develop" + assert 'requests' in project.lockfile._data[lockfile_section].keys() + assert 'idna' in project.lockfile._data[lockfile_section].keys() + install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) + assert install == 0 + assert project.venv.is_installed("requests") or project.is_installed("requests") + assert project.venv.is_installed("idna") or project.is_installed("idna") + + +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_install_editable(project, is_dev): + add_kwargs = { + "project": project, + "packages": [], + "editables": ["git+https://github.com/sarugaku/shellingham.git@1.2.1#egg=shellingham",], + "dev": is_dev, + "sync": False, + "clean": False + } + retcode = passa.actions.add.add_packages(**add_kwargs) + assert not retcode + lockfile_section = "default" if not is_dev else "develop" + assert 'shellingham' in project.lockfile._data[lockfile_section].keys() + install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) + assert install == 0 + project.reload() + assert (project.venv.is_installed("shellingham") or + project.is_installed("shellingham")), list([dist.project_name for dist in project.venv.get_distributions()]) + + +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_install_sdist(project, is_dev): + add_kwargs = { + "project": project, + "packages": ["arrow",], + "editables": [], + "dev": is_dev, + "sync": False, + "clean": False + } + retcode = passa.actions.add.add_packages(**add_kwargs) + assert not retcode + lockfile_section = "default" if not is_dev else "develop" + assert 'arrow' in project.lockfile._data[lockfile_section].keys() + install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) + assert install == 0 + project.reload() + assert project.venv.is_installed("arrow") or project.is_installed("arrow") diff --git a/tests/actions/test_lock.py b/tests/actions/test_lock.py index e69de29..962493e 100644 --- a/tests/actions/test_lock.py +++ b/tests/actions/test_lock.py @@ -0,0 +1,53 @@ +# -*- coding=utf-8 -*- + +import passa.actions.lock +import passa.actions.install +import passa.cli.options +import passa.models.projects +import pytest + + +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_lock_one(project, is_dev): + line = "pytz" + project.add_line_to_pipfile(line, develop=is_dev) + retcode = passa.actions.lock.lock(project=project) + project.reload() + assert retcode == 0 + lockfile_section = "default" if not is_dev else "develop" + assert 'pytz' in project.lockfile._data[lockfile_section].keys() + install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) + assert install == 0 + + +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_lock_one_with_deps(project, is_dev): + line = "requests" + project.add_line_to_pipfile(line, develop=is_dev) + retcode = passa.actions.lock.lock(project=project) + project.reload() + assert retcode == 0 + lockfile_section = "default" if not is_dev else "develop" + assert 'requests' in project.lockfile._data[lockfile_section].keys() + assert 'idna' in project.lockfile._data[lockfile_section].keys() + install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) + assert install == 0 + + +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_lock_editable(project, is_dev): + line = "-e git+https://github.com/sarugaku/shellingham.git@1.2.1#egg=shellingham" + project.add_line_to_pipfile(line, develop=is_dev) + retcode = passa.actions.lock.lock(project=project) + project.reload() + assert retcode == 0 + lockfile_section = "default" if not is_dev else "develop" + assert 'shellingham' in project.lockfile._data[lockfile_section].keys(), project.lockfile._data + install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) + assert install == 0 From 0863400d6946e362b9c66b5c4ec39fc5cb9f34e5 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Sun, 30 Sep 2018 16:56:55 -0400 Subject: [PATCH 15/26] Add sync and remove tests Signed-off-by: Dan Ryan --- tests/actions/test_remove_and_sync.py | 142 ++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 tests/actions/test_remove_and_sync.py diff --git a/tests/actions/test_remove_and_sync.py b/tests/actions/test_remove_and_sync.py new file mode 100644 index 0000000..e14ec8a --- /dev/null +++ b/tests/actions/test_remove_and_sync.py @@ -0,0 +1,142 @@ +# -*- coding=utf-8 -*- + +import passa.actions.add +import passa.actions.remove +import passa.cli.options +import passa.models.projects +import pytest +import vistir + + +@pytest.mark.parametrize( + 'sync', (True, False) +) +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_remove_one(project, sync, is_dev): + pkg = "xlrd" + add_kwargs = { + "project": project, + "packages": [pkg,], + "editables": [], + "dev": is_dev, + "sync": sync, + "clean": False + } + retcode = passa.actions.add.add_packages(**add_kwargs) + assert not retcode + lockfile_section = "default" if not is_dev else "develop" + assert pkg in project.lockfile._data[lockfile_section].keys() + if sync: + assert project.venv.is_installed(pkg) or project.is_installed(pkg) + remove = "default" if not is_dev else "dev" + retcode = passa.actions.remove.remove(project=project, packages=[pkg,], sync=sync, only=remove) + assert not retcode + project.reload() + assert pkg not in project.lockfile._data[lockfile_section].keys() + if sync: + assert not project.venv.is_installed(pkg) + + +@pytest.mark.parametrize( + 'sync', (True, False), +) +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_remove_one_with_deps(project, sync, is_dev): + add_kwargs = { + "project": project, + "packages": ["requests",], + "editables": [], + "dev": is_dev, + "sync": sync, + "clean": False + } + retcode = passa.actions.add.add_packages(**add_kwargs) + assert not retcode + lockfile_section = "default" if not is_dev else "develop" + assert 'requests' in project.lockfile._data[lockfile_section].keys() + assert 'idna' in project.lockfile._data[lockfile_section].keys() + if sync: + c = vistir.misc.run(["{0}".format(project.venv.python), "-c", "import requests"], + nospin=True, block=True, return_object=True) + assert c.returncode == 0, (c.out, c.err) + assert project.venv.is_installed("requests") or project.is_installed("requests") + assert project.venv.is_installed("idna") or project.is_installed("idna") + remove = "default" if not is_dev else "dev" + retcode = passa.actions.remove.remove(project=project, packages=["requests",], sync=sync, only=remove) + assert not retcode + project.reload() + assert "requests" not in project.lockfile._data[lockfile_section].keys() + assert "idna" not in project.lockfile._data[lockfile_section].keys() + if sync: + assert not project.venv.is_installed("requests") + assert not project.venv.is_installed("idna") + + +@pytest.mark.parametrize( + 'sync', (True, False), +) +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_remove_editable(project, sync, is_dev): + add_kwargs = { + "project": project, + "packages": [], + "editables": ["git+https://github.com/sarugaku/shellingham.git@1.2.1#egg=shellingham",], + "dev": is_dev, + "sync": sync, + "clean": False + } + retcode = passa.actions.add.add_packages(**add_kwargs) + assert not retcode + lockfile_section = "default" if not is_dev else "develop" + assert 'shellingham' in project.lockfile._data[lockfile_section].keys() + if sync: + c = vistir.misc.run(["{0}".format(project.venv.python), "-c", "import shellingham"], + nospin=True, block=True, return_object=True) + assert c.returncode == 0, (c.out, c.err) + assert project.venv.is_installed("shellingham") or project.is_installed("shellingham") + remove = "default" if not is_dev else "dev" + retcode = passa.actions.remove.remove(project=project, packages=["shellingham",], sync=sync, only=remove) + assert not retcode + project.reload() + assert "shellingham" not in project.lockfile._data[lockfile_section].keys() + if sync: + assert not project.venv.is_installed("shellingham") + + +@pytest.mark.parametrize( + 'sync', (True, False), +) +@pytest.mark.parametrize( + 'is_dev', (True, False) +) +def test_remove_sdist(project, is_dev, sync): + add_kwargs = { + "project": project, + "packages": ["arrow"], + "editables": [], + "dev": is_dev, + "sync": sync, + "clean": False + } + retcode = passa.actions.add.add_packages(**add_kwargs) + assert not retcode + lockfile_section = "default" if not is_dev else "develop" + assert 'arrow' in project.lockfile._data[lockfile_section].keys() + if sync: + c = vistir.misc.run(["{0}".format(project.venv.python), "-c", "import arrow"], + nospin=True, block=True, return_object=True) + assert c.returncode == 0, (c.out, c.err) + assert project.venv.is_installed("arrow") or project.is_installed("arrow") + remove = "default" if not is_dev else "dev" + retcode = passa.actions.remove.remove(project=project, packages=["arrow",], sync=sync, only=remove) + assert not retcode + project.reload() + assert "arrow" not in project.lockfile._data[lockfile_section].keys() + if sync: + assert not project.venv.is_installed("arrow") From 0c0b97427f910c78670a80688652be014bcfb3f6 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 1 Oct 2018 01:15:38 -0400 Subject: [PATCH 16/26] Monkeypatch distlib metadata to work with version 2.1 Signed-off-by: Dan Ryan --- src/passa/internals/_pip.py | 26 ++++++-------------------- src/passa/internals/_pip_shims.py | 14 ++++++++++++++ src/passa/internals/dependencies.py | 6 +++--- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/passa/internals/_pip.py b/src/passa/internals/_pip.py index da52fc6..8146df3 100644 --- a/src/passa/internals/_pip.py +++ b/src/passa/internals/_pip.py @@ -14,7 +14,6 @@ import distlib.wheel import packaging.utils import pip_shims -import setuptools.dist import six import sys import sysconfig @@ -339,15 +338,15 @@ def installation_args(self): def build_wheel(self): self.built = build_wheel(self.ireq, self.sources, self.hashes) - self.metadata = read_wheel_metadata(self.built) + self.metadata = self.built.metadata self.is_wheel = True def build_sdist(self): finder = _get_finder(self.sources) - self.ireq.populate_link(finder, True, False) + self.ireq.populate_link(finder, False, False) self.ireq.ensure_has_source_dir(self.src_dir) self.built = get_sdist(self.ireq) - self.metadata = read_sdist_metadata(self.built) + self.metadata = read_sdist_metadata(self.ireq) def install_wheel(self): scripts = distlib.scripts.ScriptMaker(None, None) @@ -381,7 +380,7 @@ def __init__(self, *args, **kwargs): def prepare(self): try: self.build_wheel() - except WheelBuildError: + except (WheelBuildError, distlib.metadata.MetadataConflictError): self.build_sdist() if not self.built or not self.metadata: raise @@ -484,21 +483,8 @@ def get_sdist(ireq): return distlib.database.EggInfoDistribution(egg_info_dir) -def read_sdist_metadata(sdist): - if not getattr(sdist, "metadata", None): - sdist = get_sdist(sdist) +def read_sdist_metadata(ireq): + sdist = get_sdist(ireq) if not sdist: return None return sdist.metadata - - -def read_wheel_metadata(wheel): - metadata = None - try: - metadata = wheel.metadata - except distlib.metadata.MetadataConflictError: - import zipfile - metadata = wheel.get_wheel_metadata( - zipfile.ZipFile(os.path.join(wheel.dirname, wheel.filename)) - ) - return metadata diff --git a/src/passa/internals/_pip_shims.py b/src/passa/internals/_pip_shims.py index 243675d..112bbc6 100644 --- a/src/passa/internals/_pip_shims.py +++ b/src/passa/internals/_pip_shims.py @@ -11,7 +11,18 @@ from __future__ import absolute_import, unicode_literals +import distlib.metadata import pip_shims +import recursive_monkey_patch + + +class LegacyMetadata(): + def set_metadata_version(self): + metadata_version = self._fields.get("Metadata-Version") + if metadata_version == "2.1": + self._fields["Metadata-Version"] = metadata_version + else: + self._fields['Metadata-Version'] = distlib.metadata._best_version(self._fields) def _build_wheel_pre10(ireq, output_dir, finder, wheel_cache, kwargs): @@ -68,3 +79,6 @@ def _unpack_url_pre10(*args, **kwargs): "f.close();" "exec(compile(code, __file__, 'exec'))" ) + + +recursive_monkey_patch.monkey_patch(LegacyMetadata, distlib.metadata.LegacyMetadata) diff --git a/src/passa/internals/dependencies.py b/src/passa/internals/dependencies.py index b163b85..6ad5629 100644 --- a/src/passa/internals/dependencies.py +++ b/src/passa/internals/dependencies.py @@ -15,7 +15,7 @@ from ..models.caches import DependencyCache, RequiresPythonCache from ._pip import ( - WheelBuildError, build_wheel, get_sdist, read_wheel_metadata, read_sdist_metadata + WheelBuildError, build_wheel, get_sdist, read_sdist_metadata ) from .markers import contains_extra, get_contained_extras, get_without_extra from .utils import get_pinned_version, is_pinned @@ -234,11 +234,11 @@ def _get_dependencies_from_pip(ireq, sources): # been downloaded, extracted into `ireq.source_dir`, and partially # built (hopefully containing .egg-info). built = get_sdist(ireq) - metadata = read_sdist_metadata(built) + metadata = read_sdist_metadata(ireq) if not metadata: raise else: - metadata = read_wheel_metadata(built) + metadata = built.metadata requirements = _read_requirements(metadata, extras) requires_python = _read_requires_python(metadata) return requirements, requires_python From ecd20ffbdf6e7b04dff2ffc6e2dc2aad4e393b02 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 1 Oct 2018 17:08:33 -0400 Subject: [PATCH 17/26] Update lockfile Signed-off-by: Dan Ryan --- Pipfile.lock | 297 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 228 insertions(+), 69 deletions(-) diff --git a/Pipfile.lock b/Pipfile.lock index c83e057..473a2d4 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -19,7 +19,7 @@ "sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92", "sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", "version": "==1.4.3" }, "attrs": { @@ -27,7 +27,7 @@ "sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69", "sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", "version": "==18.2.0" }, "backports-shutil-get-terminal-size": { @@ -69,10 +69,10 @@ }, "distlib": { "hashes": [ - "sha256:cd502c66fc27c535bab62dc4f482e403e2369c2c05281a79cc2d4e2f42a87f20" + "sha256:57977cd7d9ea27986ec62f425630e4ddb42efe651ff80bc58ed8dbc3c7c21f19" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.2.7" + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.2.8" }, "enum34": { "hashes": [ @@ -89,7 +89,7 @@ "sha256:3bb3de3582cb27071cfb514f00ed784dc444b7f96dc21e140de65fe00585c95e", "sha256:41d5b64e70507d0c3ca742d68010a76060eea8a3d863e9b5130ab11a4a91aa0e" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.0.1" }, "idna": { @@ -107,6 +107,14 @@ "markers": "python_version < '2.7' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.0.4" }, + "installer": { + "hashes": [ + "sha256:1ba23de573e9b95a8dcbd04fd026c40a64b77db0aadc48f28a844b4cb87479fe", + "sha256:f4f195c9b17ea7d2b631a758451485c6b080975349b4adebe45ef4bb022db069" + ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.1.1" + }, "modutil": { "hashes": [ "sha256:2c85c1666649e92e56de17c00e1e831313602d9b55e8661d39c01e39003b45f7", @@ -115,13 +123,21 @@ "markers": "python_version >= '2.6' and python_version >= '3.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.0.0" }, + "packagebuilder": { + "hashes": [ + "sha256:1e85c4e0e994322996b93cd6685c12834d30f3558889154f8e3de8fb1f3fd1e7", + "sha256:dc525d06ecd102db23ab421b879d7d27021d784ff933e33e8c411a53af5c9dbe" + ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.1.0" + }, "packaging": { "hashes": [ - "sha256:e9215d2d2535d3ae866c3d6efc77d5b24a0192cce0ff20e42896cc0664f889c0", - "sha256:f019b770dd64e585a99714f1fd5e01c7a8f11b45635aa953fd41c689a657375b" + "sha256:0886227f54515e592aaa2e5a553332c73962917f2831f1b0f9b9f4380a4b9807", + "sha256:f95a1e147590f204328170981833854229bb2912ac3d5f89e2a8ccd2834800c9" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==17.1" + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==18.0" }, "passa": { "editable": true, @@ -157,11 +173,11 @@ }, "pyparsing": { "hashes": [ - "sha256:0832bcf47acd283788593e7a0f542407bd9550a55a8a8435214a1960e04bcb04", - "sha256:fee43f17a9c4087e7ed1605bd6df994c6173c1e977d7ade7b651292fab2bd010" + "sha256:bc6c7146b91af3f567cf6daeaec360bc07d45ffec4cf5353f4d7a208ce7ca30a", + "sha256:d29593d8ebe7b57d6967b62494f8c72b03ac0262b1eed63826c6f788b3606401" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.2.0" + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.2.2" }, "requests": { "hashes": [ @@ -176,7 +192,7 @@ "sha256:90151d8963f814e17190e067b60e92fb35fd1bc46c99f8dba3d7b0d93a3dd958", "sha256:c3aeaa4e0b80843ba65a68878293e07ea52a8d0706dbba86b02dad6cd20ef2dd" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.1.6" }, "resolvelib": { @@ -209,7 +225,6 @@ "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" ], - "markers": "python_version < '3.5' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version < '3.5' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.11.0" }, "toml": { @@ -233,7 +248,7 @@ "sha256:57dcf675a99b74d64dacf6fba08fb17cf7e3d5fdff53d4a30ea2a5e7e52543d4", "sha256:a4c8473ce11a65999c8f59cb093e70686b6c84c98df58c1dae9b3b196089858a" ], - "markers": "python_version < '3.5' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version < '3.5' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "(python_version >= '2.7' and python_version < '2.8') or (python_version >= '3.4' and python_version < '3.5') and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or (python_version >= '2.7' and python_version < '2.8') or (python_version >= '3.4' and python_version < '3.5') and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==3.6.6" }, "urllib3": { @@ -244,6 +259,14 @@ "markers": "python_version < '4' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.23" }, + "virtualenv": { + "hashes": [ + "sha256:2ce32cd126117ce2c539f0134eb89de91a8413a29baac49cbab3eb50e2026669", + "sha256:ca07b4c0b54e14a91af9f34d0919790b016923d157afda5efdde55c96718f752" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==16.0.0" + }, "vistir": { "extras": [ "spinner" @@ -257,11 +280,11 @@ }, "wheel": { "hashes": [ - "sha256:0a2e54558a0628f2145d2fc822137e322412115173e8a2ddbe1c9024338ae83c", - "sha256:80044e51ec5bbf6c894ba0bc48d26a8c20a9ba629f4ca19ea26ecfcf87685f5f" + "sha256:3970f4130b7f8bf8167ca09215c8cc2f49a87c3d46506adfc60cb08c47ab0949", + "sha256:a26bc27230baaec9039972b7cb43db94b17c13e4d66a9ff6a4d46a0344c55c9a" ], "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.31.1" + "version": "==0.32.0" }, "yaspin": { "hashes": [ @@ -294,17 +317,9 @@ "sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92", "sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", "version": "==1.4.3" }, - "argparse": { - "hashes": [ - "sha256:62b089a55be1d8949cd2bc7e0df0bddb9e028faefc8c32038cc84862aefdd6e4", - "sha256:c31647edb69fd3d465a847ea3157d37bed1f95f19760b11a47aa91c04b666314" - ], - "markers": "python_version == '2.6'", - "version": "==1.4.0" - }, "arpeggio": { "hashes": [ "sha256:a5258b84f76661d558492fa87e42db634df143685a0e51802d59cae7daad8732", @@ -326,7 +341,7 @@ "sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69", "sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", "version": "==18.2.0" }, "babel": { @@ -353,11 +368,27 @@ }, "black": { "hashes": [ - "sha256:22158b89c1a6b4eb333a1e65e791a3f8b998cf3b11ae094adb2570f31f769a44", - "sha256:4b475bbd528acce094c503a3d2dbc2d05a4075f6d0ef7d9e7514518e14cc5191" + "sha256:817243426042db1d36617910df579a54f1afd659adb96fc5032fcf4b36209739", + "sha256:e030a9a28f542debc08acceb273f228ac422798e5215ba2a791a6ddeaaca22a5" ], "markers": "python_version >= '3.6'", - "version": "==18.6b4" + "version": "==18.9b0" + }, + "bleach": { + "hashes": [ + "sha256:0ee95f6167129859c5dce9b1ca291ebdb5d8cd7e382ca0e237dfd0dad63f63d8", + "sha256:24754b9a7d530bf30ce7cbc805bc6cce785660b4a10ff3a43633728438c105ab" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.1.4" + }, + "cached-property": { + "hashes": [ + "sha256:3a026f1a54135677e7da5ce819b0c690f156f37976f3e30c5430740725203d7f", + "sha256:9217a59f14a5682da7c4b8829deadbfc194ac22e9908ccf7c8820234e80a1504" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==1.5.1" }, "cerberus": { "hashes": [ @@ -374,6 +405,43 @@ "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2018.8.24" }, + "cffi": { + "hashes": [ + "sha256:151b7eefd035c56b2b2e1eb9963c90c6302dc15fbd8c1c0a83a163ff2c7d7743", + "sha256:1553d1e99f035ace1c0544050622b7bc963374a00c467edafac50ad7bd276aef", + "sha256:1b0493c091a1898f1136e3f4f991a784437fac3673780ff9de3bcf46c80b6b50", + "sha256:2ba8a45822b7aee805ab49abfe7eec16b90587f7f26df20c71dd89e45a97076f", + "sha256:3bb6bd7266598f318063e584378b8e27c67de998a43362e8fce664c54ee52d30", + "sha256:3c85641778460581c42924384f5e68076d724ceac0f267d66c757f7535069c93", + "sha256:3eb6434197633b7748cea30bf0ba9f66727cdce45117a712b29a443943733257", + "sha256:495c5c2d43bf6cebe0178eb3e88f9c4aa48d8934aa6e3cddb865c058da76756b", + "sha256:4c91af6e967c2015729d3e69c2e51d92f9898c330d6a851bf8f121236f3defd3", + "sha256:57b2533356cb2d8fac1555815929f7f5f14d68ac77b085d2326b571310f34f6e", + "sha256:770f3782b31f50b68627e22f91cb182c48c47c02eb405fd689472aa7b7aa16dc", + "sha256:79f9b6f7c46ae1f8ded75f68cf8ad50e5729ed4d590c74840471fc2823457d04", + "sha256:7a33145e04d44ce95bcd71e522b478d282ad0eafaf34fe1ec5bbd73e662f22b6", + "sha256:857959354ae3a6fa3da6651b966d13b0a8bed6bbc87a0de7b38a549db1d2a359", + "sha256:87f37fe5130574ff76c17cab61e7d2538a16f843bb7bca8ebbc4b12de3078596", + "sha256:95d5251e4b5ca00061f9d9f3d6fe537247e145a8524ae9fd30a2f8fbce993b5b", + "sha256:9d1d3e63a4afdc29bd76ce6aa9d58c771cd1599fbba8cf5057e7860b203710dd", + "sha256:a36c5c154f9d42ec176e6e620cb0dd275744aa1d804786a71ac37dc3661a5e95", + "sha256:a6a5cb8809091ec9ac03edde9304b3ad82ad4466333432b16d78ef40e0cce0d5", + "sha256:ae5e35a2c189d397b91034642cb0eab0e346f776ec2eb44a49a459e6615d6e2e", + "sha256:b0f7d4a3df8f06cf49f9f121bead236e328074de6449866515cea4907bbc63d6", + "sha256:b75110fb114fa366b29a027d0c9be3709579602ae111ff61674d28c93606acca", + "sha256:ba5e697569f84b13640c9e193170e89c13c6244c24400fc57e88724ef610cd31", + "sha256:be2a9b390f77fd7676d80bc3cdc4f8edb940d8c198ed2d8c0be1319018c778e1", + "sha256:ca1bd81f40adc59011f58159e4aa6445fc585a32bb8ac9badf7a2c1aa23822f2", + "sha256:d5d8555d9bfc3f02385c1c37e9f998e2011f0db4f90e250e5bc0c0a85a813085", + "sha256:e55e22ac0a30023426564b1059b035973ec82186ddddbac867078435801c7801", + "sha256:e90f17980e6ab0f3c2f3730e56d1fe9bcba1891eeea58966e89d352492cc74f4", + "sha256:ecbb7b01409e9b782df5ded849c178a0aa7c906cf8c5a67368047daab282b184", + "sha256:ed01918d545a38998bfa5902c7c00e0fee90e957ce036a4000a88e3fe2264917", + "sha256:edabd457cd23a02965166026fd9bfd196f4324fe6032e866d0f3bd0301cd486f", + "sha256:fdf1c1dc5bafc32bc5d08b054f94d659422b05aba244d6be4ddc1c72d9aa70fb" + ], + "version": "==1.11.5" + }, "chardet": { "hashes": [ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", @@ -384,10 +452,44 @@ }, "click": { "hashes": [ - "sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d", - "sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b" - ], - "version": "==6.7" + "sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13", + "sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7" + ], + "markers": "python_version >= '2.7' and python_version >= '3.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==7.0" + }, + "cmarkgfm": { + "hashes": [ + "sha256:0186dccca79483e3405217993b83b914ba4559fe9a8396efc4eea56561b74061", + "sha256:1a625afc6f62da428df96ec325dc30866cc5781520cbd904ff4ec44cf018171c", + "sha256:207b7673ff4e177374c572feeae0e4ef33be620ec9171c08fd22e2b796e03e3d", + "sha256:275905bb371a99285c74931700db3f0c078e7603bed383e8cf1a09f3ee05a3de", + "sha256:50098f1c4950722521f0671e54139e0edc1837d63c990cf0f3d2c49607bb51a2", + "sha256:50ed116d0b60a07df0dc7b180c28569064b9d37d1578d4c9021cff04d725cb63", + "sha256:61a72def110eed903cd1848245897bcb80d295cd9d13944d4f9f30cba5b76655", + "sha256:64186fb75d973a06df0e6ea12879533b71f6e7ba1ab01ffee7fc3e7534758889", + "sha256:665303d34d7f14f10d7b0651082f25ebf7107f29ef3d699490cac16cdc0fc8ce", + "sha256:70b18f843aec58e4e64aadce48a897fe7c50426718b7753aaee399e72df64190", + "sha256:761ee7b04d1caee2931344ac6bfebf37102ffb203b136b676b0a71a3f0ea3c87", + "sha256:811527e9b7280b136734ed6cb6845e5fbccaeaa132ddf45f0246cbe544016957", + "sha256:987b0e157f70c72a84f3c2f9ef2d7ab0f26c08f2bf326c12c087ff9eebcb3ff5", + "sha256:9fc6a2183d0a9b0974ec7cdcdad42bd78a3be674cc3e65f87dd694419b3b0ab7", + "sha256:a3d17ee4ae739fe16f7501a52255c2e287ac817cfd88565b9859f70520afffea", + "sha256:ba5b5488719c0f2ced0aa1986376f7baff1a1653a8eb5fdfcf3f84c7ce46ef8d", + "sha256:c573ea89dd95d41b6d8cf36799c34b6d5b1eac4aed0212dee0f0a11fb7b01e8f", + "sha256:c5f1b9e8592d2c448c44e6bc0d91224b16ea5f8293908b1561de1f6d2d0658b1", + "sha256:cbe581456357d8f0674d6a590b1aaf46c11d01dd0a23af147a51a798c3818034", + "sha256:cf219bec69e601fe27e3974b7307d2f06082ab385d42752738ad2eb630a47d65", + "sha256:cf5014eb214d814a83a7a47407272d5db10b719dbeaf4d3cfe5969309d0fcf4b", + "sha256:d08bad67fa18f7e8ff738c090628ee0cbf0505d74a991c848d6d04abfe67b697", + "sha256:d6f716d7b1182bf35862b5065112f933f43dd1aa4f8097c9bcfb246f71528a34", + "sha256:e08e479102627641c7cb4ece421c6ed4124820b1758765db32201136762282d9", + "sha256:e20ac21418af0298437d29599f7851915497ce9f2866bc8e86b084d8911ee061", + "sha256:e25f53c37e319241b9a412382140dffac98ca756ba8f360ac7ab5e30cad9670a", + "sha256:e8932bddf159064f04e946fbb64693753488de21586f20e840b3be51745c8c09", + "sha256:f20900f16377f2109783ae9348d34bc80530808439591c3d3df73d5c7ef1a00c" + ], + "version": "==0.4.2" }, "colorama": { "hashes": [ @@ -436,10 +538,10 @@ }, "distlib": { "hashes": [ - "sha256:cd502c66fc27c535bab62dc4f482e403e2369c2c05281a79cc2d4e2f42a87f20" + "sha256:57977cd7d9ea27986ec62f425630e4ddb42efe651ff80bc58ed8dbc3c7c21f19" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.2.7" + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.2.8" }, "docutils": { "hashes": [ @@ -447,7 +549,6 @@ "sha256:51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274", "sha256:7a4bd47eaf6596e1295ecb11361139febe29b084a87bf005bf899f9a42edc3c6" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.14" }, "enum34": { @@ -473,7 +574,7 @@ "sha256:3bb3de3582cb27071cfb514f00ed784dc444b7f96dc21e140de65fe00585c95e", "sha256:41d5b64e70507d0c3ca742d68010a76060eea8a3d863e9b5130ab11a4a91aa0e" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.0.1" }, "funcsigs": { @@ -484,6 +585,20 @@ "markers": "python_version < '3.0' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.0.2" }, + "future": { + "hashes": [ + "sha256:e39ced1ab767b5936646cedba8bcce582398233d6a627067d4c6a454c90cfedb" + ], + "version": "==0.16.0" + }, + "html5lib": { + "hashes": [ + "sha256:20b159aa3badc9d5ee8f5c647e5efd02ed2a66ab8d354930bd9ff139fc1dc0a3", + "sha256:66cb0dcfdbbc4f9c3ba1a63fdb511ffdbd4f513b2b6d81b80cd26ce6b3fb3736" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==1.0.1" + }, "idna": { "hashes": [ "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e", @@ -514,6 +629,14 @@ ], "version": "==17.5.0" }, + "installer": { + "hashes": [ + "sha256:1ba23de573e9b95a8dcbd04fd026c40a64b77db0aadc48f28a844b4cb87479fe", + "sha256:f4f195c9b17ea7d2b631a758451485c6b080975349b4adebe45ef4bb022db069" + ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.1.1" + }, "invoke": { "hashes": [ "sha256:4f4de934b15c2276caa4fbc5a3b8a61c0eb0b234f2be1780d2b793321995c2d6", @@ -559,13 +682,21 @@ "markers": "python_version < '3.0' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.1" }, + "packagebuilder": { + "hashes": [ + "sha256:1e85c4e0e994322996b93cd6685c12834d30f3558889154f8e3de8fb1f3fd1e7", + "sha256:dc525d06ecd102db23ab421b879d7d27021d784ff933e33e8c411a53af5c9dbe" + ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.1.0" + }, "packaging": { "hashes": [ - "sha256:e9215d2d2535d3ae866c3d6efc77d5b24a0192cce0ff20e42896cc0664f889c0", - "sha256:f019b770dd64e585a99714f1fd5e01c7a8f11b45635aa953fd41c689a657375b" + "sha256:0886227f54515e592aaa2e5a553332c73962917f2831f1b0f9b9f4380a4b9807", + "sha256:f95a1e147590f204328170981833854229bb2912ac3d5f89e2a8ccd2834800c9" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==17.1" + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==18.0" }, "parver": { "hashes": [ @@ -633,29 +764,35 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.6.0" }, + "pycparser": { + "hashes": [ + "sha256:a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.19" + }, "pygments": { "hashes": [ "sha256:78f3f434bcc5d6ee09020f92ba487f95ba50f1e3ef83ae96b9d5ffa1bab25c5d", "sha256:dbae1046def0efb574852fab9e90209b23f556367b5a320c0bcb871c77c3e8cc" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.2.0" }, "pyparsing": { "hashes": [ - "sha256:0832bcf47acd283788593e7a0f542407bd9550a55a8a8435214a1960e04bcb04", - "sha256:fee43f17a9c4087e7ed1605bd6df994c6173c1e977d7ade7b651292fab2bd010" + "sha256:bc6c7146b91af3f567cf6daeaec360bc07d45ffec4cf5353f4d7a208ce7ca30a", + "sha256:d29593d8ebe7b57d6967b62494f8c72b03ac0262b1eed63826c6f788b3606401" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.2.0" + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==2.2.2" }, "pytest": { "hashes": [ - "sha256:453cbbbe5ce6db38717d282b758b917de84802af4288910c12442984bde7b823", - "sha256:a8a07f84e680482eb51e244370aaf2caa6301ef265f37c2bdefb3dd3b663f99d" + "sha256:0a72d8a9f559c006ba153e0c9b4838efd7b656cf1f993747ba7128770d6eb12c", + "sha256:95529588ff4e85114a0b0ad8e9cf0131ca47d46b28230e25366c5aba66b1d854" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==3.8.0" + "version": "==3.8.1" }, "pytest-cov": { "hashes": [ @@ -683,11 +820,11 @@ }, "pytest-xdist": { "hashes": [ - "sha256:0875deac20f6d96597036bdf63970887a6f36d28289c2f6682faf652dfea687b", - "sha256:28e25e79698b2662b648319d3971c0f9ae0e6500f88258ccb9b153c31110ba9b" + "sha256:06aa39361694c9365baaa03bec71159b59ad06c9826c6279ebba368cb3571561", + "sha256:1ef0d05c905cfa0c5442c90e9e350e65c6ada120e33a00a066ca51c89f5f869a" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.23.0" + "version": "==1.23.2" }, "pytz": { "hashes": [ @@ -697,6 +834,13 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2018.5" }, + "readme-renderer": { + "hashes": [ + "sha256:237ca8705ffea849870de41101dba41543561da05c0ae45b2f1c547efa9843d2", + "sha256:f75049a3a7afa57165551e030dd8f9882ebf688b9600535a3f7e23596651875d" + ], + "version": "==22.0" + }, "requests": { "hashes": [ "sha256:63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1", @@ -717,7 +861,7 @@ "sha256:90151d8963f814e17190e067b60e92fb35fd1bc46c99f8dba3d7b0d93a3dd958", "sha256:c3aeaa4e0b80843ba65a68878293e07ea52a8d0706dbba86b02dad6cd20ef2dd" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.1.6" }, "resolvelib": { @@ -750,7 +894,6 @@ "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" ], - "markers": "python_version < '3.5' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version < '3.5' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.11.0" }, "snowballstemmer": { @@ -763,11 +906,11 @@ }, "sphinx": { "hashes": [ - "sha256:95acd6648902333647a0e0564abdb28a74b0a76d2333148aa35e5ed1f56d3c4b", - "sha256:c091dbdd5cc5aac6eb95d591a819fd18bccec90ffb048ec465b165a48b839b45" + "sha256:652eb8c566f18823a022bb4b6dbc868d366df332a11a0226b5bc3a798a479f17", + "sha256:d222626d8356de702431e813a05c68a35967e3d66c6cd1c2c89539bb179a7464" ], "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.8.0" + "version": "==1.8.1" }, "sphinx-rtd-theme": { "hashes": [ @@ -816,10 +959,10 @@ }, "twine": { "hashes": [ - "sha256:08eb132bbaec40c6d25b358f546ec1dc96ebd2638a86eea68769d9e67fe2b129", - "sha256:2fd9a4d9ff0bcacf41fdc40c8cb0cfaef1f1859457c9653fd1b92237cc4e9f25" + "sha256:7d89bc6acafb31d124e6e5b295ef26ac77030bf098960c2a4c4e058335827c5c", + "sha256:fad6f1251195f7ddd1460cb76d6ea106c93adb4e56c41e0da79658e56e547d2c" ], - "version": "==1.11.0" + "version": "==1.12.1" }, "typing": { "hashes": [ @@ -827,7 +970,7 @@ "sha256:57dcf675a99b74d64dacf6fba08fb17cf7e3d5fdff53d4a30ea2a5e7e52543d4", "sha256:a4c8473ce11a65999c8f59cb093e70686b6c84c98df58c1dae9b3b196089858a" ], - "markers": "python_version < '3.5' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version < '3.5' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "markers": "(python_version >= '2.7' and python_version < '2.8') or (python_version >= '3.4' and python_version < '3.5') and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or (python_version >= '2.7' and python_version < '2.8') or (python_version >= '3.4' and python_version < '3.5') and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==3.6.6" }, "urllib3": { @@ -838,6 +981,14 @@ "markers": "python_version < '4' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.23" }, + "virtualenv": { + "hashes": [ + "sha256:2ce32cd126117ce2c539f0134eb89de91a8413a29baac49cbab3eb50e2026669", + "sha256:ca07b4c0b54e14a91af9f34d0919790b016923d157afda5efdde55c96718f752" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==16.0.0" + }, "vistir": { "extras": [ "spinner" @@ -849,13 +1000,21 @@ "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.1.6" }, + "webencodings": { + "hashes": [ + "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78", + "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.5.1" + }, "wheel": { "hashes": [ - "sha256:0a2e54558a0628f2145d2fc822137e322412115173e8a2ddbe1c9024338ae83c", - "sha256:80044e51ec5bbf6c894ba0bc48d26a8c20a9ba629f4ca19ea26ecfcf87685f5f" + "sha256:3970f4130b7f8bf8167ca09215c8cc2f49a87c3d46506adfc60cb08c47ab0949", + "sha256:a26bc27230baaec9039972b7cb43db94b17c13e4d66a9ff6a4d46a0344c55c9a" ], "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.31.1" + "version": "==0.32.0" }, "yaspin": { "hashes": [ From cc5eddd6a6647ed84adfe5511cd056d49e1c0268 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 1 Oct 2018 19:24:14 -0400 Subject: [PATCH 18/26] Update pipfile and lockfile Signed-off-by: Dan Ryan --- Pipfile | 2 +- Pipfile.lock | 31 +++++++++++++++++++++++++++---- setup.cfg | 9 +++++---- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Pipfile b/Pipfile index 25ed7ee..51464ab 100644 --- a/Pipfile +++ b/Pipfile @@ -1,5 +1,5 @@ [packages] -passa = { editable = true, path = '.' } +passa = { editable = true, path = '.', extras = ['virtualenv'] } [dev-packages] black = '*' diff --git a/Pipfile.lock b/Pipfile.lock index 473a2d4..4564203 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "ff353680e286436d85c9b1b00ccb7ee257cb2922a1eec0becf9713817605d92b" + "sha256": "994d50f9fd0acc91cf216cf0ffc1233ebbfd0a411b57320f44a0f4487943e546" }, "pipfile-spec": 6, "requires": {}, @@ -44,6 +44,14 @@ "markers": "python_version < '3.3' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.0.post1" }, + "cached-property": { + "hashes": [ + "sha256:3a026f1a54135677e7da5ce819b0c690f156f37976f3e30c5430740725203d7f", + "sha256:9217a59f14a5682da7c4b8829deadbfc194ac22e9908ccf7c8820234e80a1504" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==1.5.1" + }, "cerberus": { "hashes": [ "sha256:f5c2e048fb15ecb3c088d192164316093fcfa602a74b3386eefb2983aa7e800a" @@ -141,8 +149,8 @@ }, "passa": { "editable": true, - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "path": "." + "path": ".", + "extras": ["virtualenv"] }, "pathlib2": { "hashes": [ @@ -179,6 +187,14 @@ "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.2.2" }, + "recursive-monkey-patch": { + "hashes": [ + "sha256:546739fea5be2ea9f98b5ec44fafeb697b5cf9fdcda64a03422582ab03ee24c4", + "sha256:98922554e77f2e2c85a4f5d873a0f52efdc1b553f32444bd6c788b2ff583bf3e" + ], + "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.4.0" + }, "requests": { "hashes": [ "sha256:63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1", @@ -675,6 +691,14 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==4.3.0" }, + "mork": { + "hashes": [ + "sha256:13772edb4724915cf0cfa30d31426e0565487a3b2d7883b8468718eaed8ecfc2", + "sha256:b1b41bc31603eef1b50e42e75ae2d74d7a0d9ab46ea4d0dd1ba387a451870873" + ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.1.4" + }, "ordereddict": { "hashes": [ "sha256:1c35b4ac206cef2d24816c89f89cf289dd3d38cf7c449bb3fab7bf6d43f01b1f" @@ -711,7 +735,6 @@ "extras": [ "tests" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "path": "." }, "pathlib2": { diff --git a/setup.cfg b/setup.cfg index 194cc04..097fa9b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,15 +37,17 @@ python_requires = >=2.7,!=3.0,!=3.1,!=3.2,!=3.3 setup_requires = setuptools>=36.2.2 install_requires = appdirs + cached-property distlib - packaging - packagebuilder installer + packagebuilder + packaging pip-shims>=0.1.2 plette[validation]>=0.2.2 + recursive-monkey-patch requests - resolvelib>=0.2.1,!=1.0.0.dev0 requirementslib>=1.1.1 + resolvelib>=0.2.1,!=1.0.0.dev0 six virtualenv vistir[spinner]>=0.1.4 @@ -57,7 +59,6 @@ pack = virtualenv = mork tests = - cached-property pytest-xdist pytest-timeout pytest-cov From c4b90cef73b303f51891e8f6f076f475cab9e9b8 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 1 Oct 2018 20:32:44 -0400 Subject: [PATCH 19/26] Fix packing Signed-off-by: Dan Ryan --- Pipfile.lock | 8 ++++++++ tasks/package.py | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Pipfile.lock b/Pipfile.lock index 4564203..8eb9676 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -131,6 +131,14 @@ "markers": "python_version >= '2.6' and python_version >= '3.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.0.0" }, + "mork": { + "hashes": [ + "sha256:13772edb4724915cf0cfa30d31426e0565487a3b2d7883b8468718eaed8ecfc2", + "sha256:b1b41bc31603eef1b50e42e75ae2d74d7a0d9ab46ea4d0dd1ba387a451870873" + ], + "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", + "version": "==0.1.4" + }, "packagebuilder": { "hashes": [ "sha256:1e85c4e0e994322996b93cd6685c12834d30f3558889154f8e3de8fb1f3fd1e7", diff --git a/tasks/package.py b/tasks/package.py index f229e3a..bba878b 100644 --- a/tasks/package.py +++ b/tasks/package.py @@ -22,7 +22,6 @@ 'importlib', # We only support 2.7 so this is not needed. 'modutil', # This breaks <3.7. - 'toml', # Why is requirementslib still not dropping it? 'typing', # This breaks 2.7. We'll provide a special stub for it. } From 4b6cb33866464dfdc6db2319dd26fbe03403591e Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 8 Oct 2018 23:23:59 -0400 Subject: [PATCH 20/26] Add general environment construct - Implement it by default throughout - Implement it for testing - Monkeypatch `UninstallPathSet` to work properly with it Signed-off-by: Dan Ryan --- setup.cfg | 7 +- src/passa/actions/add.py | 3 +- src/passa/cli/options.py | 15 +- src/passa/internals/_pip.py | 62 ++--- src/passa/internals/_pip_shims.py | 7 +- src/passa/internals/dependencies.py | 7 +- src/passa/models/environments.py | 369 ++++++++++++++++++++++++++ src/passa/models/projects.py | 4 +- tests/actions/test_clean.py | 10 +- tests/actions/test_install.py | 12 +- tests/actions/test_remove_and_sync.py | 26 +- tests/conftest.py | 18 +- 12 files changed, 453 insertions(+), 87 deletions(-) create mode 100644 src/passa/models/environments.py diff --git a/setup.cfg b/setup.cfg index 097fa9b..51741a5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,18 +38,17 @@ setup_requires = setuptools>=36.2.2 install_requires = appdirs cached-property - distlib + distlib>=0.2.8 installer packagebuilder packaging - pip-shims>=0.1.2 + pip-shims>=0.3.1 plette[validation]>=0.2.2 recursive-monkey-patch requests - requirementslib>=1.1.1 + requirementslib>=1.1.7 resolvelib>=0.2.1,!=1.0.0.dev0 six - virtualenv vistir[spinner]>=0.1.4 [options.extras_require] diff --git a/src/passa/actions/add.py b/src/passa/actions/add.py index 49e4bce..19471de 100644 --- a/src/passa/actions/add.py +++ b/src/passa/actions/add.py @@ -47,8 +47,7 @@ def add_packages(packages=[], editables=[], project=None, dev=False, sync=False, develop = any(lockfile_diff.develop) syncer = Synchronizer( - project, default=default, develop=develop, - clean_unneeded=clean, venv=getattr(project, "venv", None) + project, default=default, develop=develop, clean_unneeded=clean ) success = sync(syncer) if not success: diff --git a/src/passa/cli/options.py b/src/passa/cli/options.py index eafa71d..f690ae3 100644 --- a/src/passa/cli/options.py +++ b/src/passa/cli/options.py @@ -10,9 +10,10 @@ import tomlkit.exceptions import passa.models.projects -import mork import vistir +from ..models.environments import Environment + PYTHON_VERSION = ".".join(str(v) for v in sys.version_info[:2]) @@ -21,23 +22,25 @@ class Project(passa.models.projects.Project): def __init__(self, root, *args, **kwargs): root = vistir.compat.Path(root).absolute() pipfile = root.joinpath("Pipfile") + environment = kwargs.pop("environment", self.get_env()) if not pipfile.is_file(): raise argparse.ArgumentError( project, "{0!r} is not a Pipfile project".format(root.as_posix()), ) - self.venv = kwargs.pop("venv", self.get_venv(root)) try: - super(Project, self).__init__(root.as_posix(), env_prefix=self.venv.venv_dir, + super(Project, self).__init__(root.as_posix(), environment=environment, *args, **kwargs) except tomlkit.exceptions.ParseError as e: raise argparse.ArgumentError( project, "failed to parse Pipfile: {0!r}".format(str(e)), ) - def get_venv(self, root): + def get_env(self): + if self.environment: + return self.environment if 'VIRTUAL_ENV' in os.environ: - return mork.VirtualEnv(os.environ['VIRTUAL_ENV']) - return mork.VirtualEnv.from_project_path(root) + return Environment(prefix=os.environ['VIRTUAL_ENV'], is_venv=True) + return Environment() def __name__(self): return "Project Root" diff --git a/src/passa/internals/_pip.py b/src/passa/internals/_pip.py index 8146df3..4ed662a 100644 --- a/src/passa/internals/_pip.py +++ b/src/passa/internals/_pip.py @@ -20,8 +20,9 @@ import vistir from ..models.caches import CACHE_DIR +from ..models.environments import Environment from ._pip_shims import ( - SETUPTOOLS_SHIM, VCS_SUPPORT, build_wheel as _build_wheel, unpack_url + SETUPTOOLS_SHIM, VCS_SUPPORT, build_wheel as _build_wheel, unpack_url, patch_pathset ) from .utils import filter_sources @@ -200,24 +201,8 @@ def build_wheel(ireq, sources, hashes=None): return distlib.wheel.Wheel(wheel_path) -def _obtrain_ref(vcs_obj, src_dir, name, rev=None): - target_dir = os.path.join(src_dir, name) - target_rev = vcs_obj.make_rev_options(rev) - if not os.path.exists(target_dir): - vcs_obj.obtain(target_dir) - if (not vcs_obj.is_commit_id_equal(target_dir, rev) and - not vcs_obj.is_commit_id_equal(target_dir, target_rev)): - vcs_obj.update(target_dir, target_rev) - return vcs_obj.get_revision(target_dir) - - def get_vcs_ref(requirement): - backend = VCS_SUPPORT.get_backend(requirement.vcs) - vcs = backend(url=requirement.req.vcs_uri) - src = _get_src_dir() - name = requirement.normalized_name - ref = _obtrain_ref(vcs, src, name, rev=requirement.req.ref) - return ref + return requirement.commit_hash def find_installation_candidates(ireq, sources): @@ -231,17 +216,24 @@ class RequirementUninstaller(object): This uses `UninstallPathSet` to control the workflow. If the inner block exits correctly, the uninstallation is committed, otherwise rolled back. """ - def __init__(self, ireq, auto_confirm, verbose): + def __init__(self, ireq, auto_confirm, verbose, env=None): self.ireq = ireq self.pathset = None self.auto_confirm = auto_confirm self.verbose = verbose + self.env = env if env else Environment() + + def check_permitted(self, pathset, path): + if self.env.is_venv and self.env.is_installed(self.ireq.name): + return True + return pathset._permitted(path) def __enter__(self): self.pathset = self.ireq.uninstall( auto_confirm=self.auto_confirm, verbose=self.verbose, ) + self.pathset._permitted = self.check_permitted return self.pathset def __exit__(self, exc_type, exc_value, traceback): @@ -294,18 +286,15 @@ def install(self): pass -class VenvInstaller(NoopInstaller): +class BaseInstaller(NoopInstaller): """Virtualenv-capable installer""" - def __init__(self, requirement, sources=None, paths=None, venv=None): + def __init__(self, requirement, sources=None, environment=None): self.ireq = requirement.as_ireq() self.sources = filter_sources(requirement, sources) self.hashes = requirement.hashes or None - self.paths = paths - self.venv = venv + self.environment = environment if environment else Environment() self.built = None - self.python = sys.executable if not self.venv else self.venv.python - self.py_version = self.venv.python_version if self.venv else sysconfig.get_python_version() self.metadata = None self.is_wheel = False @@ -328,12 +317,14 @@ def installation_args(self): setup_path = self.setup_dir.joinpath("setup.py") install_keys = ["headers", "purelib", "platlib", "scripts", "data"] install_args = [ - self.python, "-u", "-c", SETUPTOOLS_SHIM % setup_path.as_posix(), install_arg, - "--single-version-externally-managed", "--no-deps", - "--prefix={0}".format(self.paths["prefix"]) + self.environment.python, "-u", "-c", SETUPTOOLS_SHIM % setup_path.as_posix(), + install_arg, "--single-version-externally-managed", "--no-deps", + "--prefix={0}".format(self.environment.paths["prefix"]) ] for key in install_keys: - install_args.append("--install-{0}={1}".format(key, self.paths[key])) + install_args.append( + "--install-{0}={1}".format(key, self.environment.paths[key]) + ) return install_args def build_wheel(self): @@ -350,12 +341,12 @@ def build_sdist(self): def install_wheel(self): scripts = distlib.scripts.ScriptMaker(None, None) - self.built.install(self.paths, scripts) + self.built.install(self.environment.paths, scripts) def install_sdist(self): with vistir.cd(self.setup_dir.as_posix()), _suppress_distutils_logs(): - c = vistir.misc.run(self.installation_args, return_object=True, block=True, - nospin=True) + c = self.environment.run(self.installation_args, return_object=True, + block=True, nospin=True) if c.returncode != 0: err_text = "{0!r}: {1!r}".format(c.err, c.out) raise RuntimeError("Failed to install package: {0!r}".format(err_text)) @@ -365,14 +356,11 @@ def prepare(self): pass def install(self): - if self.venv: - with self.venv.activated(): - self._install() - else: + with self.environment.activated(): self._install() -class SdistInstaller(VenvInstaller): +class SdistInstaller(BaseInstaller): """Installer for SDists""" def __init__(self, *args, **kwargs): super(SdistInstaller, self).__init__(*args, **kwargs) diff --git a/src/passa/internals/_pip_shims.py b/src/passa/internals/_pip_shims.py index 112bbc6..87d0904 100644 --- a/src/passa/internals/_pip_shims.py +++ b/src/passa/internals/_pip_shims.py @@ -12,11 +12,12 @@ from __future__ import absolute_import, unicode_literals import distlib.metadata +import importlib import pip_shims import recursive_monkey_patch -class LegacyMetadata(): +class LegacyMetadata(object): def set_metadata_version(self): metadata_version = self._fields.get("Metadata-Version") if metadata_version == "2.1": @@ -58,8 +59,8 @@ def _unpack_url_pre10(*args, **kwargs): return pip_shims.unpack_url(*args, **kwargs) -PIP_VERSION = pip_shims.utils._parse(pip_shims.pip_version) -VERSION_10 = pip_shims.utils._parse("10") +PIP_VERSION = pip_shims._parse(pip_shims.pip_version) +VERSION_10 = pip_shims._parse("10") VCS_SUPPORT = pip_shims.VcsSupport() diff --git a/src/passa/internals/dependencies.py b/src/passa/internals/dependencies.py index 6ad5629..a2b0cbc 100644 --- a/src/passa/internals/dependencies.py +++ b/src/passa/internals/dependencies.py @@ -10,13 +10,12 @@ import packaging.utils import packaging.version import requests -import requirementslib import six +import requirementslib + from ..models.caches import DependencyCache, RequiresPythonCache -from ._pip import ( - WheelBuildError, build_wheel, get_sdist, read_sdist_metadata -) +from ._pip import WheelBuildError, build_wheel, get_sdist, read_sdist_metadata from .markers import contains_extra, get_contained_extras, get_without_extra from .utils import get_pinned_version, is_pinned diff --git a/src/passa/models/environments.py b/src/passa/models/environments.py new file mode 100644 index 0000000..bc36263 --- /dev/null +++ b/src/passa/models/environments.py @@ -0,0 +1,369 @@ +# -*- coding=utf-8 -*- + +import contextlib +import importlib +import json +import os +import sys +import sysconfig + +import pkg_resources +import six + +from cached_property import cached_property + +import vistir + + +BASE_WORKING_SET = pkg_resources.WorkingSet(sys.path) + + +class Environment(object): + def __init__(self, prefix=None, is_venv=False, base_working_set=None): + self.base_working_set = base_working_set if base_working_set else BASE_WORKING_SET + self.is_venv = is_venv + self._modules = {'pkg_resources': pkg_resources} + self.extra_dists = [] + prefix = prefix if prefix else sys.prefix + self.prefix = vistir.compat.Path(prefix) + + def safe_import(self, name): + """Helper utility for reimporting previously imported modules while inside the env""" + module = None + if name not in self._modules: + self._modules[name] = importlib.import_module(name) + module = self._modules[name] + if not module: + dist = next(iter( + dist for dist in self.base_working_set if dist.project_name == name + ), None) + if dist: + dist.activate() + module = importlib.import_module(name) + if name in sys.modules: + try: + six.moves.reload_module(module) + six.moves.reload_module(sys.modules[name]) + except TypeError: + del sys.modules[name] + sys.modules[name] = self._modules[name] + return module + + @classmethod + def resolve_dist(cls, dist, working_set): + """Given a local distribution and a working set, returns all dependencies from the set. + + :param dist: A single distribution to find the dependencies of + :type dist: :class:`pkg_resources.Distribution` + :param working_set: A working set to search for all packages + :type working_set: :class:`pkg_resources.WorkingSet` + :return: A set of distributions which the package depends on, including the package + :rtype: set(:class:`pkg_resources.Distribution`) + """ + + deps = set() + deps.add(dist) + try: + reqs = dist.requires() + except AttributeError: + return deps + for req in reqs: + dist = working_set.find(req) + deps |= cls.resolve_dist(dist, working_set) + return deps + + def add_dist(self, dist_name): + dist = pkg_resources.get_distribution(pkg_resources.Requirement(dist_name)) + extras = self.resolve_dist(dist, self.base_working_set) + if extras: + self.extra_dists.extend(extras) + + @cached_property + def python_version(self): + with self.activated(): + sysconfig = self.safe_import("sysconfig") + py_version = sysconfig.get_python_version() + return py_version + + @property + def python_info(self): + include_dir = self.prefix / "include" + python_path = next(iter(list(include_dir.iterdir())), None) + if python_path and python_path.name.startswith("python"): + python_version = python_path.name.replace("python", "") + py_version_short, abiflags = python_version[:3], python_version[3:] + return {"py_version_short": py_version_short, "abiflags": abiflags} + return {} + + @cached_property + def base_paths(self): + sysconfig = self.safe_import("sysconfig") + prefix = self.prefix.as_posix() + scheme = sysconfig._get_default_scheme() + config = { + "base": prefix, + "installed_base": prefix, + "platbase": prefix, + "installed_platbase": prefix + } + config.update(self.python_info) + paths = { + k: v.format(**config) + for k, v in sysconfig._INSTALL_SCHEMES[scheme].items() + } + if "prefix" not in paths: + paths["prefix"] = prefix + return paths + + @cached_property + def script_basedir(self): + """Path to the environment scripts dir""" + script_dir = os.path.basename(sysconfig.get_paths()["scripts"]) + return script_dir + + @property + def python(self): + """Path to the environment python""" + return self.prefix.joinpath(self.script_basedir).joinpath("python").as_posix() + + @cached_property + def sys_path(self): + """The system path inside the environment + + :return: The :data:`sys.path` from the environment + :rtype: list + """ + + current_executable = vistir.compat.Path(sys.executable).as_posix() + if self.python == current_executable: + return sys.path + cmd_args = [self.python, "-c", "import json, sys; print(json.dumps(sys.path))"] + path = vistir.misc.run(cmd_args, return_object=True, nospin=True, block=True) + path = json.loads(path.out.strip()) + return path + + @cached_property + def system_paths(self): + paths = {} + sysconfig = self.safe_import("sysconfig") + paths = sysconfig.get_paths() + return paths + + @cached_property + def sys_prefix(self): + """The prefix run inside the context of the environment + + :return: The python prefix inside the environment + :rtype: :data:`sys.prefix` + """ + + command = [self.python, "-c" "import sys; print(sys.prefix)"] + c = vistir.misc.run(command, return_object=True, block=True, nospin=True) + sys_prefix = vistir.compat.Path(vistir.misc.to_text(c.out).strip()).as_posix() + return sys_prefix + + @cached_property + def paths(self): + paths = {} + with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): + os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.prefix.as_posix()) + os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") + os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") + paths = self.base_paths + if "headers" not in paths: + paths["headers"] = paths["include"] + return paths + + @property + def scripts_dir(self): + return self.paths["scripts"] + + @property + def libdir(self): + purelib = self.paths.get("purelib", None) + if purelib and os.path.exists(purelib): + return "purelib", purelib + return "platlib", self.paths["platlib"] + + def get_distributions(self): + """Retrives the distributions installed on the library path of the environment + + :return: A set of distributions found on the library path + :rtype: iterator + """ + + pkg_resources = self.safe_import("pkg_resources") + return pkg_resources.find_distributions(self.paths["purelib"], only=True) + + def get_working_set(self): + """Retrieve the working set of installed packages for the environment. + + :return: The working set for the environment + :rtype: :class:`pkg_resources.WorkingSet` + """ + + working_set = None + import pkg_resources + working_set = pkg_resources.WorkingSet(self.sys_path) + return working_set + + def is_installed(self, pkgname): + """Given a package name, returns whether it is installed in the environment + + :param str pkgname: The name of a package + :return: Whether the supplied package is installed in the environment + :rtype: bool + """ + + return any(d for d in self.get_distributions() if d.project_name == pkgname) + + def run(self, cmd, cwd=os.curdir): + """Run a command with :class:`~subprocess.Popen` in the context of the environment + + :param cmd: A command to run in the environment + :type cmd: str or list + :param str cwd: The working directory in which to execute the command, defaults to :data:`os.curdir` + :return: A finished command object + :rtype: :class:`~subprocess.Popen` + """ + + c = None + with self.activated(): + script = vistir.cmdparse.Script.parse(cmd) + c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) + return c + + def run_py(self, cmd, cwd=os.curdir): + """Run a python command in the enviornment context. + + :param cmd: A command to run in the environment - runs with `python -c` + :type cmd: str or list + :param str cwd: The working directory in which to execute the command, defaults to :data:`os.curdir` + :return: A finished command object + :rtype: :class:`~subprocess.Popen` + """ + + c = None + if isinstance(cmd, six.string_types): + script = vistir.cmdparse.Script.parse("{0} -c {1}".format(self.python, cmd)) + else: + script = vistir.cmdparse.Script.parse([self.python, "-c"] + list(cmd)) + with self.activated(): + c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) + return c + + def run_activate_this(self): + """Runs the environment's inline activation script""" + if self.is_venv: + activate_this = os.path.join(self.scripts_dir, "activate_this.py") + if not os.path.isfile(activate_this): + raise OSError("No such file: {0!s}".format(activate_this)) + with open(activate_this, "r") as f: + code = compile(f.read(), activate_this, "exec") + exec(code, dict(__file__=activate_this)) + + @contextlib.contextmanager + def activated(self, include_extras=True, extra_dists=None): + """Helper context manager to activate the environment. + + This context manager will set the following variables for the duration + of its activation: + + * sys.prefix + * sys.path + * os.environ["VIRTUAL_ENV"] + * os.environ["PATH"] + + In addition, it will make any distributions passed into `extra_dists` available + on `sys.path` while inside the context manager, as well as making `passa` itself + available. + + The environment's `prefix` as well as `scripts_dir` properties are both prepended + to `os.environ["PATH"]` to ensure that calls to `~Environment.run()` use the + environment's path preferentially. + """ + + if not extra_dists: + extra_dists = [] + original_path = sys.path + original_prefix = sys.prefix + parent_path = vistir.compat.Path(__file__).absolute().parent.parent.as_posix() + prefix = self.prefix.as_posix() + with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): + os.environ["PATH"] = os.pathsep.join([ + vistir.compat.fs_str(self.scripts_dir), + vistir.compat.fs_str(self.prefix.as_posix()), + os.environ.get("PATH", "") + ]) + os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") + os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") + os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(prefix) + if self.is_venv: + os.environ["VIRTUAL_ENV"] = vistir.compat.fs_str(prefix) + sys.path = self.sys_path + sys.prefix = self.sys_prefix + pkg_resources = self.safe_import("pkg_resources") + if include_extras: + site = self.safe_import("site") + site.addsitedir(parent_path) + extra_dists = list(self.extra_dists) + extra_dists + for extra_dist in extra_dists: + if extra_dist not in self.get_working_set(): + extra_dist.activate(self.sys_path) + try: + yield + finally: + sys.path = original_path + sys.prefix = original_prefix + six.moves.reload_module(pkg_resources) + + @contextlib.contextmanager + def uninstall(self, pkgname, *args, **kwargs): + """A context manager which allows uninstallation of packages from the environment + + :param str pkgname: The name of a package to uninstall + + >>> env = Environment("/path/to/env/root") + >>> with env.uninstall("pytz", auto_confirm=True, verbose=False) as uninstaller: + cleaned = uninstaller.paths + >>> if cleaned: + print("uninstalled packages: %s" % cleaned) + """ + + auto_confirm = kwargs.pop("auto_confirm", True) + verbose = kwargs.pop("verbose", False) + with self.activated(): + monkey_patch = next(iter( + dist for dist in self.base_working_set + if dist.project_name == "recursive-monkey-patch" + ), None) + if monkey_patch: + monkey_patch.activate() + pip_shims = self.safe_import("pip_shims") + pathset_base = pip_shims.UninstallPathSet + import recursive_monkey_patch + recursive_monkey_patch.monkey_patch( + PatchedUninstaller, pathset_base + ) + dist = next( + iter(filter(lambda d: d.project_name == pkgname, self.get_working_set())), + None + ) + pathset = pathset_base.from_dist(dist) + if pathset is not None: + pathset.remove(auto_confirm=auto_confirm, verbose=verbose) + try: + yield pathset + except Exception as e: + if pathset is not None: + pathset.rollback() + else: + if pathset is not None: + pathset.commit() + if pathset is None: + return + + +class PatchedUninstaller(object): + def _permitted(self, path): + return True diff --git a/src/passa/models/projects.py b/src/passa/models/projects.py index 7ff6f31..5c8d027 100644 --- a/src/passa/models/projects.py +++ b/src/passa/models/projects.py @@ -14,6 +14,8 @@ import six import tomlkit +from .environments import Environment + SectionDifference = collections.namedtuple("SectionDifference", [ "inthis", "inthat", @@ -84,7 +86,7 @@ def dumps(self): class Project(object): root = attr.ib() - env_prefix = attr.ib(default=None) + environment = attr.ib(default=attr.Factory(Environment)) _p = attr.ib(init=False) _l = attr.ib(init=False) diff --git a/tests/actions/test_clean.py b/tests/actions/test_clean.py index 2160301..68562f9 100644 --- a/tests/actions/test_clean.py +++ b/tests/actions/test_clean.py @@ -7,14 +7,14 @@ def test_clean(project): retcode = passa.actions.add.add_packages(["requests"], project=project) assert not retcode packages = ["requests", "chardet", "certifi", "idna"] - c = project.venv.run("pip install pytz") + c = project.env.run("pip install pytz") assert c.returncode == 0 - assert project.venv.is_installed("pytz") - c = project.venv.run("python -c 'import pytz'") + assert project.env.is_installed("pytz") + c = project.env.run("python -c 'import pytz'") assert c.returncode == 0 clean_retcode = passa.actions.clean.clean(project=project) assert not clean_retcode - assert not project.venv.is_installed("pytz") - c = project.venv.run("python -c 'import pytz'") + assert not project.env.is_installed("pytz") + c = project.env.run("python -c 'import pytz'") assert c.returncode != 0 assert all(pkg in project.lockfile.default for pkg in packages) diff --git a/tests/actions/test_install.py b/tests/actions/test_install.py index bb205e6..45b44c0 100644 --- a/tests/actions/test_install.py +++ b/tests/actions/test_install.py @@ -25,7 +25,7 @@ def test_install_one(project, is_dev): assert 'pytz' in project.lockfile._data[lockfile_section].keys() install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) assert install == 0 - assert project.venv.is_installed("pytz") or project.is_installed("pytz") + assert project.env.is_installed("pytz") or project.is_installed("pytz") @pytest.mark.parametrize( @@ -47,8 +47,8 @@ def test_install_one_with_deps(project, is_dev): assert 'idna' in project.lockfile._data[lockfile_section].keys() install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) assert install == 0 - assert project.venv.is_installed("requests") or project.is_installed("requests") - assert project.venv.is_installed("idna") or project.is_installed("idna") + assert project.env.is_installed("requests") or project.is_installed("requests") + assert project.env.is_installed("idna") or project.is_installed("idna") @pytest.mark.parametrize( @@ -70,8 +70,8 @@ def test_install_editable(project, is_dev): install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) assert install == 0 project.reload() - assert (project.venv.is_installed("shellingham") or - project.is_installed("shellingham")), list([dist.project_name for dist in project.venv.get_distributions()]) + assert (project.env.is_installed("shellingham") or + project.is_installed("shellingham")), list([dist.project_name for dist in project.env.get_distributions()]) @pytest.mark.parametrize( @@ -93,4 +93,4 @@ def test_install_sdist(project, is_dev): install = passa.actions.install.install(project=project, check=True, dev=is_dev, clean=False) assert install == 0 project.reload() - assert project.venv.is_installed("arrow") or project.is_installed("arrow") + assert project.env.is_installed("arrow") or project.is_installed("arrow") diff --git a/tests/actions/test_remove_and_sync.py b/tests/actions/test_remove_and_sync.py index e14ec8a..f428a94 100644 --- a/tests/actions/test_remove_and_sync.py +++ b/tests/actions/test_remove_and_sync.py @@ -29,14 +29,14 @@ def test_remove_one(project, sync, is_dev): lockfile_section = "default" if not is_dev else "develop" assert pkg in project.lockfile._data[lockfile_section].keys() if sync: - assert project.venv.is_installed(pkg) or project.is_installed(pkg) + assert project.env.is_installed(pkg) or project.is_installed(pkg) remove = "default" if not is_dev else "dev" retcode = passa.actions.remove.remove(project=project, packages=[pkg,], sync=sync, only=remove) assert not retcode project.reload() assert pkg not in project.lockfile._data[lockfile_section].keys() if sync: - assert not project.venv.is_installed(pkg) + assert not project.env.is_installed(pkg) @pytest.mark.parametrize( @@ -60,11 +60,11 @@ def test_remove_one_with_deps(project, sync, is_dev): assert 'requests' in project.lockfile._data[lockfile_section].keys() assert 'idna' in project.lockfile._data[lockfile_section].keys() if sync: - c = vistir.misc.run(["{0}".format(project.venv.python), "-c", "import requests"], + c = vistir.misc.run(["{0}".format(project.env.python), "-c", "import requests"], nospin=True, block=True, return_object=True) assert c.returncode == 0, (c.out, c.err) - assert project.venv.is_installed("requests") or project.is_installed("requests") - assert project.venv.is_installed("idna") or project.is_installed("idna") + assert project.env.is_installed("requests") or project.is_installed("requests") + assert project.env.is_installed("idna") or project.is_installed("idna") remove = "default" if not is_dev else "dev" retcode = passa.actions.remove.remove(project=project, packages=["requests",], sync=sync, only=remove) assert not retcode @@ -72,8 +72,8 @@ def test_remove_one_with_deps(project, sync, is_dev): assert "requests" not in project.lockfile._data[lockfile_section].keys() assert "idna" not in project.lockfile._data[lockfile_section].keys() if sync: - assert not project.venv.is_installed("requests") - assert not project.venv.is_installed("idna") + assert not project.env.is_installed("requests") + assert not project.env.is_installed("idna") @pytest.mark.parametrize( @@ -96,17 +96,17 @@ def test_remove_editable(project, sync, is_dev): lockfile_section = "default" if not is_dev else "develop" assert 'shellingham' in project.lockfile._data[lockfile_section].keys() if sync: - c = vistir.misc.run(["{0}".format(project.venv.python), "-c", "import shellingham"], + c = vistir.misc.run(["{0}".format(project.env.python), "-c", "import shellingham"], nospin=True, block=True, return_object=True) assert c.returncode == 0, (c.out, c.err) - assert project.venv.is_installed("shellingham") or project.is_installed("shellingham") + assert project.env.is_installed("shellingham") or project.is_installed("shellingham") remove = "default" if not is_dev else "dev" retcode = passa.actions.remove.remove(project=project, packages=["shellingham",], sync=sync, only=remove) assert not retcode project.reload() assert "shellingham" not in project.lockfile._data[lockfile_section].keys() if sync: - assert not project.venv.is_installed("shellingham") + assert not project.env.is_installed("shellingham") @pytest.mark.parametrize( @@ -129,14 +129,14 @@ def test_remove_sdist(project, is_dev, sync): lockfile_section = "default" if not is_dev else "develop" assert 'arrow' in project.lockfile._data[lockfile_section].keys() if sync: - c = vistir.misc.run(["{0}".format(project.venv.python), "-c", "import arrow"], + c = vistir.misc.run(["{0}".format(project.env.python), "-c", "import arrow"], nospin=True, block=True, return_object=True) assert c.returncode == 0, (c.out, c.err) - assert project.venv.is_installed("arrow") or project.is_installed("arrow") + assert project.env.is_installed("arrow") or project.is_installed("arrow") remove = "default" if not is_dev else "dev" retcode = passa.actions.remove.remove(project=project, packages=["arrow",], sync=sync, only=remove) assert not retcode project.reload() assert "arrow" not in project.lockfile._data[lockfile_section].keys() if sync: - assert not project.venv.is_installed("arrow") + assert not project.env.is_installed("arrow") diff --git a/tests/conftest.py b/tests/conftest.py index 2726762..1ac4319 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,8 @@ import passa import passa.models.projects import passa.cli.options -import mork +# import mork +import passa.models.environments import pkg_resources import plette import sys @@ -52,11 +53,11 @@ def virtualenv(tmpdir_factory): class _Project(passa.cli.options.Project): - def __init__(self, root, venv=None, working_set_extension=[]): + def __init__(self, root, environment=None, working_set_extension=[]): self.path = root - self.venv = venv self.working_set_extension = working_set_extension - super(_Project, self).__init__(self.path, venv=venv) + self.env = environment + super(_Project, self).__init__(self.path, environment=environment) self.pipfile_instance = vistir.compat.Path(self.pipfile_location) self.lockfile_instance = vistir.compat.Path(self.lockfile_location) @@ -71,6 +72,7 @@ def reload(self): invalid_ok=True, ) + @pytest.fixture(scope="function") def project_directory(tmpdir_factory): project_dir = tmpdir_factory.mktemp("passa-project") @@ -82,7 +84,11 @@ def project_directory(tmpdir_factory): @pytest.fixture def tmpvenv(virtualenv, tmpdir): venv_srcdir = virtualenv.join("src").mkdir() - venv = mork.virtualenv.VirtualEnv(virtualenv.strpath) + # venv = mork.virtualenv.VirtualEnv(virtualenv.strpath) + workingset = pkg_resources.WorkingSet(sys.path) + venv = passa.models.environments.Environment(prefix=virtualenv.strpath, is_venv=True, + base_working_set=workingset) + venv.add_dist("passa") venv.run(["pip", "install", "--upgrade", "mork", "setuptools"]) with vistir.contextmanagers.temp_environ(): os.environ["PACKAGEBUILDER_CACHE_DIR"] = tmpdir.strpath @@ -96,6 +102,6 @@ def tmpvenv(virtualenv, tmpdir): def project(project_directory, working_set_extension, tmpvenv): # resolved = tmpvenv.resolve_dist(passa_dist, tmpvenv.base_working_set) with tmpvenv.activated(extra_dists=list(working_set_extension)): - project = _Project(project_directory.strpath, venv=tmpvenv, working_set_extension=working_set_extension) + project = _Project(project_directory.strpath, environment=tmpvenv, working_set_extension=working_set_extension) project.is_installed = lambda x: any(d for d in tmpvenv.get_working_set() if d.project_name == x) yield project From 2c85a5d359d4347f73c19601452d74ca764c6eec Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 8 Oct 2018 23:29:18 -0400 Subject: [PATCH 21/26] Fix environment creation Signed-off-by: Dan Ryan --- src/passa/cli/options.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/passa/cli/options.py b/src/passa/cli/options.py index f690ae3..c1f39d2 100644 --- a/src/passa/cli/options.py +++ b/src/passa/cli/options.py @@ -36,8 +36,6 @@ def __init__(self, root, *args, **kwargs): ) def get_env(self): - if self.environment: - return self.environment if 'VIRTUAL_ENV' in os.environ: return Environment(prefix=os.environ['VIRTUAL_ENV'], is_venv=True) return Environment() From b50e59fe1c25189643b4c7afeecc56504d0fffca Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Mon, 8 Oct 2018 23:33:34 -0400 Subject: [PATCH 22/26] Update missing import Signed-off-by: Dan Ryan --- src/passa/internals/_pip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/passa/internals/_pip.py b/src/passa/internals/_pip.py index 4ed662a..450216e 100644 --- a/src/passa/internals/_pip.py +++ b/src/passa/internals/_pip.py @@ -22,7 +22,7 @@ from ..models.caches import CACHE_DIR from ..models.environments import Environment from ._pip_shims import ( - SETUPTOOLS_SHIM, VCS_SUPPORT, build_wheel as _build_wheel, unpack_url, patch_pathset + SETUPTOOLS_SHIM, VCS_SUPPORT, build_wheel as _build_wheel, unpack_url ) from .utils import filter_sources From 69a8e7c3f8e2eba77cd23c5f995230312b9e0f0a Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 9 Oct 2018 00:12:10 -0400 Subject: [PATCH 23/26] Store project on synchronizer Signed-off-by: Dan Ryan --- src/passa/models/synchronizers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/passa/models/synchronizers.py b/src/passa/models/synchronizers.py index 2ade9c5..c2f9bad 100644 --- a/src/passa/models/synchronizers.py +++ b/src/passa/models/synchronizers.py @@ -144,6 +144,7 @@ class Synchronizer(object): """ def __init__(self, project, default, develop, clean_unneeded, venv=None): self._root = project.root # Only for repr. + self.project = project self.packages = _get_packages(project.lockfile, default, develop) self.sources = project.lockfile.meta.sources._data self.clean_unneeded = clean_unneeded From 6a8d24e289c45eece4613b51aa537f4c67f0ba68 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 11 Dec 2018 23:37:11 -0500 Subject: [PATCH 24/26] update environment model Signed-off-by: Dan Ryan --- Pipfile | 9 +- Pipfile.lock | 448 ++++++++++++++++--------------- src/passa/internals/_pip.py | 53 ++++ src/passa/models/environments.py | 172 ++++++++---- 4 files changed, 406 insertions(+), 276 deletions(-) diff --git a/Pipfile b/Pipfile index 51464ab..3304c70 100644 --- a/Pipfile +++ b/Pipfile @@ -1,16 +1,17 @@ [packages] -passa = { editable = true, path = '.', extras = ['virtualenv'] } +passa = {editable = true,path = '.',extras = ['virtualenv']} [dev-packages] black = '*' invoke = '*' parver = '*' -passa = { editable = true, path = '.', extras = ['tests'] } +passa = {editable = true,path = '.',extras = ['tests']} sphinx = '*' sphinx-rtd-theme = '*' towncrier = '*' twine = '*' wheel = '*' +coverage = "<5.0" [scripts] passa-add = 'python -m passa.cli.add' @@ -18,7 +19,6 @@ passa-remove = 'python -m passa.cli.remove' passa-upgrade = 'python -m passa.cli.upgrade' passa-lock = 'python -m passa.cli.lock' passa-freeze = 'python -m passa.cli.freeze' - black = 'black src/passa/ --exclude "/(\.git|\.hg|\.mypy_cache|\.tox|\.venv|_build|buck-out|build|dist)/"' build = 'inv build' changelog = 'towncrier' @@ -27,3 +27,6 @@ draft = 'towncrier --draft' release = 'inv release' tests = "pytest -v tests" upload = 'inv upload' + +[pipenv] +allow_prereleases = true diff --git a/Pipfile.lock b/Pipfile.lock index 8eb9676..87a1b56 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "994d50f9fd0acc91cf216cf0ffc1233ebbfd0a411b57320f44a0f4487943e546" + "sha256": "ae77196fcc7d593aa66b380a7db53403cadee0631902ed2d50d979c61be029b9" }, "pipfile-spec": 6, "requires": {}, @@ -19,7 +19,6 @@ "sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92", "sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", "version": "==1.4.3" }, "attrs": { @@ -27,7 +26,6 @@ "sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69", "sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", "version": "==18.2.0" }, "backports-shutil-get-terminal-size": { @@ -49,37 +47,45 @@ "sha256:3a026f1a54135677e7da5ce819b0c690f156f37976f3e30c5430740725203d7f", "sha256:9217a59f14a5682da7c4b8829deadbfc194ac22e9908ccf7c8820234e80a1504" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.5.1" }, "cerberus": { "hashes": [ "sha256:f5c2e048fb15ecb3c088d192164316093fcfa602a74b3386eefb2983aa7e800a" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.2" }, "certifi": { "hashes": [ - "sha256:376690d6f16d32f9d1fe8932551d80b23e9d393a8578c5633a2ed39a64861638", - "sha256:456048c7e371c089d0a77a5212fb37a2c2dce1e24146e3b7e0261736aaeaa22a" + "sha256:47f9c83ef4c0c621eaef743f133f09fa8a74a9b75f037e8624f83bd1b6626cb7", + "sha256:993f830721089fef441cdfeb4b2c8c9df86f0c63239f06bd025a76a7daddb033" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2018.8.24" + "version": "==2018.11.29" }, "chardet": { "hashes": [ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==3.0.4" }, + "colorama": { + "hashes": [ + "sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d", + "sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48" + ], + "version": "==0.4.1" + }, + "cursor": { + "hashes": [ + "sha256:8ee9fe5b925e1001f6ae6c017e93682583d2b4d1ef7130a26cfcdf1651c0032c" + ], + "version": "==1.2.0" + }, "distlib": { "hashes": [ "sha256:57977cd7d9ea27986ec62f425630e4ddb42efe651ff80bc58ed8dbc3c7c21f19" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2.8" }, "enum34": { @@ -97,16 +103,14 @@ "sha256:3bb3de3582cb27071cfb514f00ed784dc444b7f96dc21e140de65fe00585c95e", "sha256:41d5b64e70507d0c3ca742d68010a76060eea8a3d863e9b5130ab11a4a91aa0e" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.0.1" }, "idna": { "hashes": [ - "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e", - "sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16" + "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", + "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.7" + "version": "==2.8" }, "importlib": { "hashes": [ @@ -120,7 +124,6 @@ "sha256:1ba23de573e9b95a8dcbd04fd026c40a64b77db0aadc48f28a844b4cb87479fe", "sha256:f4f195c9b17ea7d2b631a758451485c6b080975349b4adebe45ef4bb022db069" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.1.1" }, "modutil": { @@ -136,7 +139,6 @@ "sha256:13772edb4724915cf0cfa30d31426e0565487a3b2d7883b8468718eaed8ecfc2", "sha256:b1b41bc31603eef1b50e42e75ae2d74d7a0d9ab46ea4d0dd1ba387a451870873" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.1.4" }, "packagebuilder": { @@ -144,7 +146,6 @@ "sha256:1e85c4e0e994322996b93cd6685c12834d30f3558889154f8e3de8fb1f3fd1e7", "sha256:dc525d06ecd102db23ab421b879d7d27021d784ff933e33e8c411a53af5c9dbe" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.1.0" }, "packaging": { @@ -152,13 +153,14 @@ "sha256:0886227f54515e592aaa2e5a553332c73962917f2831f1b0f9b9f4380a4b9807", "sha256:f95a1e147590f204328170981833854229bb2912ac3d5f89e2a8ccd2834800c9" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==18.0" }, "passa": { "editable": true, - "path": ".", - "extras": ["virtualenv"] + "extras": [ + "virtualenv" + ], + "path": "." }, "pathlib2": { "hashes": [ @@ -168,13 +170,19 @@ "markers": "python_version < '3.5' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version < '3.5' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.3.2" }, + "pep517": { + "hashes": [ + "sha256:cc663a438fdfe2e88d8d3c5ef2203ac858de34e31b6609b1fc505d611490a926", + "sha256:f79bb08fb064dfc5b141204bfeb56a4141a6d504677fab4723036a464fc25cc1" + ], + "version": "==0.3" + }, "pip-shims": { "hashes": [ - "sha256:9c8a568b4a8ce4000a2982224f48a35736fca81214dfdb30dcae24287866a7e4", - "sha256:ebc2bb29ddd21fa00c0cf28a5d8c725100f2f7ee98703aba237efd02e205c1c1" + "sha256:3bc24ec050a6b9eea35419467237e4f47eaf806dadc9999bf887355c377edea7", + "sha256:edb4cf3c509eab2f36b55c1ac1a59a4c485ccd537cc87934d74950880f641256" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.1.2" + "version": "==0.3.2" }, "plette": { "extras": [ @@ -184,47 +192,47 @@ "sha256:c0e3553c1e581d8423daccbd825789c6e7f29b7d9e00e5331b12e1642a1a26d3", "sha256:dde5d525cf5f0cbad4d938c83b93db17887918daf63c13eafed257c4f61b07b4" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2.2" }, "pyparsing": { "hashes": [ - "sha256:bc6c7146b91af3f567cf6daeaec360bc07d45ffec4cf5353f4d7a208ce7ca30a", - "sha256:d29593d8ebe7b57d6967b62494f8c72b03ac0262b1eed63826c6f788b3606401" + "sha256:40856e74d4987de5d01761a22d1621ae1c7f8774585acae358aa5c5936c6c90b", + "sha256:f353aab21fd474459d97b709e527b5571314ee5f067441dc9f88e33eecd96592" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.2.2" + "version": "==2.3.0" + }, + "pytoml": { + "hashes": [ + "sha256:ca2d0cb127c938b8b76a9a0d0f855cf930c1d50cc3a0af6d3595b566519a1013" + ], + "version": "==0.1.20" }, "recursive-monkey-patch": { "hashes": [ "sha256:546739fea5be2ea9f98b5ec44fafeb697b5cf9fdcda64a03422582ab03ee24c4", "sha256:98922554e77f2e2c85a4f5d873a0f52efdc1b553f32444bd6c788b2ff583bf3e" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.4.0" }, "requests": { "hashes": [ - "sha256:63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1", - "sha256:ec22d826a36ed72a7358ff3fe56cbd4ba69dd7a6718ffd450ff0e9df7a47ce6a" + "sha256:502a824f31acdacb3a35b6690b5fbf0bc41d63a24a45c4004352b0242707598e", + "sha256:7bf2a778576d825600030a110f3c0e3e8edc51dfaafe1c146e39a2027784957b" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.19.1" + "version": "==2.21.0" }, "requirementslib": { "hashes": [ - "sha256:90151d8963f814e17190e067b60e92fb35fd1bc46c99f8dba3d7b0d93a3dd958", - "sha256:c3aeaa4e0b80843ba65a68878293e07ea52a8d0706dbba86b02dad6cd20ef2dd" + "sha256:c2c00c7bd3bd4984c97d10cd4d143efbe33b5ed9e55961bea30ca7a9a4927289", + "sha256:dc6b692e8dee03d6e90c29db1e337b0bf8152cce84a57f0fb4765e596afde4e0" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.1.6" + "version": "==1.3.3" }, "resolvelib": { "hashes": [ "sha256:6c4c6690b0bdd78bcc002e1a5d1b6abbde58c694a6ea1838f165b20d2c943db7", "sha256:8734e53271ef98f38a2c99324d5e7905bc00c97dc3fc5bb7d83c82a979e71c04" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2.2" }, "scandir": { @@ -246,10 +254,10 @@ }, "six": { "hashes": [ - "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", - "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" + "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", + "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" ], - "version": "==1.11.0" + "version": "==1.12.0" }, "toml": { "hashes": [ @@ -260,11 +268,10 @@ }, "tomlkit": { "hashes": [ - "sha256:8ab16e93162fc44d3ad83d2aa29a7140b8f7d996ae1790a73b9a7aed6fb504ac", - "sha256:ca181cee7aee805d455628f7c94eb8ae814763769a93e69157f250fe4ebe1926" + "sha256:d6506342615d051bc961f70bfcfa3d29b6616cc08a3ddfd4bc24196f16fd4ec2", + "sha256:f077456d35303e7908cc233b340f71e0bec96f63429997f38ca9272b7d64029e" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.4.4" + "version": "==0.5.3" }, "typing": { "hashes": [ @@ -277,63 +284,56 @@ }, "urllib3": { "hashes": [ - "sha256:a68ac5e15e76e7e5dd2b8f94007233e01effe3e50e8daddf69acfd81cb686baf", - "sha256:b5725a0bd4ba422ab0e66e89e030c806576753ea3ee08554382c14e685d117b5" + "sha256:61bf29cada3fc2fbefad4fdf059ea4bd1b4a86d2b6d15e1c7c0b582b9752fe39", + "sha256:de9529817c93f27c8ccbfead6985011db27bd0ddfcdb2d86f3f663385c6a9c22" ], - "markers": "python_version < '4' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.23" + "version": "==1.24.1" }, "virtualenv": { "hashes": [ - "sha256:2ce32cd126117ce2c539f0134eb89de91a8413a29baac49cbab3eb50e2026669", - "sha256:ca07b4c0b54e14a91af9f34d0919790b016923d157afda5efdde55c96718f752" + "sha256:686176c23a538ecc56d27ed9d5217abd34644823d6391cbeb232f42bf722baad", + "sha256:f899fafcd92e1150f40c8215328be38ff24b519cd95357fa6e78e006c7638208" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==16.0.0" + "version": "==16.1.0" }, "vistir": { "extras": [ "spinner" ], "hashes": [ - "sha256:8a360ac20cbcc0863d6dbbe7a52e8b2c9ebf48abd6833c3813a82c70708244af", - "sha256:bc6e10284792485c10585536e6aede9e38996c841cc9d2a67238cd05742c2d0b" + "sha256:3a1020fb7be000b268af96641ced9ead844b1f75840c41e20e473647688fc630", + "sha256:6d2005ad670f77bd9c9b5415c4e2a4a20dce5b0cf0e0d11598eb463b2e0ebe44" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.1.6" + "version": "==0.2.5" }, "wheel": { "hashes": [ - "sha256:3970f4130b7f8bf8167ca09215c8cc2f49a87c3d46506adfc60cb08c47ab0949", - "sha256:a26bc27230baaec9039972b7cb43db94b17c13e4d66a9ff6a4d46a0344c55c9a" + "sha256:029703bf514e16c8271c3821806a1c171220cc5bdd325cbf4e7da1e056a01db6", + "sha256:1e53cdb3f808d5ccd0df57f964263752aa74ea7359526d3da6c02114ec1e1d44" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.32.0" + "version": "==0.32.3" }, "yaspin": { "hashes": [ "sha256:36fdccc5e0637b5baa8892fe2c3d927782df7d504e9020f40eb2c1502518aa5a", "sha256:8e52bf8079a48e2a53f3dfeec9e04addb900c101d1591c85df69cf677d3237e7" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.14.0" } }, "develop": { "alabaster": { "hashes": [ - "sha256:674bb3bab080f598371f4443c5008cbfeb1a5e622dd312395d2d82af2c54c456", - "sha256:b63b1f4dc77c074d386752ec4a8a7517600f6c0db8cd42980cae17ab7b3275d7" + "sha256:446438bdcca0e05bd45ea2de1668c1d9b032e1a9154c2c259092d77031ddd359", + "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.7.11" + "version": "==0.7.12" }, "apipkg": { "hashes": [ "sha256:37228cda29411948b422fae072f57e31d3396d2ee1c9783775980ee9c9990af6", "sha256:58587dd4dc3daefad0487f6d9ae32b4542b185e1c36db6993290e7c41ca2b47c" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.5" }, "appdirs": { @@ -341,7 +341,6 @@ "sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92", "sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", "version": "==1.4.3" }, "arpeggio": { @@ -349,7 +348,6 @@ "sha256:a5258b84f76661d558492fa87e42db634df143685a0e51802d59cae7daad8732", "sha256:dc5c0541e7cc2c6033dc0338133436abfac53655624784736e9bc8bd35e56583" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.9.0" }, "atomicwrites": { @@ -357,7 +355,6 @@ "sha256:0312ad34fcad8fac3704d441f7b317e50af620823353ec657a53e981f92920c0", "sha256:ec9ae8adaae229e4f8446952d204a3e4b5fdd2d099f9be3aaf556120135fb3ee" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.2.1" }, "attrs": { @@ -365,7 +362,6 @@ "sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69", "sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '3.6'", "version": "==18.2.0" }, "babel": { @@ -373,7 +369,6 @@ "sha256:6778d85147d5d85345c14a26aada5e478ab04e39b078b0745ee6870c2b5cf669", "sha256:8cba50f48c529ca3fa18cf81fa9403be176d374ac4d60738b839122dfaaa3d23" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.6.0" }, "backports-shutil-get-terminal-size": { @@ -400,34 +395,30 @@ }, "bleach": { "hashes": [ - "sha256:0ee95f6167129859c5dce9b1ca291ebdb5d8cd7e382ca0e237dfd0dad63f63d8", - "sha256:24754b9a7d530bf30ce7cbc805bc6cce785660b4a10ff3a43633728438c105ab" + "sha256:48d39675b80a75f6d1c3bdbffec791cf0bbbab665cf01e20da701c77de278718", + "sha256:73d26f018af5d5adcdabf5c1c974add4361a9c76af215fe32fdec8a6fc5fb9b9" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.1.4" + "version": "==3.0.2" }, "cached-property": { "hashes": [ "sha256:3a026f1a54135677e7da5ce819b0c690f156f37976f3e30c5430740725203d7f", "sha256:9217a59f14a5682da7c4b8829deadbfc194ac22e9908ccf7c8820234e80a1504" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.5.1" }, "cerberus": { "hashes": [ "sha256:f5c2e048fb15ecb3c088d192164316093fcfa602a74b3386eefb2983aa7e800a" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.2" }, "certifi": { "hashes": [ - "sha256:376690d6f16d32f9d1fe8932551d80b23e9d393a8578c5633a2ed39a64861638", - "sha256:456048c7e371c089d0a77a5212fb37a2c2dce1e24146e3b7e0261736aaeaa22a" + "sha256:47f9c83ef4c0c621eaef743f133f09fa8a74a9b75f037e8624f83bd1b6626cb7", + "sha256:993f830721089fef441cdfeb4b2c8c9df86f0c63239f06bd025a76a7daddb033" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2018.8.24" + "version": "==2018.11.29" }, "cffi": { "hashes": [ @@ -471,7 +462,6 @@ "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==3.0.4" }, "click": { @@ -479,7 +469,6 @@ "sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13", "sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7" ], - "markers": "python_version >= '2.7' and python_version >= '3.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==7.0" }, "cmarkgfm": { @@ -517,54 +506,55 @@ }, "colorama": { "hashes": [ - "sha256:463f8483208e921368c9f306094eb6f725c6ca42b0f97e313cb5d5512459feda", - "sha256:48eb22f4f8461b1df5734a074b57042430fb06e1d61bd1e11b078c0fe6d7a1f1" + "sha256:05eed71e2e327246ad6b38c540c4a3117230b19679b875190486ddd2d721422d", + "sha256:f8ac84de7840f5b9c4e3347b3c1eaa50f7e49c2b07596221daec5edaabbd7c48" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' and sys_platform == 'win32'", - "version": "==0.3.9" + "version": "==0.4.1" }, "coverage": { "hashes": [ - "sha256:03481e81d558d30d230bc12999e3edffe392d244349a90f4ef9b88425fac74ba", - "sha256:0b136648de27201056c1869a6c0d4e23f464750fd9a9ba9750b8336a244429ed", - "sha256:10a46017fef60e16694a30627319f38a2b9b52e90182dddb6e37dcdab0f4bf95", - "sha256:198626739a79b09fa0a2f06e083ffd12eb55449b5f8bfdbeed1df4910b2ca640", - "sha256:23d341cdd4a0371820eb2b0bd6b88f5003a7438bbedb33688cd33b8eae59affd", - "sha256:28b2191e7283f4f3568962e373b47ef7f0392993bb6660d079c62bd50fe9d162", - "sha256:2a5b73210bad5279ddb558d9a2bfedc7f4bf6ad7f3c988641d83c40293deaec1", - "sha256:2eb564bbf7816a9d68dd3369a510be3327f1c618d2357fa6b1216994c2e3d508", - "sha256:337ded681dd2ef9ca04ef5d93cfc87e52e09db2594c296b4a0a3662cb1b41249", - "sha256:3a2184c6d797a125dca8367878d3b9a178b6fdd05fdc2d35d758c3006a1cd694", - "sha256:3c79a6f7b95751cdebcd9037e4d06f8d5a9b60e4ed0cd231342aa8ad7124882a", - "sha256:3d72c20bd105022d29b14a7d628462ebdc61de2f303322c0212a054352f3b287", - "sha256:3eb42bf89a6be7deb64116dd1cc4b08171734d721e7a7e57ad64cc4ef29ed2f1", - "sha256:4635a184d0bbe537aa185a34193898eee409332a8ccb27eea36f262566585000", - "sha256:56e448f051a201c5ebbaa86a5efd0ca90d327204d8b059ab25ad0f35fbfd79f1", - "sha256:5a13ea7911ff5e1796b6d5e4fbbf6952381a611209b736d48e675c2756f3f74e", - "sha256:69bf008a06b76619d3c3f3b1983f5145c75a305a0fea513aca094cae5c40a8f5", - "sha256:6bc583dc18d5979dc0f6cec26a8603129de0304d5ae1f17e57a12834e7235062", - "sha256:701cd6093d63e6b8ad7009d8a92425428bc4d6e7ab8d75efbb665c806c1d79ba", - "sha256:7608a3dd5d73cb06c531b8925e0ef8d3de31fed2544a7de6c63960a1e73ea4bc", - "sha256:76ecd006d1d8f739430ec50cc872889af1f9c1b6b8f48e29941814b09b0fd3cc", - "sha256:7aa36d2b844a3e4a4b356708d79fd2c260281a7390d678a10b91ca595ddc9e99", - "sha256:7d3f553904b0c5c016d1dad058a7554c7ac4c91a789fca496e7d8347ad040653", - "sha256:7e1fe19bd6dce69d9fd159d8e4a80a8f52101380d5d3a4d374b6d3eae0e5de9c", - "sha256:8c3cb8c35ec4d9506979b4cf90ee9918bc2e49f84189d9bf5c36c0c1119c6558", - "sha256:9d6dd10d49e01571bf6e147d3b505141ffc093a06756c60b053a859cb2128b1f", - "sha256:be6cfcd8053d13f5f5eeb284aa8a814220c3da1b0078fa859011c7fffd86dab9", - "sha256:c1bb572fab8208c400adaf06a8133ac0712179a334c09224fb11393e920abcdd", - "sha256:de4418dadaa1c01d497e539210cb6baa015965526ff5afc078c57ca69160108d", - "sha256:e05cb4d9aad6233d67e0541caa7e511fa4047ed7750ec2510d466e806e0255d6", - "sha256:f3f501f345f24383c0000395b26b726e46758b71393267aeae0bd36f8b3ade80" - ], - "markers": "python_version < '4' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==4.5.1" + "sha256:029c69deaeeeae1b15bc6c59f0ffa28aa8473721c614a23f2c2976dec245cd12", + "sha256:02abbbebc6e9d5abe13cd28b5e963dedb6ffb51c146c916d17b18f141acd9947", + "sha256:1bbfe5b82a3921d285e999c6d256c1e16b31c554c29da62d326f86c173d30337", + "sha256:210c02f923df33a8d0e461c86fdcbbb17228ff4f6d92609fc06370a98d283c2d", + "sha256:2d0807ba935f540d20b49d5bf1c0237b90ce81e133402feda906e540003f2f7a", + "sha256:35d7a013874a7c927ce997350d314144ffc5465faf787bb4e46e6c4f381ef562", + "sha256:3636f9d0dcb01aed4180ef2e57a4e34bb4cac3ecd203c2a23db8526d86ab2fb4", + "sha256:42f4be770af2455a75e4640f033a82c62f3fb0d7a074123266e143269d7010ef", + "sha256:48440b25ba6cda72d4c638f3a9efa827b5b87b489c96ab5f4ff597d976413156", + "sha256:4dac8dfd1acf6a3ac657475dfdc66c621f291b1b7422a939cc33c13ac5356473", + "sha256:4e8474771c69c2991d5eab65764289a7dd450bbea050bc0ebb42b678d8222b42", + "sha256:551f10ddfeff56a1325e5a34eff304c5892aa981fd810babb98bfee77ee2fb17", + "sha256:5b104982f1809c1577912519eb249f17d9d7e66304ad026666cb60a5ef73309c", + "sha256:5c62aef73dfc87bfcca32cee149a1a7a602bc74bac72223236b0023543511c88", + "sha256:633151f8d1ad9467b9f7e90854a7f46ed8f2919e8bc7d98d737833e8938fc081", + "sha256:772207b9e2d5bf3f9d283b88915723e4e92d9a62c83f44ec92b9bd0cd685541b", + "sha256:7d5e02f647cd727afc2659ec14d4d1cc0508c47e6cfb07aea33d7aa9ca94d288", + "sha256:a9798a4111abb0f94584000ba2a2c74841f2cfe5f9254709756367aabbae0541", + "sha256:b38ea741ab9e35bfa7015c93c93bbd6a1623428f97a67083fc8ebd366238b91f", + "sha256:b6a5478c904236543c0347db8a05fac6fc0bd574c870e7970faa88e1d9890044", + "sha256:c6248bfc1de36a3844685a2e10ba17c18119ba6252547f921062a323fb31bff1", + "sha256:c705ab445936457359b1424ef25ccc0098b0491b26064677c39f1d14a539f056", + "sha256:d95a363d663ceee647291131dbd213af258df24f41350246842481ec3709bd33", + "sha256:e27265eb80cdc5dab55a40ef6f890e04ecc618649ad3da5265f128b141f93f78", + "sha256:ebc276c9cb5d917bd2ae959f84ffc279acafa9c9b50b0fa436ebb70bbe2166ea", + "sha256:f4d229866d030863d0fe3bf297d6d11e6133ca15bbb41ed2534a8b9a3d6bd061", + "sha256:f95675bd88b51474d4fe5165f3266f419ce754ffadfb97f10323931fa9ac95e5", + "sha256:f95bc54fb6d61b9f9ff09c4ae8ff6a3f5edc937cda3ca36fc937302a7c152bf1", + "sha256:fd0f6be53de40683584e5331c341e65a679dbe5ec489a0697cec7c2ef1a48cda" + ], + "version": "==5.0a4" + }, + "cursor": { + "hashes": [ + "sha256:8ee9fe5b925e1001f6ae6c017e93682583d2b4d1ef7130a26cfcdf1651c0032c" + ], + "version": "==1.2.0" }, "distlib": { "hashes": [ "sha256:57977cd7d9ea27986ec62f425630e4ddb42efe651ff80bc58ed8dbc3c7c21f19" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2.8" }, "docutils": { @@ -590,7 +580,6 @@ "sha256:a7a84d5fa07a089186a329528f127c9d73b9de57f1a1131b82bb5320ee651f6a", "sha256:fc155a6b553c66c838d1a22dba1dc9f5f505c43285a878c6f74a79c024750b83" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.5.0" }, "first": { @@ -598,7 +587,6 @@ "sha256:3bb3de3582cb27071cfb514f00ed784dc444b7f96dc21e140de65fe00585c95e", "sha256:41d5b64e70507d0c3ca742d68010a76060eea8a3d863e9b5130ab11a4a91aa0e" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.0.1" }, "funcsigs": { @@ -625,18 +613,16 @@ }, "idna": { "hashes": [ - "sha256:156a6814fb5ac1fc6850fb002e0852d56c0c8d2531923a51032d1b70760e186e", - "sha256:684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16" + "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", + "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.7" + "version": "==2.8" }, "imagesize": { "hashes": [ "sha256:3f349de3eb99145973fefb7dbe38554414e5c30abd0c8e4b970a7c9d09f3a1d8", "sha256:f3832918bc3c66617f92e35f5d70729187676313caa60c187eb0f28b8fe5e3b5" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.1.0" }, "importlib": { @@ -658,7 +644,6 @@ "sha256:1ba23de573e9b95a8dcbd04fd026c40a64b77db0aadc48f28a844b4cb87479fe", "sha256:f4f195c9b17ea7d2b631a758451485c6b080975349b4adebe45ef4bb022db069" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.1.1" }, "invoke": { @@ -678,9 +663,36 @@ }, "markupsafe": { "hashes": [ - "sha256:a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665" + "sha256:048ef924c1623740e70204aa7143ec592504045ae4429b59c30054cb31e3c432", + "sha256:130f844e7f5bdd8e9f3f42e7102ef1d49b2e6fdf0d7526df3f87281a532d8c8b", + "sha256:19f637c2ac5ae9da8bfd98cef74d64b7e1bb8a63038a3505cd182c3fac5eb4d9", + "sha256:1b8a7a87ad1b92bd887568ce54b23565f3fd7018c4180136e1cf412b405a47af", + "sha256:1c25694ca680b6919de53a4bb3bdd0602beafc63ff001fea2f2fc16ec3a11834", + "sha256:1f19ef5d3908110e1e891deefb5586aae1b49a7440db952454b4e281b41620cd", + "sha256:1fa6058938190ebe8290e5cae6c351e14e7bb44505c4a7624555ce57fbbeba0d", + "sha256:31cbb1359e8c25f9f48e156e59e2eaad51cd5242c05ed18a8de6dbe85184e4b7", + "sha256:3e835d8841ae7863f64e40e19477f7eb398674da6a47f09871673742531e6f4b", + "sha256:4e97332c9ce444b0c2c38dd22ddc61c743eb208d916e4265a2a3b575bdccb1d3", + "sha256:525396ee324ee2da82919f2ee9c9e73b012f23e7640131dd1b53a90206a0f09c", + "sha256:52b07fbc32032c21ad4ab060fec137b76eb804c4b9a1c7c7dc562549306afad2", + "sha256:52ccb45e77a1085ec5461cde794e1aa037df79f473cbc69b974e73940655c8d7", + "sha256:5c3fbebd7de20ce93103cb3183b47671f2885307df4a17a0ad56a1dd51273d36", + "sha256:5e5851969aea17660e55f6a3be00037a25b96a9b44d2083651812c99d53b14d1", + "sha256:5edfa27b2d3eefa2210fb2f5d539fbed81722b49f083b2c6566455eb7422fd7e", + "sha256:7d263e5770efddf465a9e31b78362d84d015cc894ca2c131901a4445eaa61ee1", + "sha256:83381342bfc22b3c8c06f2dd93a505413888694302de25add756254beee8449c", + "sha256:857eebb2c1dc60e4219ec8e98dfa19553dae33608237e107db9c6078b1167856", + "sha256:98e439297f78fca3a6169fd330fbe88d78b3bb72f967ad9961bcac0d7fdd1550", + "sha256:bf54103892a83c64db58125b3f2a43df6d2cb2d28889f14c78519394feb41492", + "sha256:d9ac82be533394d341b41d78aca7ed0e0f4ba5a2231602e2f05aa87f25c51672", + "sha256:e982fe07ede9fada6ff6705af70514a52beb1b2c3d25d4e873e82114cf3c5401", + "sha256:edce2ea7f3dfc981c4ddc97add8a61381d9642dc3273737e756517cc03e84dd6", + "sha256:efdc45ef1afc238db84cb4963aa689c0408912a0239b0721cb172b4016eb31d6", + "sha256:f137c02498f8b935892d5c0172560d7ab54bc45039de8805075e19079c639a9c", + "sha256:f82e347a72f955b7017a39708a3667f106e6ad4d10b25f237396a7115d8ed5fd", + "sha256:fb7c206e01ad85ce57feeaaa0bf784b97fa3cad0d4a5737bc5295785f5c613a1" ], - "version": "==1.0" + "version": "==1.1.0" }, "modutil": { "hashes": [ @@ -696,7 +708,6 @@ "sha256:c476b5d3a34e12d40130bc2f935028b5f636df8f372dc2c1c01dc19681b2039e", "sha256:fcbfeaea0be121980e15bc97b3817b5202ca73d0eae185b4550cbfce2a3ebb3d" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==4.3.0" }, "mork": { @@ -704,7 +715,6 @@ "sha256:13772edb4724915cf0cfa30d31426e0565487a3b2d7883b8468718eaed8ecfc2", "sha256:b1b41bc31603eef1b50e42e75ae2d74d7a0d9ab46ea4d0dd1ba387a451870873" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.1.4" }, "ordereddict": { @@ -719,7 +729,6 @@ "sha256:1e85c4e0e994322996b93cd6685c12834d30f3558889154f8e3de8fb1f3fd1e7", "sha256:dc525d06ecd102db23ab421b879d7d27021d784ff933e33e8c411a53af5c9dbe" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.1.0" }, "packaging": { @@ -727,7 +736,6 @@ "sha256:0886227f54515e592aaa2e5a553332c73962917f2831f1b0f9b9f4380a4b9807", "sha256:f95a1e147590f204328170981833854229bb2912ac3d5f89e2a8ccd2834800c9" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==18.0" }, "parver": { @@ -741,7 +749,7 @@ "passa": { "editable": true, "extras": [ - "tests" + "virtualenv" ], "path": "." }, @@ -753,13 +761,19 @@ "markers": "python_version < '3.5' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version < '3.5' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.3.2" }, + "pep517": { + "hashes": [ + "sha256:cc663a438fdfe2e88d8d3c5ef2203ac858de34e31b6609b1fc505d611490a926", + "sha256:f79bb08fb064dfc5b141204bfeb56a4141a6d504677fab4723036a464fc25cc1" + ], + "version": "==0.3" + }, "pip-shims": { "hashes": [ - "sha256:9c8a568b4a8ce4000a2982224f48a35736fca81214dfdb30dcae24287866a7e4", - "sha256:ebc2bb29ddd21fa00c0cf28a5d8c725100f2f7ee98703aba237efd02e205c1c1" + "sha256:3bc24ec050a6b9eea35419467237e4f47eaf806dadc9999bf887355c377edea7", + "sha256:edb4cf3c509eab2f36b55c1ac1a59a4c485ccd537cc87934d74950880f641256" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.1.2" + "version": "==0.3.2" }, "pkginfo": { "hashes": [ @@ -776,24 +790,21 @@ "sha256:c0e3553c1e581d8423daccbd825789c6e7f29b7d9e00e5331b12e1642a1a26d3", "sha256:dde5d525cf5f0cbad4d938c83b93db17887918daf63c13eafed257c4f61b07b4" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2.2" }, "pluggy": { "hashes": [ - "sha256:6e3836e39f4d36ae72840833db137f7b7d35105079aee6ec4a62d9f80d594dd1", - "sha256:95eb8364a4708392bae89035f45341871286a333f749c3141c20573d2b3876e1" + "sha256:447ba94990e8014ee25ec853339faf7b0fc8050cdc3289d4d71f7f410fb90095", + "sha256:bde19360a8ec4dfd8a20dcb811780a30998101f078fc7ded6162f0076f50508f" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.7.1" + "version": "==0.8.0" }, "py": { "hashes": [ - "sha256:06a30435d058473046be836d3fc4f27167fd84c45b99704f2fb5509ef61f9af1", - "sha256:50402e9d1c9005d759426988a492e0edaadb7f4e68bcddfea586bc7432d009c6" + "sha256:bf92637198836372b520efcba9e020c330123be8ce527e535d185ed4b6f45694", + "sha256:e76826342cefe3c3d5f7e8ee4316b80d1dd8a300781612ddbc765c17ba25a6c6" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.6.0" + "version": "==1.7.0" }, "pycparser": { "hashes": [ @@ -804,33 +815,30 @@ }, "pygments": { "hashes": [ - "sha256:78f3f434bcc5d6ee09020f92ba487f95ba50f1e3ef83ae96b9d5ffa1bab25c5d", - "sha256:dbae1046def0efb574852fab9e90209b23f556367b5a320c0bcb871c77c3e8cc" + "sha256:6301ecb0997a52d2d31385e62d0a4a4cf18d2f2da7054a5ddad5c366cd39cee7", + "sha256:82666aac15622bd7bb685a4ee7f6625dd716da3ef7473620c192c0168aae64fc" ], - "version": "==2.2.0" + "version": "==2.3.0" }, "pyparsing": { "hashes": [ - "sha256:bc6c7146b91af3f567cf6daeaec360bc07d45ffec4cf5353f4d7a208ce7ca30a", - "sha256:d29593d8ebe7b57d6967b62494f8c72b03ac0262b1eed63826c6f788b3606401" + "sha256:40856e74d4987de5d01761a22d1621ae1c7f8774585acae358aa5c5936c6c90b", + "sha256:f353aab21fd474459d97b709e527b5571314ee5f067441dc9f88e33eecd96592" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.2.2" + "version": "==2.3.0" }, "pytest": { "hashes": [ - "sha256:0a72d8a9f559c006ba153e0c9b4838efd7b656cf1f993747ba7128770d6eb12c", - "sha256:95529588ff4e85114a0b0ad8e9cf0131ca47d46b28230e25366c5aba66b1d854" + "sha256:1d131cc532be0023ef8ae265e2a779938d0619bb6c2510f52987ffcba7fa1ee4", + "sha256:ca4761407f1acc85ffd1609f464ca20bb71a767803505bd4127d0e45c5a50e23" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==3.8.1" + "version": "==4.0.1" }, "pytest-cov": { "hashes": [ "sha256:513c425e931a0344944f84ea47f3956be0e416d95acbd897a44970c8d926d5d7", "sha256:e360f048b7dae3f2f2a9a4d067b2dd6b6a015d384d1577c994a43f3f7cbad762" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.6.0" }, "pytest-forked": { @@ -838,47 +846,55 @@ "sha256:e4500cd0509ec4a26535f7d4112a8cc0f17d3a41c29ffd4eab479d2a55b30805", "sha256:f275cb48a73fc61a6710726348e1da6d68a978f0ec0c54ece5a5fae5977e5a08" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2" }, "pytest-timeout": { "hashes": [ - "sha256:1117fc0536e1638862917efbdc0895e6b62fa61e6cf4f39bb655686af7af9627", - "sha256:b050a05da96a9992e90e884bc19b4790678b40c25471d2b77015b388417e1fa8" + "sha256:4a30ba76837a32c7b7cd5c84ee9933fde4b9022b0cd20ea7d4a577c2a1649fb1", + "sha256:d49f618c6448c14168773b6cdda022764c63ea80d42274e3156787e8088d04c6" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.3.2" + "version": "==1.3.3" }, "pytest-xdist": { "hashes": [ - "sha256:06aa39361694c9365baaa03bec71159b59ad06c9826c6279ebba368cb3571561", - "sha256:1ef0d05c905cfa0c5442c90e9e350e65c6ada120e33a00a066ca51c89f5f869a" + "sha256:5e8b68466c057f0f37e36909612f8838e518ce703c8da31f85e47c7dea8acc93", + "sha256:909bb938bdb21e68a28a8d58c16a112b30da088407b678633efb01067e3923de" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.23.2" + "version": "==1.24.1" + }, + "pytoml": { + "hashes": [ + "sha256:ca2d0cb127c938b8b76a9a0d0f855cf930c1d50cc3a0af6d3595b566519a1013" + ], + "version": "==0.1.20" }, "pytz": { "hashes": [ - "sha256:a061aa0a9e06881eb8b3b2b43f05b9439d6583c206d0a6c340ff72a7b6669053", - "sha256:ffb9ef1de172603304d9d2819af6f5ece76f2e85ec10692a524dd876e72bf277" + "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", + "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2018.5" + "version": "==2018.7" }, "readme-renderer": { "hashes": [ - "sha256:237ca8705ffea849870de41101dba41543561da05c0ae45b2f1c547efa9843d2", - "sha256:f75049a3a7afa57165551e030dd8f9882ebf688b9600535a3f7e23596651875d" + "sha256:bb16f55b259f27f75f640acf5e00cf897845a8b3e4731b5c1a436e4b8529202f", + "sha256:c8532b79afc0375a85f10433eca157d6b50f7d6990f337fa498c96cd4bfc203d" + ], + "version": "==24.0" + }, + "recursive-monkey-patch": { + "hashes": [ + "sha256:546739fea5be2ea9f98b5ec44fafeb697b5cf9fdcda64a03422582ab03ee24c4", + "sha256:98922554e77f2e2c85a4f5d873a0f52efdc1b553f32444bd6c788b2ff583bf3e" ], - "version": "==22.0" + "version": "==0.4.0" }, "requests": { "hashes": [ - "sha256:63b52e3c866428a224f97cab011de738c36aec0185aa91cfacd418b5d58911d1", - "sha256:ec22d826a36ed72a7358ff3fe56cbd4ba69dd7a6718ffd450ff0e9df7a47ce6a" + "sha256:502a824f31acdacb3a35b6690b5fbf0bc41d63a24a45c4004352b0242707598e", + "sha256:7bf2a778576d825600030a110f3c0e3e8edc51dfaafe1c146e39a2027784957b" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.19.1" + "version": "==2.21.0" }, "requests-toolbelt": { "hashes": [ @@ -889,18 +905,16 @@ }, "requirementslib": { "hashes": [ - "sha256:90151d8963f814e17190e067b60e92fb35fd1bc46c99f8dba3d7b0d93a3dd958", - "sha256:c3aeaa4e0b80843ba65a68878293e07ea52a8d0706dbba86b02dad6cd20ef2dd" + "sha256:c2c00c7bd3bd4984c97d10cd4d143efbe33b5ed9e55961bea30ca7a9a4927289", + "sha256:dc6b692e8dee03d6e90c29db1e337b0bf8152cce84a57f0fb4765e596afde4e0" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.1.6" + "version": "==1.3.3" }, "resolvelib": { "hashes": [ "sha256:6c4c6690b0bdd78bcc002e1a5d1b6abbde58c694a6ea1838f165b20d2c943db7", "sha256:8734e53271ef98f38a2c99324d5e7905bc00c97dc3fc5bb7d83c82a979e71c04" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2.2" }, "scandir": { @@ -922,17 +936,16 @@ }, "six": { "hashes": [ - "sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9", - "sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb" + "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", + "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" ], - "version": "==1.11.0" + "version": "==1.12.0" }, "snowballstemmer": { "hashes": [ "sha256:919f26a68b2c17a7634da993d91339e288964f93c274f1343e3bbbe2096e1128", "sha256:9f3bcd3c401c3e862ec0ebe6d2c069ebc012ce142cce209c098ccb5b09136e89" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.2.1" }, "sphinx": { @@ -955,7 +968,6 @@ "sha256:68ca7ff70785cbe1e7bccc71a48b5b6d965d79ca50629606c7861a21b206d9dd", "sha256:9de47f375baf1ea07cdb3436ff39d7a9c76042c10a769c52353ec46e4e8fc3b9" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.1.0" }, "toml": { @@ -967,11 +979,10 @@ }, "tomlkit": { "hashes": [ - "sha256:8ab16e93162fc44d3ad83d2aa29a7140b8f7d996ae1790a73b9a7aed6fb504ac", - "sha256:ca181cee7aee805d455628f7c94eb8ae814763769a93e69157f250fe4ebe1926" + "sha256:d6506342615d051bc961f70bfcfa3d29b6616cc08a3ddfd4bc24196f16fd4ec2", + "sha256:f077456d35303e7908cc233b340f71e0bec96f63429997f38ca9272b7d64029e" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.4.4" + "version": "==0.5.3" }, "towncrier": { "hashes": [ @@ -982,11 +993,10 @@ }, "tqdm": { "hashes": [ - "sha256:18f1818ce951aeb9ea162ae1098b43f583f7d057b34d706f66939353d1208889", - "sha256:df02c0650160986bac0218bb07952245fc6960d23654648b5d5526ad5a4128c9" + "sha256:3c4d4a5a41ef162dd61f1edb86b0e1c7859054ab656b2e7c7b77e7fbf6d9f392", + "sha256:5b4d5549984503050883bc126280b386f5f4ca87e6c023c5d015655ad75bdebb" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1'", - "version": "==4.26.0" + "version": "==4.28.1" }, "twine": { "hashes": [ @@ -1006,53 +1016,47 @@ }, "urllib3": { "hashes": [ - "sha256:a68ac5e15e76e7e5dd2b8f94007233e01effe3e50e8daddf69acfd81cb686baf", - "sha256:b5725a0bd4ba422ab0e66e89e030c806576753ea3ee08554382c14e685d117b5" + "sha256:61bf29cada3fc2fbefad4fdf059ea4bd1b4a86d2b6d15e1c7c0b582b9752fe39", + "sha256:de9529817c93f27c8ccbfead6985011db27bd0ddfcdb2d86f3f663385c6a9c22" ], - "markers": "python_version < '4' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.23" + "version": "==1.24.1" }, "virtualenv": { "hashes": [ - "sha256:2ce32cd126117ce2c539f0134eb89de91a8413a29baac49cbab3eb50e2026669", - "sha256:ca07b4c0b54e14a91af9f34d0919790b016923d157afda5efdde55c96718f752" + "sha256:686176c23a538ecc56d27ed9d5217abd34644823d6391cbeb232f42bf722baad", + "sha256:f899fafcd92e1150f40c8215328be38ff24b519cd95357fa6e78e006c7638208" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==16.0.0" + "version": "==16.1.0" }, "vistir": { "extras": [ "spinner" ], "hashes": [ - "sha256:8a360ac20cbcc0863d6dbbe7a52e8b2c9ebf48abd6833c3813a82c70708244af", - "sha256:bc6e10284792485c10585536e6aede9e38996c841cc9d2a67238cd05742c2d0b" + "sha256:3a1020fb7be000b268af96641ced9ead844b1f75840c41e20e473647688fc630", + "sha256:6d2005ad670f77bd9c9b5415c4e2a4a20dce5b0cf0e0d11598eb463b2e0ebe44" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.1.6" + "version": "==0.2.5" }, "webencodings": { "hashes": [ "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78", "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.5.1" }, "wheel": { "hashes": [ - "sha256:3970f4130b7f8bf8167ca09215c8cc2f49a87c3d46506adfc60cb08c47ab0949", - "sha256:a26bc27230baaec9039972b7cb43db94b17c13e4d66a9ff6a4d46a0344c55c9a" + "sha256:029703bf514e16c8271c3821806a1c171220cc5bdd325cbf4e7da1e056a01db6", + "sha256:1e53cdb3f808d5ccd0df57f964263752aa74ea7359526d3da6c02114ec1e1d44" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==0.32.0" + "version": "==0.32.3" }, "yaspin": { "hashes": [ "sha256:36fdccc5e0637b5baa8892fe2c3d927782df7d504e9020f40eb2c1502518aa5a", "sha256:8e52bf8079a48e2a53f3dfeec9e04addb900c101d1591c85df69cf677d3237e7" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.14.0" } } diff --git a/src/passa/internals/_pip.py b/src/passa/internals/_pip.py index 450216e..6c59c25 100644 --- a/src/passa/internals/_pip.py +++ b/src/passa/internals/_pip.py @@ -7,6 +7,7 @@ import itertools import distutils.log import os +import re import distlib.database import distlib.metadata @@ -286,6 +287,58 @@ def install(self): pass +dist_info_re = re.compile(r"""^(?P(?P.+?)(-(?P.+?))?) + \.dist-info$""", re.VERBOSE) + + +def root_is_purelib(name, wheeldir): + """ + Return True if the extracted wheel in wheeldir should go into purelib. + """ + name_folded = name.replace("-", "_") + for item in os.listdir(wheeldir): + match = dist_info_re.match(item) + if match and match.group('name') == name_folded: + with open(os.path.join(wheeldir, item, 'WHEEL')) as wheel: + for line in wheel: + line = line.lower().rstrip() + if line == "root-is-purelib: true": + return True + return False + + +def get_entrypoints(filename): + import pkg_resources + if not os.path.exists(filename): + return {}, {} + + # This is done because you can pass a string to entry_points wrappers which + # means that they may or may not be valid INI files. The attempt here is to + # strip leading and trailing whitespace in order to make them valid INI + # files. + with open(filename) as fp: + data = io.StringIO() + for line in fp: + data.write(line.strip()) + data.write("\n") + data.seek(0) + + # get the entry points and then the script names + entry_points = pkg_resources.EntryPoint.parse_map(data) + console = entry_points.get('console_scripts', {}) + gui = entry_points.get('gui_scripts', {}) + + def _split_ep(s): + """get the string representation of EntryPoint, remove space and split + on '='""" + return str(s).replace(" ", "").split("=") + + # convert the EntryPoint objects into strings with module:function + console = dict(_split_ep(v) for v in console.values()) + gui = dict(_split_ep(v) for v in gui.values()) + return console, gui + + class BaseInstaller(NoopInstaller): """Virtualenv-capable installer""" diff --git a/src/passa/models/environments.py b/src/passa/models/environments.py index bc36263..ae67aa0 100644 --- a/src/passa/models/environments.py +++ b/src/passa/models/environments.py @@ -4,8 +4,12 @@ import importlib import json import os +import site import sys -import sysconfig + +from distutils.sysconfig import get_python_lib +from functools import partial +from sysconfig import get_paths import pkg_resources import six @@ -16,16 +20,22 @@ BASE_WORKING_SET = pkg_resources.WorkingSet(sys.path) +run = partial(vistir.misc.run, write_to_stdout=False, nospin=True, block=True) class Environment(object): def __init__(self, prefix=None, is_venv=False, base_working_set=None): self.base_working_set = base_working_set if base_working_set else BASE_WORKING_SET - self.is_venv = is_venv self._modules = {'pkg_resources': pkg_resources} self.extra_dists = [] prefix = prefix if prefix else sys.prefix + prefix = vistir.path.normalize_path(prefix) + sys_prefix = vistir.path.normalize_path(sys.prefix) + prefix = prefix if prefix else sys_prefix + self.is_venv = is_venv or prefix != sys_prefix self.prefix = vistir.compat.Path(prefix) + self.sys_paths = get_paths() + super(Environment, self).__init__() def safe_import(self, name): """Helper utility for reimporting previously imported modules while inside the env""" @@ -65,7 +75,7 @@ def resolve_dist(cls, dist, working_set): deps.add(dist) try: reqs = dist.requires() - except AttributeError: + except (AttributeError, OSError, IOError): # The METADATA file can't be found return deps for req in reqs: dist = working_set.find(req) @@ -97,83 +107,103 @@ def python_info(self): @cached_property def base_paths(self): - sysconfig = self.safe_import("sysconfig") + """ + Returns the context appropriate paths for the environment. + + :return: A dictionary of environment specific paths to be used for installation operations + :rtype: dict + + .. note:: The implementation of this is borrowed from a combination of pip and + virtualenv and is likely to change at some point in the future. + + >>> from pipenv.core import project + >>> from pipenv.environment import Environment + >>> env = Environment(prefix=project.virtualenv_location, is_venv=True, sources=project.sources) + >>> import pprint + >>> pprint.pprint(env.base_paths) + {'PATH': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/bin::/bin:/usr/bin', + 'PYTHONPATH': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7/site-packages', + 'data': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW', + 'include': '/home/hawk/.pyenv/versions/3.7.1/include/python3.7m', + 'libdir': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7/site-packages', + 'platinclude': '/home/hawk/.pyenv/versions/3.7.1/include/python3.7m', + 'platlib': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7/site-packages', + 'platstdlib': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7', + 'prefix': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW', + 'purelib': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/lib/python3.7/site-packages', + 'scripts': '/home/hawk/.virtualenvs/pipenv-MfOPs1lW/bin', + 'stdlib': '/home/hawk/.pyenv/versions/3.7.1/lib/python3.7'} + """ + prefix = self.prefix.as_posix() - scheme = sysconfig._get_default_scheme() - config = { - "base": prefix, - "installed_base": prefix, - "platbase": prefix, - "installed_platbase": prefix - } - config.update(self.python_info) - paths = { - k: v.format(**config) - for k, v in sysconfig._INSTALL_SCHEMES[scheme].items() - } + install_scheme = 'nt' if (os.name == 'nt') else 'posix_prefix' + paths = get_paths(install_scheme, vars={ + 'base': prefix, + 'platbase': prefix, + }) + paths["PATH"] = paths["scripts"] + os.pathsep + os.defpath if "prefix" not in paths: paths["prefix"] = prefix + purelib = get_python_lib(plat_specific=0, prefix=prefix) + platlib = get_python_lib(plat_specific=1, prefix=prefix) + if purelib == platlib: + lib_dirs = purelib + else: + lib_dirs = purelib + os.pathsep + platlib + paths["libdir"] = purelib + paths["purelib"] = purelib + paths["platlib"] = platlib + paths['PYTHONPATH'] = lib_dirs + paths["libdirs"] = lib_dirs return paths @cached_property def script_basedir(self): """Path to the environment scripts dir""" - script_dir = os.path.basename(sysconfig.get_paths()["scripts"]) + script_dir = self.base_paths["scripts"] return script_dir @property def python(self): """Path to the environment python""" - return self.prefix.joinpath(self.script_basedir).joinpath("python").as_posix() + py = vistir.compat.Path(self.base_paths["scripts"]).joinpath("python").as_posix() + if not py: + return vistir.compat.Path(sys.executable).as_posix() + return py @cached_property def sys_path(self): - """The system path inside the environment + """ + The system path inside the environment :return: The :data:`sys.path` from the environment :rtype: list """ current_executable = vistir.compat.Path(sys.executable).as_posix() - if self.python == current_executable: + if not self.python or self.python == current_executable: + return sys.path + elif any([sys.prefix == self.prefix, not self.is_venv]): return sys.path cmd_args = [self.python, "-c", "import json, sys; print(json.dumps(sys.path))"] - path = vistir.misc.run(cmd_args, return_object=True, nospin=True, block=True) - path = json.loads(path.out.strip()) + path, _ = run(cmd_args, return_object=False, combine_stderr=False) + path = json.loads(path.strip()) return path - @cached_property - def system_paths(self): - paths = {} - sysconfig = self.safe_import("sysconfig") - paths = sysconfig.get_paths() - return paths - @cached_property def sys_prefix(self): - """The prefix run inside the context of the environment + """ + The prefix run inside the context of the environment :return: The python prefix inside the environment :rtype: :data:`sys.prefix` """ command = [self.python, "-c" "import sys; print(sys.prefix)"] - c = vistir.misc.run(command, return_object=True, block=True, nospin=True) + c = run(command, return_object=True) sys_prefix = vistir.compat.Path(vistir.misc.to_text(c.out).strip()).as_posix() return sys_prefix - @cached_property - def paths(self): - paths = {} - with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): - os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(self.prefix.as_posix()) - os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") - os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") - paths = self.base_paths - if "headers" not in paths: - paths["headers"] = paths["include"] - return paths - @property def scripts_dir(self): return self.paths["scripts"] @@ -193,7 +223,48 @@ def get_distributions(self): """ pkg_resources = self.safe_import("pkg_resources") - return pkg_resources.find_distributions(self.paths["purelib"], only=True) + return pkg_resources.find_distributions(self.paths["PYTHONPATH"], only=True) + + def find_egg(self, egg_dist): + """Find an egg by name in the given environment""" + + site_packages = self.libdir[1] + search_filename = "{0}.egg-link".format(egg_dist.project_name) + try: + user_site = site.getusersitepackages() + except AttributeError: + user_site = site.USER_SITE + search_locations = [site_packages, user_site] + for site_directory in search_locations: + egg = os.path.join(site_directory, search_filename) + if os.path.isfile(egg): + return egg + + def locate_dist(self, dist): + """ + Given a distribution, try to find a corresponding egg link first. + + If the egg - link doesn 't exist, return the supplied distribution.""" + + location = self.find_egg(dist) + return location or dist.location + + def dist_is_in_project(self, dist): + """Determine whether the supplied distribution is in the environment.""" + + prefix = vistir.path.normalize_path(self.base_paths["prefix"]) + location = self.locate_dist(dist) + if not location: + return False + return vistir.path.normalize_path(location).startswith(prefix) + + def get_installed_packages(self): + """ + Returns all of the installed packages in a given environment""" + + workingset = self.get_working_set() + packages = [pkg for pkg in workingset if self.dist_is_in_project(pkg)] + return packages def get_working_set(self): """Retrieve the working set of installed packages for the environment. @@ -230,7 +301,7 @@ def run(self, cmd, cwd=os.curdir): c = None with self.activated(): script = vistir.cmdparse.Script.parse(cmd) - c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) + c = run(script._parts, return_object=True, cwd=cwd) return c def run_py(self, cmd, cwd=os.curdir): @@ -249,7 +320,7 @@ def run_py(self, cmd, cwd=os.curdir): else: script = vistir.cmdparse.Script.parse([self.python, "-c"] + list(cmd)) with self.activated(): - c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) + c = run(script._parts, return_object=True, cwd=cwd) return c def run_activate_this(self): @@ -285,7 +356,6 @@ def activated(self, include_extras=True, extra_dists=None): if not extra_dists: extra_dists = [] - original_path = sys.path original_prefix = sys.prefix parent_path = vistir.compat.Path(__file__).absolute().parent.parent.as_posix() prefix = self.prefix.as_posix() @@ -293,18 +363,19 @@ def activated(self, include_extras=True, extra_dists=None): os.environ["PATH"] = os.pathsep.join([ vistir.compat.fs_str(self.scripts_dir), vistir.compat.fs_str(self.prefix.as_posix()), - os.environ.get("PATH", "") + os.environ.get("PATH", os.defpath) ]) os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") - os.environ["PYTHONUSERBASE"] = vistir.compat.fs_str(prefix) + os.environ["PYTHONPATH"] = self.base_paths["PYTHONPATH"] if self.is_venv: os.environ["VIRTUAL_ENV"] = vistir.compat.fs_str(prefix) sys.path = self.sys_path sys.prefix = self.sys_prefix pkg_resources = self.safe_import("pkg_resources") + site = self.safe_import("site") + site.addsitedir(self.libdir[1]) if include_extras: - site = self.safe_import("site") site.addsitedir(parent_path) extra_dists = list(self.extra_dists) + extra_dists for extra_dist in extra_dists: @@ -313,7 +384,6 @@ def activated(self, include_extras=True, extra_dists=None): try: yield finally: - sys.path = original_path sys.prefix = original_prefix six.moves.reload_module(pkg_resources) From 038621f9bda8e36039a3cd0fd53e558de8c2286c Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Wed, 12 Dec 2018 01:30:37 -0500 Subject: [PATCH 25/26] Add session closures, fix a bunch of test failures Signed-off-by: Dan Ryan --- Pipfile.lock | 94 ++++++++++++----------------- setup.cfg | 7 ++- src/passa/internals/_pip.py | 52 ++++++++-------- src/passa/internals/dependencies.py | 28 ++++----- src/passa/internals/utils.py | 44 +++++++++++++- src/passa/models/caches.py | 44 ++++++++++---- src/passa/models/environments.py | 13 ++++ src/passa/models/synchronizers.py | 71 +++++++++++----------- tasks/admin.py | 8 +++ tox.ini | 9 +-- 10 files changed, 225 insertions(+), 145 deletions(-) diff --git a/Pipfile.lock b/Pipfile.lock index 481946a..6dca024 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "98ad4ec51e7ea8861ce2e31ac6d39a134251d84a2a7b47f2053e905900312639" + "sha256": "2c60c86f5fbcfab3b4b94e06a793479341cd462c3868f40ca1efffd795ad9a20" }, "pipfile-spec": 6, "requires": {}, @@ -87,7 +87,6 @@ "hashes": [ "sha256:8ee9fe5b925e1001f6ae6c017e93682583d2b4d1ef7130a26cfcdf1651c0032c" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.2.0" }, "distlib": { @@ -115,7 +114,12 @@ }, "functools32": { "file": "https://github.com/sarugaku/functools32/releases/download/3.2.3-2/functools32-3.2.3.post2-py2.py3-none-any.whl", - "markers": "python_version < '3.0' or python_version < '3.0' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version < '3.0' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'" + "hashes": [ + "sha256:89d824aa6c358c421a234d7f9ee0bd75933a67c29588ce50aaa3acdf4d403fa0", + "sha256:f6253dfbe0538ad2e387bd8fdfd9293c925d63553f5813c4e587745416501e6d" + ], + "markers": "python_version < '3.0'", + "version": "==3.2.3.post2" }, "idna": { "hashes": [ @@ -124,12 +128,26 @@ ], "version": "==2.8" }, - "importlib": { + "installer": { + "hashes": [ + "sha256:1ba23de573e9b95a8dcbd04fd026c40a64b77db0aadc48f28a844b4cb87479fe", + "sha256:f4f195c9b17ea7d2b631a758451485c6b080975349b4adebe45ef4bb022db069" + ], + "version": "==0.1.1" + }, + "mork": { "hashes": [ - "sha256:b6ee7066fea66e35f8d0acee24d98006de1a0a8a94a8ce6efe73a9a23c8d9826" + "sha256:13772edb4724915cf0cfa30d31426e0565487a3b2d7883b8468718eaed8ecfc2", + "sha256:b1b41bc31603eef1b50e42e75ae2d74d7a0d9ab46ea4d0dd1ba387a451870873" ], - "markers": "python_version < '2.7' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.0.4" + "version": "==0.1.4" + }, + "packagebuilder": { + "hashes": [ + "sha256:1e85c4e0e994322996b93cd6685c12834d30f3558889154f8e3de8fb1f3fd1e7", + "sha256:dc525d06ecd102db23ab421b879d7d27021d784ff933e33e8c411a53af5c9dbe" + ], + "version": "==0.1.0" }, "packaging": { "hashes": [ @@ -158,7 +176,6 @@ "sha256:cc663a438fdfe2e88d8d3c5ef2203ac858de34e31b6609b1fc505d611490a926", "sha256:f79bb08fb064dfc5b141204bfeb56a4141a6d504677fab4723036a464fc25cc1" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.3" }, "pip-shims": { @@ -402,7 +419,6 @@ "sha256:47f9c83ef4c0c621eaef743f133f09fa8a74a9b75f037e8624f83bd1b6626cb7", "sha256:993f830721089fef441cdfeb4b2c8c9df86f0c63239f06bd025a76a7daddb033" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2018.11.29" }, "chardet": { @@ -493,7 +509,6 @@ "sha256:ed02c7539705696ecb7dc9d476d861f3904a8d2b7e894bd418994920935d36bb", "sha256:ee5b8abc35b549012e03a7b1e86c09491457dba6c94112a2482b18589cc2bdb9" ], - "markers": "python_version < '4' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==4.5.2" }, "cursor": { @@ -580,13 +595,6 @@ ], "version": "==1.1.0" }, - "importlib": { - "hashes": [ - "sha256:b6ee7066fea66e35f8d0acee24d98006de1a0a8a94a8ce6efe73a9a23c8d9826" - ], - "markers": "python_version < '2.7' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.0.4" - }, "incremental": { "hashes": [ "sha256:717e12246dddf231a349175f48d74d93e2897244939173b01974ab6661406b9f", @@ -649,14 +657,6 @@ ], "version": "==1.1.0" }, - "modutil": { - "hashes": [ - "sha256:2c85c1666649e92e56de17c00e1e831313602d9b55e8661d39c01e39003b45f7", - "sha256:cc3dad264e36ed359fdd67c4588959d2996bd0402ad9c9d974ca906821537218" - ], - "markers": "python_version >= '2.6' and python_version >= '3.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==2.0.0" - }, "more-itertools": { "hashes": [ "sha256:c187a73da93e7a8acc0001572aebc7e3c69daf7bf6881a2cea10650bd4420092", @@ -665,6 +665,13 @@ ], "version": "==4.3.0" }, + "packagebuilder": { + "hashes": [ + "sha256:1e85c4e0e994322996b93cd6685c12834d30f3558889154f8e3de8fb1f3fd1e7", + "sha256:dc525d06ecd102db23ab421b879d7d27021d784ff933e33e8c411a53af5c9dbe" + ], + "version": "==0.1.0" + }, "packaging": { "hashes": [ "sha256:0886227f54515e592aaa2e5a553332c73962917f2831f1b0f9b9f4380a4b9807", @@ -677,7 +684,6 @@ "sha256:b8b2976fd8a73a0515465b2a265fd9b20cc25a6dc88bc1154fd5f60f10dad4db", "sha256:d9ae08a2629105fdb83e4971ae8a04f1de5a3803d1dd928f6e181aeadb398180" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2.0" }, "passa": { @@ -766,6 +772,13 @@ "sha256:1d131cc532be0023ef8ae265e2a779938d0619bb6c2510f52987ffcba7fa1ee4", "sha256:ca4761407f1acc85ffd1609f464ca20bb71a767803505bd4127d0e45c5a50e23" ], + "version": "==4.0.1" + }, + "pytest-cov": { + "hashes": [ + "sha256:513c425e931a0344944f84ea47f3956be0e416d95acbd897a44970c8d926d5d7", + "sha256:e360f048b7dae3f2f2a9a4d067b2dd6b6a015d384d1577c994a43f3f7cbad762" + ], "version": "==2.6.0" }, "pytest-forked": { @@ -844,29 +857,12 @@ ], "version": "==0.2.2" }, - "scandir": { - "hashes": [ - "sha256:04b8adb105f2ed313a7c2ef0f1cf7aff4871aa7a1883fa4d8c44b5551ab052d6", - "sha256:1444134990356c81d12f30e4b311379acfbbcd03e0bab591de2696a3b126d58e", - "sha256:1b5c314e39f596875e5a95dd81af03730b338c277c54a454226978d5ba95dbb6", - "sha256:346619f72eb0ddc4cf355ceffd225fa52506c92a2ff05318cfabd02a144e7c4e", - "sha256:44975e209c4827fc18a3486f257154d34ec6eaec0f90fef0cca1caa482db7064", - "sha256:61859fd7e40b8c71e609c202db5b0c1dbec0d5c7f1449dec2245575bdc866792", - "sha256:a5e232a0bf188362fa00123cc0bb842d363a292de7126126df5527b6a369586a", - "sha256:c14701409f311e7a9b7ec8e337f0815baf7ac95776cc78b419a1e6d49889a383", - "sha256:c7708f29d843fc2764310732e41f0ce27feadde453261859ec0fca7865dfc41b", - "sha256:c9009c527929f6e25604aec39b0a43c3f831d2947d89d6caaab22f057b7055c8", - "sha256:f5c71e29b4e2af7ccdc03a020c626ede51da471173b4a6ad1e904f2b2e04b4bd" - ], - "markers": "python_version < '3.5' and python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' or python_version < '3.5' and python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", - "version": "==1.9.0" - }, "six": { "hashes": [ "sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c", "sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73" ], - "version": "==1.11.0" + "version": "==1.12.0" }, "snowballstemmer": { "hashes": [ @@ -880,7 +876,6 @@ "sha256:120732cbddb1b2364471c3d9f8bfd4b0c5b550862f99a65736c77f970b142aea", "sha256:b348790776490894e0424101af9c8413f2a86831524bd55c5f379d3e3e12ca64" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==1.8.2" }, "sphinx-rtd-theme": { @@ -948,13 +943,6 @@ ], "version": "==1.24.1" }, - "virtualenv": { - "hashes": [ - "sha256:686176c23a538ecc56d27ed9d5217abd34644823d6391cbeb232f42bf722baad", - "sha256:f899fafcd92e1150f40c8215328be38ff24b519cd95357fa6e78e006c7638208" - ], - "version": "==16.1.0" - }, "vistir": { "extras": [ "spinner" @@ -963,7 +951,6 @@ "sha256:3a1020fb7be000b268af96641ced9ead844b1f75840c41e20e473647688fc630", "sha256:6d2005ad670f77bd9c9b5415c4e2a4a20dce5b0cf0e0d11598eb463b2e0ebe44" ], - "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.2.5" }, "webencodings": { @@ -971,7 +958,6 @@ "sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78", "sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923" ], - "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==0.5.1" }, "wheel": { diff --git a/setup.cfg b/setup.cfg index 51741a5..fbd97bb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -95,7 +95,7 @@ ignore = # E231: missing whitespace after ',' # E402: module level import not at top of file # E501: line too long - E127,E128,E129,E222,E231,E402,E501 + E231,E402,E501 [tool:pytest] strict = true @@ -108,3 +108,8 @@ filterwarnings = [build-system] requires = ["setuptools", "wheel"] + +[mypy] +ignore_missing_imports=true +follow_imports=skip +python_version=2.7 diff --git a/src/passa/internals/_pip.py b/src/passa/internals/_pip.py index 6c59c25..7b1a067 100644 --- a/src/passa/internals/_pip.py +++ b/src/passa/internals/_pip.py @@ -93,21 +93,21 @@ def _get_pip_session(trusted_hosts): options, _ = cmd.parser.parse_args([]) options.cache_dir = CACHE_DIR options.trusted_hosts = trusted_hosts - session = cmd._build_session(options) - return session + return cmd._build_session(options) +@contextlib.contextmanager def _get_finder(sources): index_urls, trusted_hosts = _get_pip_index_urls(sources) - session = _get_pip_session(trusted_hosts) - finder = pip_shims.PackageFinder( - find_links=[], - index_urls=index_urls, - trusted_hosts=trusted_hosts, - allow_all_prereleases=True, - session=session, - ) - return finder + with contextlib.closing(_get_pip_session(trusted_hosts)) as session: + finder = pip_shims.PackageFinder( + find_links=[], + index_urls=index_urls, + trusted_hosts=trusted_hosts, + allow_all_prereleases=True, + session=session, + ) + yield finder def _get_wheel_cache(): @@ -140,7 +140,7 @@ class WheelBuildError(RuntimeError): pass -def build_wheel(ireq, sources, hashes=None): +def build_wheel(ireq, sources, finder, hashes=None): """Build a wheel file for the InstallRequirement object. An artifact is downloaded (or read from cache). If the artifact is not a @@ -154,7 +154,6 @@ def build_wheel(ireq, sources, hashes=None): `RuntimeError` subclass) if the wheel cannot be built. """ kwargs = _prepare_wheel_building_kwargs(ireq) - finder = _get_finder(sources) # Not for upgrade, hash not required. Hashes are not required here even # when we provide them, because pip skips local wheel cache if we set it @@ -207,8 +206,10 @@ def get_vcs_ref(requirement): def find_installation_candidates(ireq, sources): - finder = _get_finder(sources) - return finder.find_all_candidates(ireq.name) + candidates = [] + with _get_finder(sources) as finder: + candidates = finder.find_all_candidates(ireq.name) + return candidates class RequirementUninstaller(object): @@ -381,16 +382,17 @@ def installation_args(self): return install_args def build_wheel(self): - self.built = build_wheel(self.ireq, self.sources, self.hashes) - self.metadata = self.built.metadata + with _get_finder(self.sources) as finder: + self.built = build_wheel(self.ireq, self.sources, finder, self.hashes) + self.metadata = self.built.metadata self.is_wheel = True def build_sdist(self): - finder = _get_finder(self.sources) - self.ireq.populate_link(finder, False, False) - self.ireq.ensure_has_source_dir(self.src_dir) - self.built = get_sdist(self.ireq) - self.metadata = read_sdist_metadata(self.ireq) + with _get_finder(self.sources) as finder: + self.ireq.populate_link(finder, False, False) + self.ireq.ensure_has_source_dir(self.src_dir) + self.built = get_sdist(self.ireq) + self.metadata = read_sdist_metadata(self.ireq) def install_wheel(self): scripts = distlib.scripts.ScriptMaker(None, None) @@ -398,8 +400,10 @@ def install_wheel(self): def install_sdist(self): with vistir.cd(self.setup_dir.as_posix()), _suppress_distutils_logs(): - c = self.environment.run(self.installation_args, return_object=True, - block=True, nospin=True) + c = self.environment.run( + self.installation_args, return_object=True, block=True, nospin=True, + combine_stderr=False, write_to_stdout=False + ) if c.returncode != 0: err_text = "{0!r}: {1!r}".format(c.err, c.out) raise RuntimeError("Failed to install package: {0!r}".format(err_text)) diff --git a/src/passa/internals/dependencies.py b/src/passa/internals/dependencies.py index a2b0cbc..6c74b47 100644 --- a/src/passa/internals/dependencies.py +++ b/src/passa/internals/dependencies.py @@ -141,20 +141,20 @@ def _get_dependencies_from_json(ireq, sources): if proc_url.endswith("/simple") ] - session = requests.session() - - for prefix in url_prefixes: - url = "{prefix}/pypi/{name}/{version}/json".format( - prefix=prefix, - name=packaging.utils.canonicalize_name(ireq.name), - version=version, - ) - try: - dependencies = _get_dependencies_from_json_url(url, session) - if dependencies is not None: - return dependencies - except Exception as e: - print("unable to read dependencies via {0} ({1})".format(url, e)) + with requests.session() as session: + + for prefix in url_prefixes: + url = "{prefix}/pypi/{name}/{version}/json".format( + prefix=prefix, + name=packaging.utils.canonicalize_name(ireq.name), + version=version, + ) + try: + dependencies = _get_dependencies_from_json_url(url, session) + if dependencies is not None: + return dependencies + except Exception as e: + print("unable to read dependencies via {0} ({1})".format(url, e)) return diff --git a/src/passa/internals/utils.py b/src/passa/internals/utils.py index 8f8e6fd..d9d6c0d 100644 --- a/src/passa/internals/utils.py +++ b/src/passa/internals/utils.py @@ -1,9 +1,33 @@ # -*- coding=utf-8 -*- -from __future__ import absolute_import, unicode_literals +from __future__ import absolute_import, unicode_literals, print_function + +import atexit +import os + +import requests + + +def is_type_checking(): + # type: () -> bool + try: + from typing import TYPE_CHECKING + except ImportError: + return False + return TYPE_CHECKING + + +MYPY_RUNNING = os.environ.get("MYPY_RUNNING", is_type_checking()) + + +if MYPY_RUNNING: + from typing import Any, List, Dict # noqa + from requirementslib.models.requirements import Requirement # noqa + from pip_shims.shims import InstallRequirement # noqa def identify_requirment(r): + # type: (Requirement) -> str """Produce an identifier for a requirement to use in the resolver. Note that we are treating the same package with different extras as @@ -18,6 +42,7 @@ def identify_requirment(r): def get_pinned_version(ireq): + # type: (InstallRequirement) -> str """Get the pinned version of an InstallRequirement. An InstallRequirement is considered pinned if: @@ -60,6 +85,7 @@ def get_pinned_version(ireq): def is_pinned(ireq): + # type: (InstallRequirement) -> bool """Returns whether an InstallRequirement is a "pinned" requirement. An InstallRequirement is considered pinned if: @@ -83,6 +109,7 @@ def is_pinned(ireq): def filter_sources(requirement, sources): + # type: (Requirement, List[Dict[str, Union[bool, str]]]) -> List[Dict[str, Union[bool, str]]] """Returns a filtered list of sources for this requirement. This considers the index specified by the requirement, and returns only @@ -98,11 +125,13 @@ def filter_sources(requirement, sources): def get_allow_prereleases(requirement, global_setting): + # type: (Requirement, bool) -> bool # TODO: Implement per-package prereleases flag. (pypa/pipenv#1696) return global_setting def are_requirements_equal(this, that): + # type: (Requirement, Requirement) -> bool return ( this.as_line(include_hashes=False) == that.as_line(include_hashes=False) @@ -110,9 +139,22 @@ def are_requirements_equal(this, that): def strip_extras(requirement): + # type: (Requirement) -> Requirement """Returns a new requirement object with extras removed. """ line = requirement.as_line() new = type(requirement).from_line(line) new.extras = None return new + + +REQUESTS_SESSIONS = [] # type: List[requests.Session] + + +def get_tracked_session(): + # type: () -> requests.Session + """Build a requests session and register it to be closed with interpreter exit""" + + session = requests.Session() + atexit.register(session.close) + return session diff --git a/src/passa/models/caches.py b/src/passa/models/caches.py index c6d29b5..ed8c92f 100644 --- a/src/passa/models/caches.py +++ b/src/passa/models/caches.py @@ -10,25 +10,33 @@ import appdirs import pip_shims -import requests import vistir from ..internals._pip_shims import VCS_SUPPORT -from ..internals.utils import get_pinned_version +from ..internals.utils import get_pinned_version, get_tracked_session, MYPY_RUNNING -CACHE_DIR = os.environ.get("PASSA_CACHE_DIR", appdirs.user_cache_dir("passa")) +if MYPY_RUNNING: + import requests # noqa + from typing import Optional # noqa + + +CACHE_DIR = os.environ.get("PASSA_CACHE_DIR", appdirs.user_cache_dir("passa")) # type: ignore class HashCache(pip_shims.SafeFileCache): + """Caches hashes of PyPI artifacts so we do not need to re-download them. Hashes are only cached when the URL appears to contain a hash in it and the cache key includes the hash value returned from the server). This ought to avoid ssues where the location on the server changes. """ + def __init__(self, *args, **kwargs): - session = kwargs.pop('session', requests.session()) + session = kwargs.pop('session', None) # type: requests.Session + if session is None: + session = get_tracked_session() self.session = session kwargs.setdefault('directory', os.path.join(CACHE_DIR, 'hash-cache')) super(HashCache, self).__init__(*args, **kwargs) @@ -76,6 +84,7 @@ def __str__(self): def _key_from_req(req): """Get an all-lowercase version of the requirement's name.""" + if hasattr(req, 'key'): # from pkg_resources, such as installed dists for pip-sync key = req.key @@ -100,6 +109,7 @@ def _read_cache_file(cache_file_path): class _JSONCache(object): + """A persistent cache backed by a JSON file. The cache file is written to the appropriate user cache dir for the @@ -109,7 +119,8 @@ class _JSONCache(object): Where X.Y indicates the Python version. """ - filename_format = None + + filename_format = None # type: Optional[str] def __init__(self, cache_dir=CACHE_DIR): vistir.mkdir_p(cache_dir) @@ -122,10 +133,12 @@ def __init__(self, cache_dir=CACHE_DIR): @property def cache(self): - """The dictionary that is the actual in-memory cache. + """ + The dictionary that is the actual in-memory cache. This property lazily loads the cache from disk. """ + if self._cache is None: self.read_cache() return self._cache @@ -144,6 +157,7 @@ def as_cache_key(self, ireq): ("ipython", "2.1.0[nbconvert,notebook]") """ + extras = tuple(sorted(ireq.extras)) if not extras: extras_string = "" @@ -154,16 +168,16 @@ def as_cache_key(self, ireq): return name, "{}{}".format(version, extras_string) def read_cache(self): - """Reads the cached contents into memory. - """ + """Reads the cached contents into memory.""" + if os.path.exists(self._cache_file): self._cache = _read_cache_file(self._cache_file) else: self._cache = {} def write_cache(self): - """Writes the cache to disk as JSON. - """ + """Writes the cache to disk as JSON.""" + doc = { '__format__': 1, 'dependencies': self._cache, @@ -203,12 +217,18 @@ def get(self, ireq, default=None): class DependencyCache(_JSONCache): - """Cache the dependency of cancidates. + """ + Cache the dependency of cancidates. + """ + filename_format = "depcache-py{python_version}.json" class RequiresPythonCache(_JSONCache): - """Cache a candidate's Requires-Python information. + """ + Cache a candidate's Requires-Python information. + """ + filename_format = "pyreqcache-py{python_version}.json" diff --git a/src/passa/models/environments.py b/src/passa/models/environments.py index ae67aa0..bb52d13 100644 --- a/src/passa/models/environments.py +++ b/src/passa/models/environments.py @@ -215,6 +215,19 @@ def libdir(self): return "purelib", purelib return "platlib", self.paths["platlib"] + @cached_property + def paths(self): + paths = {} + with vistir.contextmanagers.temp_environ(), vistir.contextmanagers.temp_path(): + os.environ["PYTHONIOENCODING"] = vistir.compat.fs_str("utf-8") + os.environ["PYTHONDONTWRITEBYTECODE"] = vistir.compat.fs_str("1") + paths = self.base_paths + os.environ["PATH"] = paths["PATH"] + os.environ["PYTHONPATH"] = paths["PYTHONPATH"] + if "headers" not in paths: + paths["headers"] = paths["include"] + return paths + def get_distributions(self): """Retrives the distributions installed on the library path of the environment diff --git a/src/passa/models/synchronizers.py b/src/passa/models/synchronizers.py index c2f9bad..6842950 100644 --- a/src/passa/models/synchronizers.py +++ b/src/passa/models/synchronizers.py @@ -18,14 +18,14 @@ from ..internals._pip import uninstall, Installer -def _is_installation_local(name, venv=None): +def _is_installation_local(name, environment=None): """Check whether the distribution is in the current Python installation. - This is used to distinguish packages seen by a virtual environment. A venv + This is used to distinguish packages seen by a virtual environment. A environment may be able to see global packages, but we don't want to mess with them. """ - if venv: - return venv.is_installed(name) + if environment: + return environment.is_installed(name) loc = os.path.normcase(pkg_resources.working_set.by_key[name].location) pre = os.path.normcase(sys.prefix) return os.path.commonprefix([loc, pre]) == pre @@ -41,13 +41,13 @@ def _is_up_to_date(distro, version): ]) -def _group_installed_names(packages, venv=None): +def _group_installed_names(packages, environment=None): """Group locally installed packages based on given specifications. `packages` is a name-package mapping that are used as baseline to determine how the installed package should be grouped. - `venv` is the virtual environment object of the virtualenv being installed into. + `environment` is the virtual environment object of the virtualenv being installed into. Returns a 3-tuple of disjoint sets, all containing names of installed packages: @@ -59,8 +59,8 @@ def _group_installed_names(packages, venv=None): """ groupcoll = GroupCollection(set(), set(), set(), set()) - if venv: - working_set = venv.get_working_set() + if environment: + working_set = environment.get_working_set() else: working_set = pkg_resources.working_set @@ -85,13 +85,13 @@ def _group_installed_names(packages, venv=None): @contextlib.contextmanager -def _remove_package(name, venv=None): - if name is None or not _is_installation_local(name, venv=venv): +def _remove_package(name, environment=None): + if name is None or not _is_installation_local(name, environment=environment): yield None return _uninstall = uninstall - if venv: - _uninstall = venv.uninstall + if environment: + _uninstall = environment.uninstall with _uninstall(name, auto_confirm=True, verbose=False) as uninstaller: yield uninstaller @@ -108,15 +108,15 @@ def _get_packages(lockfile, default, develop): return packages -def _build_paths(venv=None): +def _build_paths(environment=None): """Prepare paths for distlib.wheel.Wheel to install into. """ - if venv: - paths = venv.paths + if environment: + paths = environment.paths else: paths = sysconfig.get_paths() return { - "prefix": sys.prefix if not venv else venv.venv_dir.as_posix(), + "prefix": sys.prefix if not environment else environment.prefix.as_posix(), "data": paths["data"], "scripts": paths["scripts"], "headers": paths["include"], @@ -128,12 +128,12 @@ def _build_paths(venv=None): PROTECTED_FROM_CLEAN = {"setuptools", "pip", "wheel"} -def _clean(names, venv=None): +def _clean(names, environment=None): cleaned = set() for name in names: if name in PROTECTED_FROM_CLEAN: continue - with _remove_package(name, venv=venv) as uninst: + with _remove_package(name, environment=environment) as uninst: if uninst: cleaned.add(name) return cleaned @@ -142,35 +142,36 @@ def _clean(names, venv=None): class Synchronizer(object): """Helper class to install packages from a project's lock file. """ - def __init__(self, project, default, develop, clean_unneeded, venv=None): + def __init__(self, project, default, develop, clean_unneeded, environment=None): self._root = project.root # Only for repr. self.project = project self.packages = _get_packages(project.lockfile, default, develop) self.sources = project.lockfile.meta.sources._data self.clean_unneeded = clean_unneeded - if not venv: - self._venv = getattr(project, "venv", None) + if not environment: + self._environment = getattr(project, "environment", None) else: - self._venv = venv - self.paths = _build_paths(venv=self.venv) + self._environment = environment + super(Synchronizer, self).__init__() + self.paths = _build_paths(environment=self.environment) @property - def venv(self): - if self._venv: - return self._venv - return self.project.venv + def environment(self): + if self._environment: + return self._environment + return self.project.environment def __repr__(self): return "<{0} @ {1!r}>".format(type(self).__name__, self._root) def sync(self): - if not self.venv: + if not self.environment: return self._sync() - with self.venv.activated(): + with self.environment.activated(): return self._sync() def _sync(self): - groupcoll = _group_installed_names(self.packages, venv=self.venv) + groupcoll = _group_installed_names(self.packages, environment=self.environment) installed = set() updated = set() @@ -179,7 +180,7 @@ def _sync(self): # TODO: Show a prompt to confirm cleaning. We will need to implement a # reporter pattern for this as well. if self.clean_unneeded: - names = _clean(groupcoll.unneeded, venv=self.venv) + names = _clean(groupcoll.unneeded, environment=self.environment) cleaned.update(names) # TODO: Specify installation order? (pypa/pipenv#2274) @@ -193,7 +194,7 @@ def _sync(self): if markers and not packaging.markers.Marker(markers).evaluate(): continue r.markers = None - installer = Installer(r, sources=self.sources, paths=self.paths, venv=self.venv) + installer = Installer(r, sources=self.sources, paths=self.paths, environment=self.environment) try: installer.prepare() except Exception as e: @@ -211,7 +212,7 @@ def _sync(self): else: name_to_remove = None try: - with _remove_package(name_to_remove, venv=self.venv): + with _remove_package(name_to_remove, environment=self.environment): installer.install() except Exception as e: if os.environ.get("PASSA_NO_SUPPRESS_EXCEPTIONS"): @@ -248,10 +249,10 @@ def print(self, packages): print(message.format(", ".join(sorted(set(packages))))) def clean(self): - groupcoll = _group_installed_names(self.packages, venv=self.project.venv) + groupcoll = _group_installed_names(self.packages, environment=self.project.environment) cleaned = set() if self.sync: - cleaned = _clean(groupcoll.unneeded, venv=self.project.venv) + cleaned = _clean(groupcoll.unneeded, environment=self.project.environment) else: return groupcoll.unneeded return cleaned diff --git a/tasks/admin.py b/tasks/admin.py index 2fabe99..fa1be74 100644 --- a/tasks/admin.py +++ b/tasks/admin.py @@ -14,6 +14,14 @@ INIT_PY = ROOT.joinpath('src', PACKAGE_NAME, '__init__.py') +@invoke.task() +def typecheck(ctx): + src_dir = ROOT / "src" / PACKAGE_NAME + src_dir = src_dir.as_posix() + env = {"MYPYPATH": src_dir} + ctx.run(f"mypy {src_dir}", env=env) + + @invoke.task() def clean(ctx): """Clean previously built package artifacts. diff --git a/tox.ini b/tox.ini index 6428cef..5c0a6dd 100644 --- a/tox.ini +++ b/tox.ini @@ -33,8 +33,9 @@ commands = [testenv:packaging] deps = - check-manifest - readme_renderer + setuptools + twine + readme_renderer[md] commands = - check-manifest - python setup.py check -m -r -s + python setup.py sdist bdist_wheel + twine check dist/* From 3ed2038b6ef4bf8645c8a29b9aa233a802bf987a Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Wed, 12 Dec 2018 01:45:57 -0500 Subject: [PATCH 26/26] remove extra kwarg Signed-off-by: Dan Ryan --- src/passa/models/synchronizers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/passa/models/synchronizers.py b/src/passa/models/synchronizers.py index 6842950..1ba8fa6 100644 --- a/src/passa/models/synchronizers.py +++ b/src/passa/models/synchronizers.py @@ -194,7 +194,7 @@ def _sync(self): if markers and not packaging.markers.Marker(markers).evaluate(): continue r.markers = None - installer = Installer(r, sources=self.sources, paths=self.paths, environment=self.environment) + installer = Installer(r, sources=self.sources, environment=self.environment) try: installer.prepare() except Exception as e: