# Buggy code
def parse_requirements(filename, finder=None, comes_from=None, options=None):
    skip_match = None
    skip_regex = options.skip_requirements_regex if options else None
    if skip_regex:
        skip_match = re.compile(skip_regex)
    reqs_file_dir = os.path.dirname(os.path.abspath(filename))
    filename, content = get_file_content(filename, comes_from=comes_from)
    for line_number, line in enumerate(content.splitlines()):
        line_number += 1
        line = line.strip()
        if not line or line.startswith("#"):
            continue
        if skip_match and skip_match.search(line):
            continue
        if line.startswith("-r") or line.startswith("--requirement"):
            if line.startswith("-r"):
                req_url = line[2:].strip()
            else:
                req_url = line[len("--requirement") :].strip().strip("=")
            if _scheme_re.search(filename):
                # Relative to a URL
                req_url = urlparse.urljoin(filename, req_url)
            elif not _scheme_re.search(req_url):
                req_url = os.path.join(os.path.dirname(filename), req_url)
            for item in parse_requirements(
                req_url, finder, comes_from=filename, options=options
            ):
                yield item
        elif line.startswith("-Z") or line.startswith("--always-unzip"):
            # No longer used, but previously these were used in
            # requirement files, so we'll ignore.
            pass
        elif line.startswith("-f") or line.startswith("--find-links"):
            if line.startswith("-f"):
                line = line[2:].strip()
            else:
                line = line[len("--find-links") :].strip().lstrip("=")
            ## FIXME: it would be nice to keep track of the source of
            ## the find_links:
            # support a find-links local path relative to a requirements file
            relative_to_reqs_file = os.path.join(reqs_file_dir, line)
            if os.path.exists(relative_to_reqs_file):
                line = relative_to_reqs_file
            if finder:
                finder.find_links.append(line)
        elif line.startswith("-i") or line.startswith("--index-url"):
            if line.startswith("-i"):
                line = line[2:].strip()
            else:
                line = line[len("--index-url") :].strip().lstrip("=")
            if finder:
                finder.index_urls = [line]
        elif line.startswith("--extra-index-url"):
            line = line[len("--extra-index-url") :].strip().lstrip("=")
            if finder:
                finder.index_urls.append(line)
        elif line.startswith("--no-index"):
            finder.index_urls = []
        else:
            comes_from = "-r %s (line %s)" % (filename, line_number)
            if line.startswith("-e") or line.startswith("--editable"):
                if line.startswith("-e"):
                    line = line[2:].strip()
                else:
                    line = line[len("--editable") :].strip().lstrip("=")
                req = InstallRequirement.from_editable(
                    line, comes_from=comes_from, default_vcs=options.default_vcs
                )
            else:
                req = InstallRequirement.from_line(line, comes_from)
            yield req


# Traceback (IOError)
! (py25) crose@02-mr41-a (log) $ ../bin/pip -v install pyhamcrest
../bin/pip -v install pyhamcrest
Downloading/unpacking pyhamcrest
Using version 1.4 (newest of versions: 1.4, 1.4, 1.4, 1.3, 1.3, 1.2.1, 1.2.1, 1.1, 1.0)
Downloading PyHamcrest-1.4.tar.gz
Running setup.py egg_info for package pyhamcrest
Traceback (most recent call last):
File "<string>", line 14, in <module>
IOError: [Errno 2] No such file or directory: '/Users/crose/projects/advanis/cs008_defines/python/.tox/py25/build/pyhamcrest/setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "<string>", line 14, in <module>

IOError: [Errno 2] No such file or directory: '/Users/crose/projects/advanis/cs008_defines/python/.tox/py25/build/pyhamcrest/setup.py'

