From 9f58768ead790f09c5bcb4d086ff65ff6e99605b Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Tue, 19 Jun 2018 04:37:51 -0400 Subject: [PATCH] Exclude dependencies with failing markers from lock Signed-off-by: Dan Ryan --- news/2384.bugfix | 1 + pipenv/utils.py | 27 +++++++-------------------- 2 files changed, 8 insertions(+), 20 deletions(-) create mode 100644 news/2384.bugfix diff --git a/news/2384.bugfix b/news/2384.bugfix new file mode 100644 index 00000000..0261fd31 --- /dev/null +++ b/news/2384.bugfix @@ -0,0 +1 @@ +Dependencies with markers that don't match the current environment will now be skipped during ``pipenv lock``. diff --git a/pipenv/utils.py b/pipenv/utils.py index fa3d8b23..74032ead 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -248,27 +248,22 @@ def actually_resolve_deps( dep, url = dep.split(' -i ') req = Requirement.from_line(dep) - # req.as_line() is theoratically the same as dep, but is guaranteed to - # be normalized. This is safer than passing in dep. - # TODO: Stop passing dep lines around; just use requirement objects. - constraints.append(req.constraint_line) + # Just use req.ireq directly, no need to actually use the extra file intermediares + # And also allows us to eliminate any markers that don't match before we start + # locking / resolving + ireq = req.ireq + if not ireq.markers or ireq.markers.evaluate(): + constraints.append(req.ireq) # extra_constraints = [] if url: index_lookup[req.name] = project.get_source(url=url).get('name') if req.markers: markers_lookup[req.name] = req.markers.replace('"', "'") - constraints_file = None pip_command = get_pip_command() pip_args = [] if sources: pip_args = prepare_pip_source_args(sources, pip_args) - with NamedTemporaryFile(mode='w', prefix='pipenv-', suffix='-constraints.txt', dir=req_dir.name, delete=False) as f: - if sources: - requirementstxt_sources = ' '.join(pip_args).replace(' --', '\n--') - f.write(u'{0}\n'.format(requirementstxt_sources)) - f.write(u'\n'.join([_constraint for _constraint in constraints])) - constraints_file = f.name if verbose: print('Using pip: {0}'.format(' '.join(pip_args))) pip_args = pip_args.extend(['--cache-dir', PIPENV_CACHE_DIR]) @@ -281,15 +276,7 @@ def actually_resolve_deps( logging.log.verbose = True piptools_logging.log.verbose = True resolved_tree = set() - resolver = Resolver( - constraints=parse_requirements( - constraints_file, - finder=pypi.finder, session=pypi.session, options=pip_options, - ), - repository=pypi, - clear_caches=clear, - prereleases=pre, - ) + resolver = Resolver(constraints=constraints, repository=pypi, clear_caches=clear, prereleases=pre) # pre-resolve instead of iterating to avoid asking pypi for hashes of editable packages try: resolved_tree.update(resolver.resolve(max_rounds=PIPENV_MAX_ROUNDS))