Exemplo n.º 1
0
def preprocess(content, options):
    """Split, filter, and join lines, and return a line iterator
    :param content: the content of the requirements file
    :param options: cli options
    """
    lines_enum = enumerate(content.splitlines(), start=1)
    lines_enum = join_lines(lines_enum)
    lines_enum = ignore_comments(lines_enum)
    lines_enum = skip_regex(lines_enum, options)
    return lines_enum
Exemplo n.º 2
0
 def test_last_line_with_escape(self):
     lines = enumerate([
         'line 1',
         'line 2 \\',
     ], start=1)
     expect = [
         (1, 'line 1'),
         (2, 'line 2 '),
     ]
     assert expect == list(join_lines(lines))
Exemplo n.º 3
0
 def test_last_line_with_escape(self):
     lines = enumerate([
         'line 1',
         'line 2 \\',
     ], start=1)
     expect = [
         (1, 'line 1'),
         (2, 'line 2 '),
     ]
     assert expect == list(join_lines(lines))
Exemplo n.º 4
0
 def test_join_lines(self):
     lines = enumerate([
         'line 1', 'line 2:1 \\', 'line 2:2', 'line 3:1 \\', 'line 3:2 \\',
         'line 3:3', 'line 4'
     ],
                       start=1)
     expect = [
         (1, 'line 1'),
         (2, 'line 2:1 line 2:2'),
         (4, 'line 3:1 line 3:2 line 3:3'),
         (7, 'line 4'),
     ]
     assert expect == list(join_lines(lines))
Exemplo n.º 5
0
 def test_join_lines(self):
     lines = enumerate([
         'line 1',
         'line 2:1 \\',
         'line 2:2',
         'line 3:1 \\',
         'line 3:2 \\',
         'line 3:3',
         'line 4'
     ], start=1)
     expect = [
         (1, 'line 1'),
         (2, 'line 2:1 line 2:2'),
         (4, 'line 3:1 line 3:2 line 3:3'),
         (7, 'line 4'),
     ]
     assert expect == list(join_lines(lines))
Exemplo n.º 6
0
    def test_join_lines(self):
        lines = dedent('''\
        line 1
        line 2:1 \\
        line 2:2
        line 3:1 \\
        line 3:2 \\
        line 3:3
        line 4
        ''').splitlines()

        expect = [
            'line 1',
            'line 2:1 line 2:2',
            'line 3:1 line 3:2 line 3:3',
            'line 4',
        ]
        assert expect == list(join_lines(lines))
Exemplo n.º 7
0
    def test_join_lines(self):
        lines = dedent('''\
        line 1
        line 2:1 \\
        line 2:2
        line 3:1 \\
        line 3:2 \\
        line 3:3
        line 4
        ''').splitlines()

        expect = [
            'line 1',
            'line 2:1 line 2:2',
            'line 3:1 line 3:2 line 3:3',
            'line 4',
        ]
        assert expect == list(join_lines(lines))
Exemplo n.º 8
0
def parse_requirements(filename, finder=None, comes_from=None, options=None,
                       session=None, constraint=False, wheel_cache=None):
    """Parse a requirements file and yield InstallRequirement instances.
    :param filename:    Path or url of requirements file.
    :param finder:      Instance of pip.index.PackageFinder.
    :param comes_from:  Origin description of requirements.
    :param options:     Global options.
    :param session:     Instance of pip.download.PipSession.
    :param constraint:  If true, parsing a constraint file rather than
        requirements file.
    :param wheel_cache: Instance of pip.wheel.WheelCache
    """
    if session is None:
        raise TypeError(
            "parse_requirements() missing 1 required keyword argument: "
            "'session'"
        )

    _, content = get_file_content(
        filename, comes_from=comes_from, session=session
    )

    lines = content.splitlines()
    lines = ignore_comments(lines)
    lines = join_lines(lines)
    lines = skip_regex(lines, options)
    lines = expand_env_variables(lines)

    kwargs = {}
    # The constraint keyword was only added in 7.1+
    if tuple(pip.__version__.split('.')[:2]) > ('7', '0'):
        kwargs['constraint'] = constraint

    for line_number, line in enumerate(lines, 1):
        req_iter = process_line(line, filename, line_number, finder,
                                comes_from, options, session, wheel_cache,
                                **kwargs)
        for req in req_iter:
            yield req
Exemplo n.º 9
0
 def __read_lines(self):
     with open(self.path) as f:
         lines = f.read().splitlines()
         lines_enum = enumerate(lines, start=1)
         lines_enum = join_lines(lines_enum)
         lines_enum = ignore_comments(lines_enum)
     for line_number, line in lines_enum:
         if line.startswith('-e '):
             ui.warn('requirements file flags are not supported yet:', line)
             continue
         req_iter = process_line(
             line,
             None,
             0,
             None,
             None,
             None,
             None,
             None,
         )
         for req in req_iter:
             yield req, line_number
Exemplo n.º 10
0
def yield_lines(content):
    lines = content.splitlines()
    for line_number, line in req_file.join_lines(enumerate(lines)):
        yield (lines[line_number], line_number + 1, line)