Skip to content

Commit 0571bfe

Browse files
committed
fix recursion
1 parent b143706 commit 0571bfe

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

unidep/_dependencies_parsing.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,13 @@ def _update_data_structures(
267267
seen: set[tuple[PathWithExtras, ...]], # modified in place
268268
yaml: YAML,
269269
is_nested: bool,
270-
origin: PathWithExtras | None = None,
270+
origin: PathWithExtras,
271271
verbose: bool = False,
272272
) -> None:
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
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(_unique([path_with_extras, origin]))
305298

306299
# Handle "local_dependencies" (or old name "includes", changed in 0.42.0)
307300
for local_dependency in _get_local_dependencies(data):
@@ -314,10 +307,16 @@ def _update_data_structures(
314307
all_extras=all_extras, # modified in place
315308
seen=seen, # modified in place
316309
yaml=yaml,
310+
origin=origin,
317311
verbose=verbose,
318312
)
319313

320314

315+
def _unique(paths: list[PathWithExtras]) -> tuple[PathWithExtras, ...]:
316+
"""Remove duplicates from a list of PathWithExtras."""
317+
return tuple(sorted({p.resolved() for p in paths}))
318+
319+
321320
def _move_optional_dependencies_to_dependencies(
322321
data: dict[str, Any],
323322
path_with_extras: PathWithExtras,
@@ -390,6 +389,7 @@ def _add_local_dependencies(
390389
all_extras: list[list[str]],
391390
seen: set[tuple[PathWithExtras, ...]],
392391
yaml: YAML,
392+
origin: PathWithExtras,
393393
verbose: bool = False,
394394
) -> None:
395395
try:
@@ -409,7 +409,7 @@ def _add_local_dependencies(
409409
"detect its dependencies.",
410410
)
411411
return
412-
if requirements_dep_file.resolved() in seen:
412+
if _unique([origin, requirements_dep_file]) in seen:
413413
return # Avoids circular local_dependencies
414414
if verbose:
415415
print(f"📄 Parsing `{local_dependency}` from `local_dependencies`")
@@ -421,7 +421,7 @@ def _add_local_dependencies(
421421
yaml=yaml,
422422
verbose=verbose,
423423
is_nested=True,
424-
origin=path_with_extras,
424+
origin=origin,
425425
)
426426

427427

@@ -473,6 +473,7 @@ def parse_requirements(
473473
yaml=yaml,
474474
verbose=verbose,
475475
is_nested=False,
476+
origin=path_with_extras,
476477
)
477478

478479
assert len(datas) == len(all_extras)
@@ -497,7 +498,7 @@ def parse_requirements(
497498
ignore_pins,
498499
overwrite_pins_map,
499500
skip_dependencies,
500-
origin=data["_origin"],
501+
origin=data["_origin"].path,
501502
)
502503
for opt_name, opt_deps in data.get("optional_dependencies", {}).items():
503504
if opt_name in _extras or "*" in _extras:
@@ -509,7 +510,7 @@ def parse_requirements(
509510
overwrite_pins_map,
510511
skip_dependencies,
511512
is_optional=True,
512-
origin=data["_origin"],
513+
origin=data["_origin"].path,
513514
)
514515

515516
return ParsedRequirements(

0 commit comments

Comments
 (0)