diff --git a/requirements/parser.py b/requirements/parser.py index 6c92bc2..b12c294 100644 --- a/requirements/parser.py +++ b/requirements/parser.py @@ -39,7 +39,7 @@ } -def parse(reqstr: Union[str, TextIO]) -> Iterator[Requirement]: +def parse(reqstr: Union[str, TextIO], skip_includes: bool=False) -> Iterator[Requirement]: """ Parse a requirements file into a list of Requirements @@ -63,6 +63,8 @@ def parse(reqstr: Union[str, TextIO]) -> Iterator[Requirement]: # comments are lines that start with # only continue elif line.startswith('-r') or line.startswith('--requirement'): + if skip_includes: + continue _, new_filename = line.split() new_file_path = os.path.join(os.path.dirname(filename or '.'), new_filename) diff --git a/tests/test_parser.py b/tests/test_parser.py index 303c866..c071f74 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -44,6 +44,12 @@ def test_requirement_files(self) -> None: self._test_req_file(req_file=fn) + def test_skip_includes(self) -> None: + fp = join(TestParser._requirements_files_dir, 'recursive_1.txt') + with open(fp) as req_fh: + parsed = parse(req_fh, skip_includes=True) + self.assertEqual([p.line for p in parsed], ['Django==1.6']) + def _test_req_file(self, req_file: str) -> None: fp = join(TestParser._requirements_files_dir, req_file) with open(fp) as req_fh: