Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grab updates from latest vendored changes #3196

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
36f054d
Grab updates from latest vendored changes
techalchemy Nov 8, 2018
5b49670
Fix broken requirementslib updates
techalchemy Nov 8, 2018
f3003b6
Merge branch 'master' into update-vendor
techalchemy Nov 8, 2018
2b90c89
Revendor requirementslib
techalchemy Nov 11, 2018
dec7be5
Introduce `pipenv.environments.Environment`
techalchemy Nov 11, 2018
642b6f9
Update vistir and requirementslib
techalchemy Nov 11, 2018
45100b8
Fix stdout and stderr wrappers
techalchemy Nov 11, 2018
5602952
Merge branch 'update-vendor' of github.com:pypa/pipenv into update-ve…
techalchemy Nov 11, 2018
8644611
Merge branch 'master' into update-vendor
techalchemy Nov 11, 2018
0caf7a0
Fix configparser import
techalchemy Nov 11, 2018
650cc32
Fix resource errors
techalchemy Nov 11, 2018
382be38
Fix python 2.7 installations
techalchemy Nov 12, 2018
489e534
Fix various bugs with python 2.7 and vendored deps
techalchemy Nov 12, 2018
32b1113
Support python 2 parsing
techalchemy Nov 12, 2018
1216ae0
Fix environment site import
techalchemy Nov 12, 2018
70fc92b
Fix import errors on setup parsing
techalchemy Nov 12, 2018
013e3d0
Revendor
techalchemy Nov 12, 2018
96cbd58
Fix prefix comparison for py2
techalchemy Nov 12, 2018
8fa4057
Merge branch 'master' into update-vendor
techalchemy Nov 12, 2018
9eabde0
no samefile for windows python2.7
techalchemy Nov 12, 2018
ef59d15
Fix bugs in environment implementation
techalchemy Nov 13, 2018
cb601b0
Fix syntax
techalchemy Nov 13, 2018
13c9e62
Update pythonfinder
techalchemy Nov 13, 2018
7bc754a
Merge branch 'master' into update-vendor
techalchemy Nov 13, 2018
d73879b
Update requirementslib
techalchemy Nov 13, 2018
e328ae2
Fix feedback
techalchemy Nov 13, 2018
310e0b2
Fix pythonfinder
techalchemy Nov 13, 2018
6b3c9a7
Remove accidentally committed test script
techalchemy Nov 13, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3196.vendor.rst
@@ -0,0 +1 @@
Updated ``requirementslib`` to aid in resolution of local and remote archives.
12 changes: 8 additions & 4 deletions pipenv/__init__.py
Expand Up @@ -10,7 +10,7 @@

from .__version__ import __version__

PIPENV_ROOT = os.path.dirname(os.path.realpath(__file__))
PIPENV_ROOT = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
PIPENV_VENDOR = os.sep.join([PIPENV_ROOT, "vendor"])
PIPENV_PATCHED = os.sep.join([PIPENV_ROOT, "patched"])
# Inject vendored directory into system path.
Expand All @@ -27,11 +27,15 @@
if sys.version_info >= (3, 1) and sys.version_info <= (3, 6):
if sys.stdout.isatty() and sys.stderr.isatty():
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf8')
import atexit
stdout_wrapper = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')
atexit.register(stdout_wrapper.close)
stderr_wrapper = io.TextIOWrapper(sys.stderr.buffer, encoding='utf8')
atexit.register(stderr_wrapper.close)
sys.stdout = stdout_wrapper
sys.stderr = stderr_wrapper

os.environ["PIP_DISABLE_PIP_VERSION_CHECK"] = fs_str("1")
os.environ["PIP_SHIMS_BASE_MODULE"] = fs_str("pipenv.patched.notpip")

