12
12
_scheme_re = re .compile (r'^(http|https|file):' , re .I )
13
13
14
14
15
+ def _remove_prefixes (line , short_prefix , long_prefix ):
16
+ if line .startswith (short_prefix ):
17
+ return line [len (short_prefix ):].lstrip ()
18
+ else :
19
+ return _remove_prefix (line , long_prefix )
20
+
21
+
15
22
def _remove_prefix (line , prefix ):
16
23
"""Remove the prefix and eventually one '=' or spaces"""
17
24
return re .sub (r'\s*=?\s*' , '' , line [len (prefix ):])
@@ -46,10 +53,7 @@ def parse_requirements(filename, finder=None, comes_from=None, options=None,
46
53
if skip_match and skip_match .search (line ):
47
54
continue
48
55
if line .startswith (('-r' , '--requirement' )):
49
- if line .startswith ('-r' ):
50
- req_url = line [2 :].lstrip ()
51
- else :
52
- req_url = _remove_prefix (line , '--requirement' )
56
+ req_url = _remove_prefixes (line , '-r' , '--requirement' )
53
57
if _scheme_re .search (filename ):
54
58
# Relative to a URL
55
59
req_url = urllib_parse .urljoin (filename , req_url )
@@ -66,25 +70,19 @@ def parse_requirements(filename, finder=None, comes_from=None, options=None,
66
70
# requirement files, so we'll ignore.
67
71
pass
68
72
elif line .startswith (('-f' , '--find-links' )):
69
- if line .startswith ('-f' ):
70
- line = line [2 :].lstrip ()
71
- else :
72
- line = _remove_prefix (line , '--find-links' )
73
+ find_links = _remove_prefixes (line , '-f' , '--find-links' )
73
74
# FIXME: it would be nice to keep track of the source of
74
75
# the find_links:
75
76
# support a find-links local path relative to a requirements file
76
- relative_to_reqs_file = os .path .join (reqs_file_dir , line )
77
+ relative_to_reqs_file = os .path .join (reqs_file_dir , find_links )
77
78
if os .path .exists (relative_to_reqs_file ):
78
- line = relative_to_reqs_file
79
+ find_links = relative_to_reqs_file
79
80
if finder :
80
- finder .find_links .append (line )
81
+ finder .find_links .append (find_links )
81
82
elif line .startswith (('-i' , '--index-url' )):
82
- if line .startswith ('-i' ):
83
- line = line [2 :].lstrip ()
84
- else :
85
- line = _remove_prefix (line , '--index-url' )
83
+ index_url = _remove_prefixes (line , '-i' , '--index-url' )
86
84
if finder :
87
- finder .index_urls = [line ]
85
+ finder .index_urls = [index_url ]
88
86
elif line .startswith ('--extra-index-url' ):
89
87
line = _remove_prefix (line , '--extra-index-url' )
90
88
if finder :
@@ -123,12 +121,9 @@ def parse_requirements(filename, finder=None, comes_from=None, options=None,
123
121
else :
124
122
comes_from = '-r %s (line %s)' % (filename , line_number )
125
123
if line .startswith (('-e' , '--editable' )):
126
- if line .startswith ('-e' ):
127
- line = line [2 :].lstrip ()
128
- else :
129
- line = _remove_prefix (line , '--editable' )
124
+ editable = _remove_prefixes (line , '-e' , '--editable' )
130
125
req = InstallRequirement .from_editable (
131
- line ,
126
+ editable ,
132
127
comes_from = comes_from ,
133
128
default_vcs = options .default_vcs if options else None ,
134
129
isolated = options .isolated_mode if options else False ,
0 commit comments