Skip to content

Commit 4e89dd1

Browse files
committed
Limit marker complexity a bit
- Fix bugs related to previous marker complexity reduction Signed-off-by: Dan Ryan <[email protected]>
1 parent e2f7918 commit 4e89dd1

File tree

3 files changed

+18
-88
lines changed

3 files changed

+18
-88
lines changed

src/requirementslib/models/dependencies.py

+10-80
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from ..environment import MYPY_RUNNING
2020
from ..utils import _ensure_dir, prepare_pip_source_args
2121
from .cache import CACHE_DIR, DependencyCache
22+
from .setup_info import SetupInfo
2223
from .utils import (
2324
clean_requires_python,
2425
fix_requires_python_marker,
@@ -479,90 +480,19 @@ def get_dependencies_from_index(dep, sources=None, pip_options=None, wheel_cache
479480
if not wheel_cache:
480481
wheel_cache = WHEEL_CACHE
481482
dep.is_direct = True
482-
reqset = pip_shims.shims.RequirementSet()
483-
reqset.add_requirement(dep)
484483
requirements = None
485484
setup_requires = {}
486-
with temp_environ(), start_resolver(
487-
finder=finder, session=session, wheel_cache=wheel_cache
488-
) as resolver:
485+
with temp_environ():
489486
os.environ["PIP_EXISTS_ACTION"] = "i"
490-
dist = None
491487
if dep.editable and not dep.prepared and not dep.req:
492-
with cd(dep.setup_py_dir):
493-
from setuptools.dist import distutils
494-
495-
try:
496-
dist = distutils.core.run_setup(dep.setup_py)
497-
except (ImportError, TypeError, AttributeError):
498-
dist = None
499-
else:
500-
setup_requires[dist.get_name()] = dist.setup_requires
501-
if not dist:
502-
try:
503-
dist = dep.get_dist()
504-
except (TypeError, ValueError, AttributeError):
505-
pass
506-
else:
507-
setup_requires[dist.get_name()] = dist.setup_requires
508-
resolver.require_hashes = False
509-
try:
510-
results = resolver._resolve_one(reqset, dep)
511-
except Exception:
512-
# FIXME: Needs to bubble the exception somehow to the user.
513-
results = []
514-
finally:
515-
try:
516-
wheel_cache.cleanup()
517-
except AttributeError:
518-
pass
519-
resolver_requires_python = getattr(resolver, "requires_python", None)
520-
requires_python = getattr(reqset, "requires_python", resolver_requires_python)
521-
if requires_python:
522-
add_marker = fix_requires_python_marker(requires_python)
523-
reqset.remove(dep)
524-
if dep.req.marker:
525-
dep.req.marker._markers.extend(["and"].extend(add_marker._markers))
526-
else:
527-
dep.req.marker = add_marker
528-
reqset.add(dep)
529-
requirements = set()
530-
for r in results:
531-
if requires_python:
532-
if r.req.marker:
533-
r.req.marker._markers.extend(["and"].extend(add_marker._markers))
534-
else:
535-
r.req.marker = add_marker
536-
requirements.add(format_requirement(r))
537-
for section in setup_requires:
538-
python_version = section
539-
not_python = not is_python(section)
540-
541-
# This is for cleaning up :extras: formatted markers
542-
# by adding them to the results of the resolver
543-
# since any such extra would have been returned as a result anyway
544-
for value in setup_requires[section]:
545-
546-
# This is a marker.
547-
if is_python(section):
548-
python_version = value[1:-1]
549-
else:
550-
not_python = True
551-
552-
if ":" not in value and not_python:
553-
try:
554-
requirement_str = "{0}{1}".format(value, python_version).replace(
555-
":", ";"
556-
)
557-
requirements.add(
558-
format_requirement(
559-
make_install_requirement(requirement_str).ireq
560-
)
561-
)
562-
# Anything could go wrong here -- can't be too careful.
563-
except Exception:
564-
pass
565-
488+
setup_info = SetupInfo.from_ireq(dep)
489+
results = setup_info.get_info()
490+
setup_requires.update(results["setup_requires"])
491+
requirements = set(results["requires"].values())
492+
else:
493+
results = pip_shims.shims.resolve(dep)
494+
requirements = [v for v in results.values() if v.name != dep.name]
495+
requirements = set([format_requirement(r) for r in requirements])
566496
if not dep.editable and is_pinned_requirement(dep) and requirements is not None:
567497
DEPENDENCY_CACHE[dep] = list(requirements)
568498
return requirements

src/requirementslib/models/markers.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,8 @@ def _format_pyspec(specifier):
148148
version = getattr(specifier, "version", specifier).rstrip()
149149
if version and version.endswith("*"):
150150
if version.endswith(".*"):
151-
version = version.rstrip(".*")
152-
else:
153-
version = version.rstrip("*")
151+
version = version[:-2]
152+
version = version.rstrip("*")
154153
specifier = Specifier("{0}{1}".format(specifier.operator, version))
155154
try:
156155
op = REPLACE_RANGES[specifier.operator]
@@ -228,10 +227,10 @@ def normalize_specifier_set(specs):
228227
return {_format_pyspec(spec) for spec in specs}
229228
spec_list = []
230229
for spec in specs.split(","):
230+
spec = spec.strip()
231231
if spec.endswith(".*"):
232-
spec = spec.rstrip(".*")
233-
elif spec.endswith("*"):
234-
spec = spec.rstrip("*")
232+
spec = spec[:-2]
233+
spec = spec.rstrip("*")
235234
spec_list.append(spec)
236235
return normalize_specifier_set(SpecifierSet(",".join(spec_list)))
237236

@@ -582,9 +581,10 @@ def get_specset(marker_list):
582581
specset = set()
583582
_last_str = "and"
584583
for marker_parts in marker_list:
585-
specset.update(marker_parts)
586584
if isinstance(marker_parts, str):
587585
_last_str = marker_parts # noqa
586+
else:
587+
specset.update(_get_specifiers_from_markers(marker_parts))
588588
specifiers = SpecifierSet()
589589
specifiers._specs = frozenset(specset)
590590
return specifiers

tests/unit/test_markers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_get_extras(marker, extras):
136136
Marker(
137137
"os_name == 'posix' and python_version >= '2.7' and python_version not in '3.0.*,3.1.*,3.2.*,3.3.*'"
138138
),
139-
SpecifierSet("!=3.0,!=3.1,!=3.2,!=3.3,>=2.7"),
139+
SpecifierSet("!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,>=2.7"),
140140
),
141141
],
142142
)

0 commit comments

Comments
 (0)