@@ -324,19 +324,20 @@ def __init__(
324
324
) -> None :
325
325
self ._session = session
326
326
self ._line_parser = line_parser
327
- self ._parsed_files : dict [str , Optional [str ]] = {}
328
327
329
328
def parse (
330
329
self , filename : str , constraint : bool
331
330
) -> Generator [ParsedLine , None , None ]:
332
331
"""Parse a given file, yielding parsed lines."""
333
- self . _parsed_files [ os . path . abspath ( filename )] = (
334
- None # The primary requirements file passed
332
+ yield from self . _parse_and_recurse (
333
+ filename , constraint , [{ os . path . abspath ( filename ): None }]
335
334
)
336
- yield from self ._parse_and_recurse (filename , constraint )
337
335
338
336
def _parse_and_recurse (
339
- self , filename : str , constraint : bool
337
+ self ,
338
+ filename : str ,
339
+ constraint : bool ,
340
+ parsed_files_stack : List [Dict [str , Optional [str ]]],
340
341
) -> Generator [ParsedLine , None , None ]:
341
342
for line in self ._parse_file (filename , constraint ):
342
343
if not line .is_requirement and (
@@ -364,8 +365,9 @@ def _parse_and_recurse(
364
365
req_path ,
365
366
)
366
367
)
367
- if req_path in self ._parsed_files :
368
- initial_file = self ._parsed_files [req_path ]
368
+ parsed_files = parsed_files_stack [0 ]
369
+ if req_path in parsed_files :
370
+ initial_file = parsed_files [req_path ]
369
371
tail = (
370
372
f" and again in { initial_file } "
371
373
if initial_file is not None
@@ -375,8 +377,11 @@ def _parse_and_recurse(
375
377
f"{ req_path } recursively references itself in { filename } { tail } "
376
378
)
377
379
# Keeping a track where was each file first included in
378
- self ._parsed_files [req_path ] = filename
379
- yield from self ._parse_and_recurse (req_path , nested_constraint )
380
+ new_parsed_files = parsed_files .copy ()
381
+ new_parsed_files [req_path ] = filename
382
+ yield from self ._parse_and_recurse (
383
+ req_path , nested_constraint , [new_parsed_files , * parsed_files_stack ]
384
+ )
380
385
else :
381
386
yield line
382
387
0 commit comments