----------------------------------------
Command python setup.py egg_info failed with error code 1
Exception information:
Traceback (most recent call last):
File "/Users/crose/projects/advanis/cs008_defines/python/.tox/py25/lib/python2.5/site-packages/pip-0.8.1-py2.5.egg/pip/basecommand.py", line 130, in main
self.run(options, args)
File "/Users/crose/projects/advanis/cs008_defines/python/.tox/py25/lib/python2.5/site-packages/pip-0.8.1-py2.5.egg/pip/commands/install.py", line 223, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/Users/crose/projects/advanis/cs008_defines/python/.tox/py25/lib/python2.5/site-packages/pip-0.8.1-py2.5.egg/pip/req.py", line 941, in prepare_files
req_to_install.run_egg_info()
File "/Users/crose/projects/advanis/cs008_defines/python/.tox/py25/lib/python2.5/site-packages/pip-0.8.1-py2.5.egg/pip/req.py", line 219, in run_egg_info
command_desc='python setup.py egg_info')
File "/Users/crose/projects/advanis/cs008_defines/python/.tox/py25/lib/python2.5/site-packages/pip-0.8.1-py2.5.egg/pip/__init__.py", line 249, in call_subprocess
% (command_desc, proc.returncode))
InstallationError: Command python setup.py egg_info failed with error code 1

Storing complete log in /Users/crose/.pip/pip.log
! (py25) crose@02-mr41-a (log) $ python --version
python --version
Python 2.5.4

# Fixed code
def parse_requirements(filename, finder=None, comes_from=None, options=None):
    skip_match = None
    skip_regex = options.skip_requirements_regex if options else None
    if skip_regex:
        skip_match = re.compile(skip_regex)
    reqs_file_dir = os.path.dirname(os.path.abspath(filename))
    filename, content = get_file_content(filename, comes_from=comes_from)
    for line_number, line in enumerate(content.splitlines()):
        line_number += 1
        line = line.strip()
        if not line or line.startswith("#"):
            continue
        if skip_match and skip_match.search(line):
            continue
        if line.startswith("-r") or line.startswith("--requirement"):
            if line.startswith("-r"):
                req_url = line[2:].strip()
            else:
                req_url = line[len("--requirement") :].strip().strip("=")
            if _scheme_re.search(filename):
                # Relative to a URL
                req_url = urlparse.urljoin(filename, req_url)
            elif not _scheme_re.search(req_url):
                req_url = os.path.join(os.path.dirname(filename), req_url)
            for item in parse_requirements(
                req_url, finder, comes_from=filename, options=options
            ):
                yield item
        elif line.startswith("-Z") or line.startswith("--always-unzip"):
            # No longer used, but previously these were used in
            # requirement files, so we'll ignore.
            pass
        elif line.startswith("-f") or line.startswith("--find-links"):
            if line.startswith("-f"):
                line = line[2:].strip()
            else:
                line = line[len("--find-links") :].strip().lstrip("=")
            ## FIXME: it would be nice to keep track of the source of
            ## the find_links:
            # support a find-links local path relative to a requirements file
            relative_to_reqs_file = os.path.join(reqs_file_dir, line)
            if os.path.exists(relative_to_reqs_file):
                line = relative_to_reqs_file
            if finder:
                finder.find_links.append(line)
        elif line.startswith("-i") or line.startswith("--index-url"):
            if line.startswith("-i"):
                line = line[2:].strip()
            else:
                line = line[len("--index-url") :].strip().lstrip("=")
            if finder:
                finder.index_urls = [line]
        elif line.startswith("--extra-index-url"):
            line = line[len("--extra-index-url") :].strip().lstrip("=")
            if finder:
                finder.index_urls.append(line)
        elif line.startswith("--use-wheel"):
            finder.use_wheel = True
        elif line.startswith("--no-index"):
            finder.index_urls = []
        else:
            comes_from = "-r %s (line %s)" % (filename, line_number)
            if line.startswith("-e") or line.startswith("--editable"):
                if line.startswith("-e"):
                    line = line[2:].strip()
                else:
                    line = line[len("--editable") :].strip().lstrip("=")
                req = InstallRequirement.from_editable(
                    line, comes_from=comes_from, default_vcs=options.default_vcs
                )
            else:
                req = InstallRequirement.from_line(line, comes_from)
            yield req