# Hack to make things work better.
try:
Expand Down
2 changes: 1 addition & 1 deletion pipenv/_compat.py
Expand Up @@ -382,7 +382,7 @@ def decode_output(output):
except (AttributeError, UnicodeDecodeError, UnicodeEncodeError):
if six.PY2:
output = unicode.translate(vistir.misc.to_text(output),
UNICODE_TO_ASCII_TRANSLATION_MAP)
UNICODE_TO_ASCII_TRANSLATION_MAP)
else:
output = output.translate(UNICODE_TO_ASCII_TRANSLATION_MAP)
output = output.encode(DEFAULT_ENCODING, "replace")
Expand Down
131 changes: 71 additions & 60 deletions pipenv/core.py
Expand Up @@ -40,8 +40,8 @@
clean_resolved_dep,
parse_indexes,
escape_cmd,
fix_venv_site,
create_spinner,
get_canonical_names
)
from . import environments, pep508checker, progress
from .environments import (
Expand Down Expand Up @@ -915,7 +915,16 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
project_file_name = os.path.join(project.virtualenv_location, ".project")
with open(project_file_name, "w") as f:
f.write(vistir.misc.fs_str(project.project_directory))
fix_venv_site(project.env_paths["lib"])
from .environment import Environment
sources = project.pipfile_sources
project._environment = Environment(
prefix=project.get_location_for_virtualenv(),
is_venv=True,
sources=sources,
pipfile=project.parsed_pipfile,
project=project
)
project._environment.add_dist("pipenv")
# Say where the virtualenv is.
do_where(virtualenv=True, bare=False)

Expand Down Expand Up @@ -1076,7 +1085,7 @@ def do_purge(bare=False, downloads=False, allow_global=False):

# Remove comments from the output, if any.
installed = set([
pep423_name(pkg.project_name) for pkg in project.get_installed_packages()
pep423_name(pkg.project_name) for pkg in project.environment.get_installed_packages()
])
bad_pkgs = set([pep423_name(pkg) for pkg in BAD_PACKAGES])
# Remove setuptools, pip, etc from targets for removal
Expand Down Expand Up @@ -1243,7 +1252,7 @@ def pip_install(
pypi_mirror=None,
trusted_hosts=None
):
from notpip._internal import logger as piplogger
from pipenv.patched.notpip._internal import logger as piplogger
from .utils import Mapping
from .vendor.urllib3.util import parse_url

Expand Down Expand Up @@ -1609,11 +1618,11 @@ def do_outdated(pypi_mirror=None):
packages = {}
package_info = namedtuple("PackageInfo", ["name", "installed", "available"])

installed_packages = project.get_installed_packages()
installed_packages = project.environment.get_installed_packages()
outdated_packages = {
canonicalize_name(pkg.project_name): package_info
(pkg.project_name, pkg.parsed_version, pkg.latest_version)
for pkg in project.get_outdated_packages()
for pkg in project.environment.get_outdated_packages()
}
for result in installed_packages:
dep = Requirement.from_line(str(result.as_requirement()))
Expand Down Expand Up @@ -1693,11 +1702,11 @@ def do_install(
if requirements or package_args or project.pipfile_exists:
skip_requirements = True
# Don't attempt to install develop and default packages if Pipfile is missing
if not project.pipfile_exists and not (packages or dev) and not code:
if not (skip_lock or deploy):
raise exceptions.PipfileNotFound(project.pipfile_location)
elif (skip_lock or deploy) and not project.lockfile_exists:
raise exceptions.LockfileNotFound(project.lockfile_location)
if not project.pipfile_exists and not (package_args or dev) and not code:
if not (ignore_pipfile or deploy):
raise exceptions.PipfileNotFound(project.path_to("Pipfile"))
elif ((skip_lock and deploy) or ignore_pipfile) and not project.lockfile_exists:
raise exceptions.LockfileNotFound(project.path_to("Pipfile.lock"))
concurrent = not sequential
# Ensure that virtualenv is available.
ensure_project(
Expand Down Expand Up @@ -1839,7 +1848,7 @@ def do_install(
# Install all dependencies, if none was provided.
# This basically ensures that we have a pipfile and lockfile, then it locks and
# installs from the lockfile
if packages is False and editable_packages is False:
if not packages and not editable_packages:
# Update project settings with pre preference.
if pre:
project.update_settings({"allow_prereleases": pre})
Expand All @@ -1863,7 +1872,18 @@ def do_install(

# make a tuple of (display_name, entry)
pkg_list = packages + ["-e {0}".format(pkg) for pkg in editable_packages]

if not system and not project.virtualenv_exists:
do_init(
dev=dev,
system=system,
allow_global=system,
concurrent=concurrent,
keep_outdated=keep_outdated,
requirements_dir=requirements_directory,
deploy=deploy,
pypi_mirror=pypi_mirror,
skip_lock=skip_lock,
)
for pkg_line in pkg_list:
click.echo(
crayons.normal(
Expand All @@ -1872,8 +1892,7 @@ def do_install(
)
)
# pip install:
with vistir.contextmanagers.temp_environ(), \
create_spinner("Installing...") as sp:
with vistir.contextmanagers.temp_environ(), create_spinner("Installing...") as sp:
os.environ["PIP_USER"] = vistir.compat.fs_str("0")
try:
pkg_requirement = Requirement.from_line(pkg_line)
Expand Down Expand Up @@ -2002,30 +2021,17 @@ def do_uninstall(
package_map = {
canonicalize_name(p): p for p in packages if p
}
installed_package_names = set([
canonicalize_name(pkg.project_name) for pkg in project.get_installed_packages()
])
installed_package_names = project.installed_package_names
# Intelligently detect if --dev should be used or not.
lockfile_packages = set()
if project.lockfile_exists:
develop = set(
[canonicalize_name(k) for k in project.lockfile_content["develop"].keys()]
)
default = set(
[canonicalize_name(k) for k in project.lockfile_content["default"].keys()]
)
lockfile_packages |= develop | default
project_pkg_names = project.lockfile_package_names
else:
develop = set(
[canonicalize_name(k) for k in project.dev_packages.keys()]
)
default = set(
[canonicalize_name(k) for k in project.packages.keys()]
)
project_pkg_names = project.pipfile_package_names
pipfile_remove = True
# Uninstall [dev-packages], if --dev was provided.
if all_dev:
if "dev-packages" not in project.parsed_pipfile and not develop:
if "dev-packages" not in project.parsed_pipfile and not project_pkg_names["dev"]:
click.echo(
crayons.normal(
"No {0} to uninstall.".format(crayons.red("[dev-packages]")),
Expand All @@ -2038,37 +2044,41 @@ def do_uninstall(
fix_utf8("Un-installing {0}…".format(crayons.red("[dev-packages]"))), bold=True
)
)
package_names = develop
fix_venv_site(project.env_paths["lib"])
package_names = project_pkg_names["dev"]

# Remove known "bad packages" from the list.
bad_pkgs = set([canonicalize_name(pkg) for pkg in BAD_PACKAGES])
for bad_package in BAD_PACKAGES:
normalized_bad_pkg = canonicalize_name(bad_package)
if normalized_bad_pkg in package_map:
if environments.is_verbose():
click.echo("Ignoring {0}.".format(bad_package), err=True)
pkg_name_index = package_names.index(package_map[normalized_bad_pkg])
del package_names[pkg_name_index]
used_packages = develop | default & installed_package_names
bad_pkgs = get_canonical_names(BAD_PACKAGES)
ignored_packages = bad_pkgs & set(list(package_map.keys()))
for ignored_pkg in ignored_packages:
if environments.is_verbose():
click.echo("Ignoring {0}.".format(ignored_pkg), err=True)
pkg_name_index = package_names.index(package_map[ignored_pkg])
del package_names[pkg_name_index]

used_packages = project_pkg_names["combined"] & installed_package_names
failure = False
packages_to_remove = set()
if all:
package_names = develop | default
click.echo(
crayons.normal(fix_utf8("Un-installing all packages from virtualenv…"), bold=True)
crayons.normal(
fix_utf8("Un-installing all {0} and {1}…".format(
crayons.red("[dev-packages]"),
crayons.red("[packages]"),
)), bold=True
)
)
do_purge(allow_global=system)
return
do_purge(bare=False, allow_global=system)
sys.exit(0)
if all_dev:
package_names = develop
package_names = project_pkg_names["dev"]
else:
package_names = set([pkg_name for pkg_name in package_names])
selected_pkg_map = {
canonicalize_name(p): p for p in package_names
}
packages_to_remove = [
p for normalized, p in selected_pkg_map.items()
if (normalized in used_packages and normalized not in bad_pkgs)
if normalized in (used_packages - bad_pkgs)
]
for normalized, package_name in selected_pkg_map.items():
click.echo(
Expand All @@ -2078,15 +2088,16 @@ def do_uninstall(
)
# Uninstall the package.
if package_name in packages_to_remove:
cmd = "{0} uninstall {1} -y".format(
escape_grouped_arguments(which_pip(allow_global=system)), package_name,
)
if environments.is_verbose():
click.echo("$ {0}".format(cmd))
c = delegator.run(cmd)
click.echo(crayons.blue(c.out))
if c.return_code != 0:
failure = True
with project.environment.activated():
cmd = "{0} uninstall {1} -y".format(
escape_grouped_arguments(which_pip(allow_global=system)), package_name,
)
if environments.is_verbose():
click.echo("$ {0}".format(cmd))
c = delegator.run(cmd)
click.echo(crayons.blue(c.out))
if c.return_code != 0:
failure = True
if not failure and pipfile_remove:
in_packages = project.get_package_name_in_pipfile(package_name, dev=False)
in_dev_packages = project.get_package_name_in_pipfile(
Expand Down Expand Up @@ -2597,9 +2608,9 @@ def do_clean(ctx, three=None, python=None, dry_run=False, bare=False, pypi_mirro
ensure_lockfile(pypi_mirror=pypi_mirror)
# Make sure that the virtualenv's site packages are configured correctly
# otherwise we may end up removing from the global site packages directory
fix_venv_site(project.env_paths["lib"])
installed_package_names = [
canonicalize_name(pkg.project_name) for pkg in project.get_installed_packages()
canonicalize_name(pkg.project_name) for pkg
in project.environment.get_installed_packages()
]
# Remove known "bad packages" from the list.
for bad_package in BAD_PACKAGES:
Expand Down