|
6 | 6 | import re
|
7 | 7 |
|
8 | 8 | from packaging.utils import canonicalize_name
|
| 9 | +from packaging.markers import Marker |
9 | 10 | # Between different versions of pip the location of PipSession has changed.
|
10 | 11 | try:
|
11 | 12 | from pip._internal.network.session import PipSession
|
@@ -142,12 +143,33 @@ def find_required_modules(options, requirements_filename: str):
|
142 | 143 |
|
143 | 144 | if options.ignore_reqs(requirement):
|
144 | 145 | log.debug('ignoring requirement: %s', requirement_name)
|
| 146 | + continue |
| 147 | + |
| 148 | + if options.skip_incompatible: |
| 149 | + requirement_string = requirement.requirement |
| 150 | + if not has_compatible_markers(requirement_string): |
| 151 | + log.debug('ignoring requirement (incompatible environment ' |
| 152 | + 'marker): %s', requirement_string) |
| 153 | + continue |
| 154 | + |
145 | 155 | else:
|
146 | 156 | log.debug('found requirement: %s', requirement_name)
|
147 | 157 | explicit.add(canonicalize_name(requirement_name))
|
| 158 | + |
148 | 159 | return explicit
|
149 | 160 |
|
150 | 161 |
|
| 162 | +def has_compatible_markers(full_requirement: str) -> bool: |
| 163 | + if ';' not in full_requirement: |
| 164 | + return True # No environment marker. |
| 165 | + |
| 166 | + enviroment_marker = full_requirement.split(';')[1] |
| 167 | + if not enviroment_marker: |
| 168 | + return True # Empty environment marker. |
| 169 | + |
| 170 | + return Marker(enviroment_marker).evaluate() |
| 171 | + |
| 172 | + |
151 | 173 | def is_package_file(path):
|
152 | 174 | '''Determines whether the path points to a Python package sentinel
|
153 | 175 | file - the __init__.py or its compiled variants.
|
|
0 commit comments