Skip to content

Commit

Permalink
Fix lock -r output to include all markers
Browse files Browse the repository at this point in the history
- Fixes #2748

Signed-off-by: Dan Ryan <dan@danryan.co>
  • Loading branch information
techalchemy authored and uranusjr committed Sep 5, 2018
1 parent a506a8c commit c611b1e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 82 deletions.
13 changes: 2 additions & 11 deletions pipenv/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ def cli(
short_help="Installs provided packages and adds them to Pipfile, or (if none is given), installs all packages.",
context_settings=dict(ignore_unknown_options=True, allow_extra_args=True),
)
@requirementstxt_option
@system_option
@code_option
@deploy_option
Expand Down Expand Up @@ -295,27 +294,19 @@ def uninstall(


@cli.command(short_help="Generates Pipfile.lock.")
@option(
"--requirements",
"-r",
is_flag=True,
default=False,
help="Generate output compatible with requirements.txt.",
)
@lock_options
@pass_state
def lock(
state,
requirements=False,
**kwargs
):
"""Generates Pipfile.lock."""
from ..core import ensure_project, do_init, do_lock

# Ensure that virtualenv is available.
ensure_project(three=state.three, python=state.python, pypi_mirror=state.pypi_mirror)
if requirements:
do_init(dev=state.installstate.dev, requirements=requirements,
if state.installstate.requirementstxt:
do_init(dev=state.installstate.dev, requirements=state.installstate.requirementstxt,
pypi_mirror=state.pypi_mirror)
do_lock(
clear=state.clear,
Expand Down
22 changes: 16 additions & 6 deletions pipenv/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,16 @@ def callback(ctx, param, value):
help="Import a requirements.txt file.", callback=callback)(f)


def requirements_flag(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
if value:
state.installstate.requirementstxt = value
return value
return option("--requirements", "-r", default=False, is_flag=True, expose_value=False,
help="Generate output in requirements.txt format.", callback=callback)(f)


def code_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
Expand Down Expand Up @@ -345,23 +355,23 @@ def uninstall_options(f):

def lock_options(f):
f = install_base_options(f)
f = index_option(f)
f = extra_index_option(f)
f = skip_lock_option(f)
f = requirements_flag(f)
f = pre_option(f)
return f


def sync_options(f):
f = install_base_options(f)
f = sequential_option(f)
f = sequential_option(f)
return f


def install_options(f):
f = lock_options(f)
f = sequential_option(f)
f = sync_options(f)
f = index_option(f)
f = extra_index_option(f)
f = requirementstxt_option(f)
f = pre_option(f)
f = selective_upgrade_option(f)
f = ignore_pipfile_option(f)
f = editable_option(f)
Expand Down
23 changes: 8 additions & 15 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,24 +711,18 @@ def cleanup_procs(procs, concurrent):
)
failed_deps_list = []
if requirements:
# Comment out packages that shouldn't be included in
# requirements.txt, for pip9.
# Additional package selectors, specific to pip's --hash checking mode.
for l in (deps_list, dev_deps_list):
for i, dep in enumerate(l):
l[i] = list(l[i])
if "--hash" in l[i][0]:
l[i][0] = l[i][0].split("--hash")[0].strip()
index_args = prepare_pip_source_args(project.sources)
index_args = " ".join(index_args).replace(" -", "\n-")
deps_list = [dep for dep, ignore_hash, block in deps_list]
dev_deps_list = [dep for dep, ignore_hash, block in dev_deps_list]
# Output only default dependencies
click.echo(index_args)
if not dev:
click.echo("\n".join(d[0] for d in sorted(deps_list)))
click.echo("\n".join(d.partition('--hash')[0].strip() for d in sorted(deps_list)))
sys.exit(0)
# Output only dev dependencies
if dev:
click.echo("\n".join(d[0] for d in sorted(dev_deps_list)))
click.echo("\n".join(d.partition('--hash')[0].strip() for d in sorted(dev_deps_list)))
sys.exit(0)
procs = []
deps_list_bar = progress.bar(
Expand Down Expand Up @@ -1634,7 +1628,7 @@ def do_install(
)
if selective_upgrade:
keep_outdated = True
packages = packages if packages else[]
packages = packages if packages else []
editable_packages = editable_packages if editable_packages else []
package_args = [p for p in packages if p] + [p for p in editable_packages if p]
skip_requirements = False
Expand Down Expand Up @@ -1814,12 +1808,11 @@ def do_install(
'packages': [(pkg, pkg) for pkg in packages],
'editables': [("-e {0}".format(pkg), pkg) for pkg in editable_packages]
}
pkg_tuples = [pkg_tuple for pkg_list in pkg_dict.values() for pkg_tuple in pkg_list]

for pkg_tuple in pkg_tuples:
for pkg_type, pkg_tuple in pkg_dict.items():
if not pkg_tuple:
continue
pkg_line, pkg_val = pkg_tuple
pkg_line, pkg_val = pkg_tuple.pop()
click.echo(
crayons.normal(
u"Installing {0}…".format(crayons.green(pkg_line, bold=True)),
Expand Down Expand Up @@ -1966,7 +1959,7 @@ def do_uninstall(
)
)
package_names = project.dev_packages.keys()
if not packages and not editable_packages and not all_dev:
if packages is False and editable_packages is False and not all_dev:
click.echo(crayons.red("No package provided!"), err=True)
return 1
for package_name in package_names:
Expand Down
4 changes: 2 additions & 2 deletions pipenv/patched/piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ def get_legacy_dependencies(self, ireq):
except (TypeError, ValueError, AttributeError):
pass
else:
setup_requires = getattr(dist, "requires", None)
setup_requires = getattr(dist, "extras_require", None)
if not setup_requires:
setup_requires = getattr(dist, "setup_requires", None)
setup_requires = {"setup_requires": getattr(dist, "setup_requires", None)}
try:
# Pip 9 and below
reqset = RequirementSet(
Expand Down
Loading

0 comments on commit c611b1e

Please sign in to comment.