Skip to content

Commit 6b98142

Browse files
committed
simplify
1 parent db2b4fd commit 6b98142

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

unidep/_dependencies_parsing.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _parse_dependency(
112112
ignore_pins: list[str],
113113
overwrite_pins: dict[str, str | None],
114114
skip_dependencies: list[str],
115-
origin: Path,
115+
origin: tuple[Path, ...],
116116
) -> list[Spec]:
117117
name, pin, selector = parse_package_str(dependency)
118118
if name in ignore_pins:
@@ -131,10 +131,10 @@ def _parse_dependency(
131131
identifier_hash = _identifier(identifier, selector)
132132
if which == "both":
133133
return [
134-
Spec(name, "conda", pin, identifier_hash, selector, origin=(origin,)),
135-
Spec(name, "pip", pin, identifier_hash, selector, origin=(origin,)),
134+
Spec(name, "conda", pin, identifier_hash, selector, origin=origin),
135+
Spec(name, "pip", pin, identifier_hash, selector, origin=origin),
136136
]
137-
return [Spec(name, which, pin, identifier_hash, selector, origin=(origin,))]
137+
return [Spec(name, which, pin, identifier_hash, selector, origin=origin)]
138138

139139

140140
class ParsedRequirements(NamedTuple):
@@ -264,7 +264,7 @@ def _update_data_structures(
264264
path_with_extras: PathWithExtras,
265265
datas: list[dict[str, Any]], # modified in place
266266
all_extras: list[list[str]], # modified in place
267-
seen: set[tuple[PathWithExtras, ...]], # modified in place
267+
seen: set[PathWithExtras], # modified in place
268268
yaml: YAML,
269269
is_nested: bool,
270270
origin: PathWithExtras | None = None,
@@ -273,10 +273,7 @@ def _update_data_structures(
273273
if verbose:
274274
print(f"📄 Parsing `{path_with_extras.path_with_extras}`")
275275
data = _load(path_with_extras.path, yaml)
276-
if origin is None:
277-
data["_origin"] = path_with_extras.path
278-
else:
279-
data["_origin"] = origin.path
276+
data["_origin"] = origin or path_with_extras
280277
datas.append(data)
281278
_move_local_optional_dependencies_to_local_dependencies(
282279
data=data, # modified in place
@@ -297,11 +294,7 @@ def _update_data_structures(
297294
verbose=verbose,
298295
)
299296

300-
seen.add(
301-
(origin.resolved(), path_with_extras.resolved())
302-
if origin is not None
303-
else (path_with_extras.resolved(),),
304-
)
297+
seen.add(path_with_extras.resolved())
305298

306299
# Handle "local_dependencies" (or old name "includes", changed in 0.42.0)
307300
for local_dependency in _get_local_dependencies(data):
@@ -318,6 +311,13 @@ def _update_data_structures(
318311
)
319312

320313

314+
def _unique_sorted_resolved(
315+
paths: tuple[PathWithExtras, ...],
316+
) -> tuple[PathWithExtras, ...]:
317+
"""Return a unique list of paths."""
318+
return tuple(sorted({p.resolved() for p in paths}))
319+
320+
321321
def _move_optional_dependencies_to_dependencies(
322322
data: dict[str, Any],
323323
path_with_extras: PathWithExtras,
@@ -388,7 +388,7 @@ def _add_local_dependencies(
388388
path_with_extras: PathWithExtras,
389389
datas: list[dict[str, Any]],
390390
all_extras: list[list[str]],
391-
seen: set[tuple[PathWithExtras, ...]],
391+
seen: set[PathWithExtras],
392392
yaml: YAML,
393393
verbose: bool = False,
394394
) -> None:
@@ -462,7 +462,7 @@ def parse_requirements(
462462
# `data` and `all_extras` are lists of the same length
463463
datas: list[dict[str, Any]] = []
464464
all_extras: list[list[str]] = []
465-
seen: set[tuple[PathWithExtras, ...]] = set()
465+
seen: set[PathWithExtras] = set()
466466
yaml = YAML(typ="rt") # Might be unused if all are TOML files
467467
for path_with_extras in paths_with_extras:
468468
_update_data_structures(
@@ -497,7 +497,7 @@ def parse_requirements(
497497
ignore_pins,
498498
overwrite_pins_map,
499499
skip_dependencies,
500-
origin=data["_origin"],
500+
origin=data["_origin"].resolved().path,
501501
)
502502
for opt_name, opt_deps in data.get("optional_dependencies", {}).items():
503503
if opt_name in _extras or "*" in _extras:
@@ -509,7 +509,7 @@ def parse_requirements(
509509
overwrite_pins_map,
510510
skip_dependencies,
511511
is_optional=True,
512-
origin=data["_origin"],
512+
origin=data["_origin"].resolved().path,
513513
)
514514

515515
return ParsedRequirements(
@@ -546,7 +546,7 @@ def _add_dependencies(
546546
skip_dependencies: list[str],
547547
*,
548548
is_optional: bool = False,
549-
origin: Path,
549+
origin: tuple[Path, ...],
550550
) -> int:
551551
for i, dep in enumerate(dependencies):
552552
identifier += 1

0 commit comments

Comments
 (0)