Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion requirements/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down