mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
A bit more refactoring and cleanup
Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
+22
-35
@@ -959,6 +959,14 @@ def get_downloads_info(names_map, section):
|
||||
return info
|
||||
|
||||
|
||||
def overwrite_dev(prod, dev):
|
||||
dev_keys = set(list(dev.keys()))
|
||||
prod_keys = set(list(prod.keys()))
|
||||
for pkg in dev_keys & prod_keys:
|
||||
dev[pkg] = prod[pkg]
|
||||
return dev
|
||||
|
||||
|
||||
def do_lock(
|
||||
ctx=None,
|
||||
system=False,
|
||||
@@ -989,58 +997,40 @@ def do_lock(
|
||||
del lockfile[section][k]
|
||||
# Ensure that develop inherits from default.
|
||||
dev_packages = project.dev_packages.copy()
|
||||
for dev_package in project.dev_packages:
|
||||
if dev_package in project.packages:
|
||||
dev_packages[dev_package] = project.packages[dev_package]
|
||||
dev_packages = overwrite_dev(project.packages, dev_packages)
|
||||
# Resolve dev-package dependencies, with pip-tools.
|
||||
sections = {
|
||||
"dev": {
|
||||
"packages": project.dev_packages,
|
||||
"vcs": project.vcs_dev_packages,
|
||||
"pipfile_key": "dev_packages",
|
||||
"lockfile_key": "develop",
|
||||
"log_string": "dev-packages",
|
||||
"dev": True,
|
||||
},
|
||||
"default": {
|
||||
"packages": project.packages,
|
||||
"vcs": project.vcs_packages,
|
||||
"pipfile_key": "packages",
|
||||
"lockfile_key": "default",
|
||||
"log_string": "packages",
|
||||
"dev": False,
|
||||
},
|
||||
}
|
||||
for section_name in ["dev", "default"]:
|
||||
settings = sections[section_name]
|
||||
for is_dev in [True, False]:
|
||||
pipfile_section = "dev_packages" if is_dev else "packages"
|
||||
lockfile_section = "develop" if is_dev else "default"
|
||||
packages = getattr(project, pipfile_section)
|
||||
|
||||
if write:
|
||||
# Alert the user of progress.
|
||||
click.echo(
|
||||
u"{0} {1} {2}".format(
|
||||
crayons.normal(u"Locking"),
|
||||
crayons.red(u"[{0}]".format(settings["log_string"])),
|
||||
crayons.red(u"[{0}]".format(pipfile_section.replace("_", "-"))),
|
||||
crayons.normal(fix_utf8("dependencies…")),
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
|
||||
deps = convert_deps_to_pip(
|
||||
settings["packages"], project, r=False, include_index=True
|
||||
packages, project, r=False, include_index=True
|
||||
)
|
||||
lockfile_base = lockfile[settings["lockfile_key"]].copy()
|
||||
locked_lockfile = venv_resolve_deps(
|
||||
# Mutates the lockfile
|
||||
venv_resolve_deps(
|
||||
deps,
|
||||
which=which,
|
||||
project=project,
|
||||
dev=settings["dev"],
|
||||
dev=is_dev,
|
||||
clear=clear,
|
||||
pre=pre,
|
||||
allow_global=system,
|
||||
pypi_mirror=pypi_mirror,
|
||||
pipfile=settings["packages"],
|
||||
lockfile=lockfile_base
|
||||
pipfile=packages,
|
||||
lockfile=lockfile
|
||||
)
|
||||
lockfile[settings["lockfile_key"]] = locked_lockfile
|
||||
|
||||
# Support for --keep-outdated…
|
||||
if keep_outdated:
|
||||
@@ -1057,10 +1047,7 @@ def do_lock(
|
||||
section_name
|
||||
][canonical_name].copy()
|
||||
# Overwrite any develop packages with default packages.
|
||||
develop_keys = set(list(lockfile["develop"].keys()))
|
||||
default_keys = set(list(lockfile["default"].keys()))
|
||||
for pkg in default_keys & develop_keys:
|
||||
lockfile["develop"][pkg] = lockfile["default"][pkg]
|
||||
lockfile["develop"].update(overwrite_dev(lockfile.get("default", {}), lockfile["develop"]))
|
||||
if write:
|
||||
project.write_lockfile(lockfile)
|
||||
click.echo(
|
||||
|
||||
+17
-17
@@ -509,18 +509,22 @@ def resolve(cmd, sp):
|
||||
|
||||
def get_locked_dep(dep, pipfile_section):
|
||||
entry = None
|
||||
lockfile_entry = None
|
||||
cleaner_kwargs = {
|
||||
"is_top_level": False,
|
||||
"pipfile_entry": None
|
||||
}
|
||||
if isinstance(dep, Mapping) and dep.get("name", ""):
|
||||
name_options = [dep.get("name"), pep423_name(dep.get("name"))]
|
||||
name_options = [dep["name"], pep423_name(dep["name"])]
|
||||
name = next(iter(k for k in name_options if k in pipfile_section), None)
|
||||
entry = pipfile_section.get(name, None)
|
||||
lockfile_entry = clean_resolved_dep(dep, is_top_level=True, pipfile_entry=entry)
|
||||
else:
|
||||
lockfile_entry = clean_resolved_dep(dep, is_top_level=False, pipfile_entry=entry)
|
||||
entry = pipfile_section[name] if name else None
|
||||
|
||||
if entry:
|
||||
cleaner_kwargs.update({"is_top_level": True, "pipfile_entry": entry})
|
||||
lockfile_entry = clean_resolved_dep(dep, **cleaner_kwargs)
|
||||
return lockfile_entry
|
||||
|
||||
|
||||
def prepare_lockfiles(results, pipfile, lockfile, vcs_lockfile):
|
||||
def prepare_lockfile(results, pipfile, lockfile):
|
||||
from .vendor.requirementslib.utils import is_vcs
|
||||
for dep in results:
|
||||
# Merge in any relevant information from the pipfile entry, including
|
||||
@@ -528,12 +532,6 @@ def prepare_lockfiles(results, pipfile, lockfile, vcs_lockfile):
|
||||
if not is_vcs(dep):
|
||||
lockfile_entry = get_locked_dep(dep, pipfile)
|
||||
lockfile.update(lockfile_entry)
|
||||
# For vcs dependencies, treat the initial pass at locking (i.e. checkout)
|
||||
# as the pipfile entry because it gets us an actual ref to use
|
||||
else:
|
||||
lockfile_entry = get_locked_dep(dep, vcs_lockfile)
|
||||
vcs_lockfile.update(lockfile_entry)
|
||||
lockfile.update(vcs_lockfile)
|
||||
return lockfile
|
||||
|
||||
|
||||
@@ -568,7 +566,7 @@ def venv_resolve_deps(
|
||||
if not pipfile:
|
||||
pipfile = getattr(project, pipfile_section, None)
|
||||
if not lockfile:
|
||||
lockfile = project._lockfile[lockfile_section]
|
||||
lockfile = project._lockfile
|
||||
req_dir = create_tracked_tempdir(prefix="pipenv", suffix="requirements")
|
||||
if vcs_deps:
|
||||
with create_spinner(text=fs_str("Pinning VCS Packages...")) as sp:
|
||||
@@ -621,7 +619,10 @@ def venv_resolve_deps(
|
||||
try:
|
||||
results = json.loads(results.split("RESULTS:")[1].strip())
|
||||
if vcs_results:
|
||||
# For vcs dependencies, treat the initial pass at locking (i.e. checkout)
|
||||
# as the pipfile entry because it gets us an actual ref to use
|
||||
vcs_results = json.loads(vcs_results.split("RESULTS:")[1].strip())
|
||||
vcs_lockfile = prepare_lockfile(vcs_results, vcs_lockfile.copy(), vcs_lockfile)
|
||||
else:
|
||||
vcs_results = []
|
||||
|
||||
@@ -630,9 +631,8 @@ def venv_resolve_deps(
|
||||
click_echo(out.strip(), err=True)
|
||||
click_echo(err.strip(), err=True)
|
||||
raise RuntimeError("There was a problem with locking.")
|
||||
results += vcs_results
|
||||
lockfile = prepare_lockfiles(results, pipfile, lockfile, vcs_lockfile)
|
||||
return lockfile
|
||||
lockfile[lockfile_section] = prepare_lockfile(results, pipfile, lockfile[lockfile_section])
|
||||
lockfile[lockfile_section].update(vcs_lockfile)
|
||||
|
||||
|
||||
def resolve_deps(
|
||||
|
||||
Reference in New Issue
Block a user