<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> import os <EOL> import re <EOL> import shlex <EOL> import sys <EOL> import optparse <EOL> import warnings <EOL> from pip . _vendor . six . moves . urllib import parse as urllib_parse <EOL> from pip . _vendor . six . moves import filterfalse <EOL> import pip <EOL> from pip . download import get_file_content <EOL> from pip . req . req_install import InstallRequirement <EOL> from pip . exceptions import ( RequirementsFileParseError ) <EOL> from pip . utils . deprecation import RemovedInPip10Warning <EOL> from pip import cmdoptions <EOL> __all__ = [ '<STR_LIT>' ] <EOL> SCHEME_RE = re . compile ( r'<STR_LIT>' , re . I ) <EOL> COMMENT_RE = re . compile ( r'<STR_LIT>' ) <EOL> SUPPORTED_OPTIONS = [ <EOL> cmdoptions . constraints , <EOL> cmdoptions . editable , <EOL> cmdoptions . requirements , <EOL> cmdoptions . no_index , <EOL> cmdoptions . index_url , <EOL> cmdoptions . find_links , <EOL> cmdoptions . extra_index_url , <EOL> cmdoptions . allow_external , <EOL> cmdoptions . allow_all_external , <EOL> cmdoptions . no_allow_external , <EOL> cmdoptions . allow_unsafe , <EOL> cmdoptions . no_allow_unsafe , <EOL> cmdoptions . use_wheel , <EOL> cmdoptions . no_use_wheel , <EOL> cmdoptions . always_unzip , <EOL> cmdoptions . no_binary , <EOL> cmdoptions . only_binary , <EOL> cmdoptions . pre , <EOL> cmdoptions . process_dependency_links , <EOL> cmdoptions . trusted_host , <EOL> cmdoptions . require_hashes , <EOL> ] <EOL> SUPPORTED_OPTIONS_REQ = [ <EOL> cmdoptions . install_options , <EOL> cmdoptions . global_options , <EOL> cmdoptions . hash , <EOL> ] <EOL> SUPPORTED_OPTIONS_REQ_DEST = [ o ( ) . dest for o in SUPPORTED_OPTIONS_REQ ] <EOL> def parse_requirements ( filename , finder = None , comes_from = None , options = None , <EOL> session = None , constraint = False , wheel_cache = None ) : <EOL> """<STR_LIT>""" <EOL> if session is None : <EOL> raise TypeError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> _ , content = get_file_content ( <EOL> filename , comes_from = comes_from , session = session <EOL> ) <EOL> lines_enum = preprocess ( content , options ) <EOL> for line_number , line in lines_enum : <EOL> req_iter = process_line ( line , filename , line_number , finder , <EOL> comes_from , options , session , wheel_cache , <EOL> constraint = constraint ) <EOL> for req in req_iter : <EOL> yield req <EOL> def preprocess ( content , options ) : <EOL> """<STR_LIT>""" <EOL> lines_enum = enumerate ( content . splitlines ( ) , start = <NUM_LIT:1> ) <EOL> lines_enum = join_lines ( lines_enum ) <EOL> lines_enum = ignore_comments ( lines_enum ) <EOL> lines_enum = skip_regex ( lines_enum , options ) <EOL> return lines_enum <EOL> def process_line ( line , filename , line_number , finder = None , comes_from = None , <EOL> options = None , session = None , wheel_cache = None , <EOL> constraint = False ) : <EOL> """<STR_LIT>""" <EOL> parser = build_parser ( ) <EOL> defaults = parser . get_default_values ( ) <EOL> defaults . index_url = None <EOL> if finder : <EOL> defaults . format_control = finder . format_control <EOL> args_str , options_str = break_args_options ( line ) <EOL> if sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:3> ) : <EOL> options_str = options_str . encode ( '<STR_LIT:utf8>' ) <EOL> opts , _ = parser . parse_args ( shlex . split ( options_str ) , defaults ) <EOL> line_comes_from = '<STR_LIT>' % ( <EOL> '<STR_LIT:-c>' if constraint else '<STR_LIT>' , filename , line_number ) <EOL> if args_str : <EOL> isolated = options . isolated_mode if options else False <EOL> if options : <EOL> cmdoptions . check_install_build_global ( options , opts ) <EOL> req_options = { } <EOL> for dest in SUPPORTED_OPTIONS_REQ_DEST : <EOL> if dest in opts . __dict__ and opts . __dict__ [ dest ] : <EOL> req_options [ dest ] = opts . __dict__ [ dest ] <EOL> yield InstallRequirement . from_line ( <EOL> args_str , line_comes_from , constraint = constraint , <EOL> isolated = isolated , options = req_options , wheel_cache = wheel_cache <EOL> ) <EOL> elif opts . editables : <EOL> isolated = options . isolated_mode if options else False <EOL> default_vcs = options . default_vcs if options else None <EOL> yield InstallRequirement . from_editable ( <EOL> opts . editables [ <NUM_LIT:0> ] , comes_from = line_comes_from , <EOL> constraint = constraint , default_vcs = default_vcs , isolated = isolated , <EOL> wheel_cache = wheel_cache <EOL> ) <EOL> elif opts . requirements or opts . constraints : <EOL> if opts . requirements : <EOL> req_path = opts . requirements [ <NUM_LIT:0> ] <EOL> nested_constraint = False <EOL> else : <EOL> req_path = opts . constraints [ <NUM_LIT:0> ] <EOL> nested_constraint = True <EOL> if SCHEME_RE . search ( filename ) : <EOL> req_path = urllib_parse . urljoin ( filename , req_path ) <EOL> elif not SCHEME_RE . search ( req_path ) : <EOL> req_path = os . path . join ( os . path . dirname ( filename ) , req_path ) <EOL> parser = parse_requirements ( <EOL> req_path , finder , comes_from , options , session , <EOL> constraint = nested_constraint , wheel_cache = wheel_cache <EOL> ) <EOL> for req in parser : <EOL> yield req <EOL> elif opts . require_hashes : <EOL> options . require_hashes = opts . require_hashes <EOL> elif finder : <EOL> if opts . allow_external : <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> RemovedInPip10Warning , <EOL> ) <EOL> if opts . allow_all_external : <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> RemovedInPip10Warning , <EOL> ) <EOL> if opts . allow_unverified : <EOL> warnings . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> RemovedInPip10Warning , <EOL> ) <EOL> if opts . index_url : <EOL> finder . index_urls = [ opts . index_url ] <EOL> if opts . use_wheel is False : <EOL> finder . use_wheel = False <EOL> pip . index . fmt_ctl_no_use_wheel ( finder . format_control ) <EOL> if opts . no_index is True : <EOL> finder . index_urls = [ ] <EOL> if opts . extra_index_urls : <EOL> finder . index_urls . extend ( opts . extra_index_urls ) <EOL> if opts . find_links : <EOL> value = opts . find_links [ <NUM_LIT:0> ] <EOL> req_dir = os . path . dirname ( os . path . abspath ( filename ) ) <EOL> relative_to_reqs_file = os . path . join ( req_dir , value ) <EOL> if os . path . exists ( relative_to_reqs_file ) : <EOL> value = relative_to_reqs_file <EOL> finder . find_links . append ( value ) <EOL> if opts . pre : <EOL> finder . allow_all_prereleases = True <EOL> if opts . process_dependency_links : <EOL> finder . process_dependency_links = True <EOL> if opts . trusted_hosts : <EOL> finder . secure_origins . extend ( <EOL> ( "<STR_LIT:*>" , host , "<STR_LIT:*>" ) for host in opts . trusted_hosts ) <EOL> def break_args_options ( line ) : <EOL> """<STR_LIT>""" <EOL> tokens = line . split ( '<STR_LIT:U+0020>' ) <EOL> args = [ ] <EOL> options = tokens [ : ] <EOL> for token in tokens : <EOL> if token . startswith ( '<STR_LIT:->' ) or token . startswith ( '<STR_LIT>' ) : <EOL> break <EOL> else : <EOL> args . append ( token ) <EOL> options . pop ( <NUM_LIT:0> ) <EOL> return '<STR_LIT:U+0020>' . join ( args ) , '<STR_LIT:U+0020>' . join ( options ) <EOL> def build_parser ( ) : <EOL> """<STR_LIT>""" <EOL> parser = optparse . OptionParser ( add_help_option = False ) <EOL> option_factories = SUPPORTED_OPTIONS + SUPPORTED_OPTIONS_REQ <EOL> for option_factory in option_factories : <EOL> option = option_factory ( ) <EOL> parser . add_option ( option ) <EOL> def parser_exit ( self , msg ) : <EOL> raise RequirementsFileParseError ( msg ) <EOL> parser . exit = parser_exit <EOL> return parser <EOL> def join_lines ( lines_enum ) : <EOL> """<STR_LIT>""" <EOL> primary_line_number = None <EOL> new_line = [ ] <EOL> for line_number , line in lines_enum : <EOL> if not line . endswith ( '<STR_LIT:\\>' ) or COMMENT_RE . match ( line ) : <EOL> if COMMENT_RE . match ( line ) : <EOL> line = '<STR_LIT:U+0020>' + line <EOL> if new_line : <EOL> new_line . append ( line ) <EOL> yield primary_line_number , '<STR_LIT>' . join ( new_line ) <EOL> new_line = [ ] <EOL> else : <EOL> yield line_number , line <EOL> else : <EOL> if not new_line : <EOL> primary_line_number = line_number <EOL> new_line . append ( line . strip ( '<STR_LIT:\\>' ) ) <EOL> if new_line : <EOL> yield primary_line_number , '<STR_LIT>' . join ( new_line ) <EOL> def ignore_comments ( lines_enum ) : <EOL> """<STR_LIT>""" <EOL> for line_number , line in lines_enum : <EOL> line = COMMENT_RE . sub ( '<STR_LIT>' , line ) <EOL> line = line . strip ( ) <EOL> if line : <EOL> yield line_number , line <EOL> def skip_regex ( lines_enum , options ) : <EOL> """<STR_LIT>""" <EOL> skip_regex = options . skip_requirements_regex if options else None <EOL> if skip_regex : <EOL> pattern = re . compile ( skip_regex ) <EOL> lines_enum = filterfalse ( <EOL> lambda e : pattern . search ( e [ <NUM_LIT:1> ] ) , <EOL> lines_enum ) <EOL> return lines_enum </s>
