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

Requirements Refactor (ready to merge, after conflict resolution) #1962

Merged
merged 17 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

from .cmdparse import ScriptEmptyError
from .project import Project, SourceNotFound
from .vendor.requirementslib import Requirement
from .utils import (
convert_deps_from_pip,
convert_deps_to_pip,
is_required_version,
proper_case,
Expand All @@ -35,14 +35,12 @@
merge_deps,
venv_resolve_deps,
escape_grouped_arguments,
is_vcs,
python_version,
find_windows_executable,
prepare_pip_source_args,
temp_environ,
is_valid_url,
download_file,
get_requirement,
is_pinned,
is_star,
rmtree,
Expand Down Expand Up @@ -975,7 +973,7 @@ def get_downloads_info(names_map, section):
p = project.parsed_pipfile
for fname in os.listdir(project.download_location):
# Get name from filename mapping.
name = list(convert_deps_from_pip(names_map[fname]))[0]
name = Requirement.from_line(names_map[fname]).name
# Get the version info from the filenames.
version = parse_download_fname(fname, name)
# Get the hash of each file.
Expand Down Expand Up @@ -1242,14 +1240,12 @@ def do_purge(bare=False, downloads=False, allow_global=False, verbose=False):
actually_installed = []
for package in installed:
try:
dep = convert_deps_from_pip(package)
dep = Requirement.from_line(package)
except AssertionError:
dep = None
if dep and not is_vcs(dep):
dep = [k for k in dep.keys()][0]
# TODO: make this smarter later.
if not dep.startswith('-e ') and not dep.startswith('git+'):
actually_installed.append(dep)
if dep and not dep.is_vcs and not dep.editable:
dep = dep.name
actually_installed.append(dep)
if not bare:
click.echo(
u'Found {0} installed package(s), purging…'.format(
Expand Down Expand Up @@ -1414,7 +1410,7 @@ def pip_install(
f.write(package_name)
# Install dependencies when a package is a VCS dependency.
try:
req = get_requirement(
req = Requirement.from_line(
package_name.split('--hash')[0].split('--trusted-host')[0]
).vcs
except (ParseException, ValueError) as e:
Expand Down Expand Up @@ -1711,7 +1707,8 @@ def do_outdated():
)
results = filter(bool, results)
for result in results:
packages.update(convert_deps_from_pip(result))
dep = Requirement.from_line(result)
packages.update(dep.as_pipfile())
updated_packages = {}
lockfile = do_lock(write=False)
for section in ('develop', 'default'):
Expand Down Expand Up @@ -1935,9 +1932,8 @@ def do_install(
if selective_upgrade:
for i, package_name in enumerate(package_names[:]):
section = project.packages if not dev else project.dev_packages
package = convert_deps_from_pip(package_name)
package__name = list(package.keys())[0]
package__val = list(package.values())[0]
package = Requirement.from_line(package_name)
package__name, package__val = package.pipfile_entry
try:
if not is_star(section[package__name]) and is_star(
package__val
Expand Down Expand Up @@ -1977,17 +1973,12 @@ def do_install(
)
# Warn if --editable wasn't passed.
try:
converted = convert_deps_from_pip(package_name)
converted = Requirement.from_line(package_name)
except ValueError as e:
click.echo('{0}: {1}'.format(crayons.red('WARNING'), e))
requirements_directory.cleanup()
sys.exit(1)
key = [k for k in converted.keys()][0]
if is_vcs(key) or is_vcs(converted[key]) and not converted[
key
].get(
'editable'
):
if converted.is_vcs and not converted.editable:
click.echo(
'{0}: You installed a VCS dependency in non–editable mode. '
'This will work fine, but sub-dependencies will not be resolved by {1}.'
Expand Down Expand Up @@ -2566,7 +2557,7 @@ def do_clean(
)
installed_package_names = []
for installed in installed_packages:
r = get_requirement(installed)
r = Requirement.from_line(installed).requirement
# Ignore editable installations.
if not r.editable:
installed_package_names.append(r.name.lower())
Expand Down
6 changes: 5 additions & 1 deletion pipenv/patched/notpip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ def format_reqs(rs):
else:
self.req.build_env = NoOpBuildEnvironment(no_clean=False)

self.req.run_egg_info()
try:
self.req.run_egg_info()
except (OSError, TypeError):
self.req._correct_build_location()
self.req.run_egg_info()
self.req.assert_source_matches_version()


Expand Down
2 changes: 1 addition & 1 deletion pipenv/patched/piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def get_legacy_dependencies(self, ireq):
upgrade_strategy="to-satisfy-only",
force_reinstall=False,
ignore_dependencies=False,
ignore_requires_python=False,
ignore_requires_python=True,
ignore_installed=True,
isolated=False,
wheel_cache=self.wheel_cache,
Expand Down
21 changes: 8 additions & 13 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@
from pathlib2 import Path

from .cmdparse import Script
from .vendor.requirementslib import Requirement
from .utils import (
atomic_open_for_write,
mkdir_p,
pep423_name,
proper_case,
find_requirements,
is_editable,
is_file,
is_vcs,
cleanup_toml,
is_installable_file,
is_valid_url,
normalize_drive,
python_version,
safe_expandvars,
is_star,
)
from .environments import (
PIPENV_MAX_DEPTH,
Expand All @@ -45,6 +46,7 @@
PIPENV_PYTHON,
PIPENV_DEFAULT_PYTHON_VERSION,
)
from .vendor.first import first


def _normalized(p):
Expand Down Expand Up @@ -723,28 +725,21 @@ def remove_package_from_pipfile(self, package_name, dev=False):
self.write_toml(p)

def add_package_to_pipfile(self, package_name, dev=False):
from .utils import convert_deps_from_pip
# Read and append Pipfile.
p = self.parsed_pipfile
# Don't re-capitalize file URLs or VCSs.
converted = convert_deps_from_pip(package_name)
converted = converted[first(k for k in converted.keys())]
if not (
is_file(package_name) or is_vcs(converted) or 'path' in converted
):
package_name = pep423_name(package_name)
package = Requirement.from_line(package_name)
converted = first(package.as_pipfile().values())
key = 'dev-packages' if dev else 'packages'
# Set empty group if it doesn't exist yet.
if key not in p:
p[key] = {}
package = convert_deps_from_pip(package_name)
package_name = first(k for k in package.keys())
name = self.get_package_name_in_pipfile(package_name, dev)
if name and converted == '*':
name = self.get_package_name_in_pipfile(package.name, dev)
if name and is_star(converted):
# Skip for wildcard version
return
# Add the package to the group.
p[key][name or package_name] = package[package_name]
p[key][name or package.normalized_name] = converted
# Write Pipfile.
self.write_toml(p)

Expand Down
Loading