-
-
Notifications
You must be signed in to change notification settings - Fork 612
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
sync: Use options from the txt file #464
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import optparse | ||
|
||
import pip | ||
|
||
from ..repositories import PyPIRepository | ||
|
||
|
||
class PipCommand(pip.basecommand.Command): | ||
name = 'PipCommand' | ||
|
||
|
||
def get_pip_options_and_pypi_repository( | ||
index_url=None, extra_index_url=None, no_index=None, | ||
find_links=None, cert=None, client_cert=None, pre=None, | ||
trusted_host=None): | ||
pip_command = get_pip_command() | ||
|
||
pip_args = [] | ||
if find_links: | ||
for link in find_links: | ||
pip_args.extend(['-f', link]) | ||
if index_url: | ||
pip_args.extend(['-i', index_url]) | ||
if no_index: | ||
pip_args.extend(['--no-index']) | ||
if extra_index_url: | ||
for extra_index in extra_index_url: | ||
pip_args.extend(['--extra-index-url', extra_index]) | ||
if cert: | ||
pip_args.extend(['--cert', cert]) | ||
if client_cert: | ||
pip_args.extend(['--client-cert', client_cert]) | ||
if pre: | ||
pip_args.extend(['--pre']) | ||
if trusted_host: | ||
for host in trusted_host: | ||
pip_args.extend(['--trusted-host', host]) | ||
|
||
pip_options, _ = pip_command.parse_args(pip_args) | ||
|
||
session = pip_command._build_session(pip_options) | ||
repository = PyPIRepository(pip_options, session) | ||
return (pip_options, repository) | ||
|
||
|
||
def get_pip_command(): | ||
# Use pip's parser for pip.conf management and defaults. | ||
# General options (find_links, index_url, extra_index_url, trusted_host, | ||
# and pre) are defered to pip. | ||
pip_command = PipCommand() | ||
index_opts = pip.cmdoptions.make_option_group( | ||
pip.cmdoptions.index_group, | ||
pip_command.parser, | ||
) | ||
pip_command.parser.insert_option_group(0, index_opts) | ||
pip_command.parser.add_option( | ||
optparse.Option('--pre', action='store_true', default=False)) | ||
|
||
return pip_command |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from ..exceptions import PipToolsError | ||
from ..logging import log | ||
from ..utils import assert_compatible_pip_version, flat_map | ||
from ._repo import get_pip_options_and_pypi_repository | ||
|
||
# Make sure we're using a compatible version of pip | ||
assert_compatible_pip_version() | ||
|
@@ -47,8 +48,15 @@ def cli(dry_run, force, find_links, index_url, extra_index_url, no_index, quiet, | |
log.error('ERROR: ' + msg) | ||
sys.exit(2) | ||
|
||
requirements = flat_map(lambda src: pip.req.parse_requirements(src, session=True), | ||
src_files) | ||
(pip_options, repository) = get_pip_options_and_pypi_repository( | ||
index_url=index_url, extra_index_url=extra_index_url, | ||
no_index=no_index, find_links=find_links) | ||
|
||
def parse_req_file(filename): | ||
return pip.req.parse_requirements( | ||
filename, session=True, finder=repository.finder) | ||
|
||
requirements = flat_map(parse_req_file, src_files) | ||
|
||
try: | ||
requirements = sync.merge(requirements, ignore_conflicts=force) | ||
|
@@ -60,15 +68,15 @@ def cli(dry_run, force, find_links, index_url, extra_index_url, no_index, quiet, | |
to_install, to_uninstall = sync.diff(requirements, installed_dists) | ||
|
||
install_flags = [] | ||
for link in find_links or []: | ||
for link in repository.finder.find_links or []: | ||
install_flags.extend(['-f', link]) | ||
if no_index: | ||
if not repository.finder.index_urls: | ||
install_flags.append('--no-index') | ||
if index_url: | ||
install_flags.extend(['-i', index_url]) | ||
if extra_index_url: | ||
for extra_index in extra_index_url: | ||
install_flags.extend(['--extra-index-url', extra_index]) | ||
for (i, index_url) in enumerate(repository.finder.index_urls): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not quite the same intent. I see that you are reconstructing the parameter invocation based upon the index_urls, but that exposes too much of the implementation detail. I don't quite grasp why you are doing this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point here is that the call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what you mean by the "implementation detail", since there wasn't really any separation between implementation and interface here before my changes either. If implementation details should be hidden, then there should be a class like Can you elaborate what do you mean by exposing the implementation detail here? |
||
if i == 0: | ||
install_flags.extend(['-i', index_url]) | ||
else: | ||
install_flags.extend(['--extra-index-url', index_url]) | ||
|
||
sys.exit(sync.sync(to_install, to_uninstall, verbose=(not quiet), dry_run=dry_run, | ||
install_flags=install_flags)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change the no_index flag is inhibited. Is this wanted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
no_index
flag is passed to theget_pip_options_and_pypi_repository
call which then passes it along to thefinder
in the constructed repository. That'll make therepository.finder.index_urls
to be empty ifno_index
isTrue
. It'll also consider--no-index
specified in the parsed txt file.