# Buggy code
def requires(package, requirement):
    if not distributions.has(package):
        local_package = Package.from_href(context.fetch(package, into=cache))
        if package.remote:
            # this was a remote resolution -- so if we copy from remote to local but the
            # local already existed, update the mtime of the local so that it is correct
            # with respect to cache_ttl.
            os.utime(local_package.path, None)
        dist = translator.translate(local_package, into=cache)
        if dist is None:
            raise Untranslateable("Package %s is not translateable." % package)
        if not distribution_compatible(dist, interpreter, platform):
            raise Untranslateable(
                "Could not get distribution for %s on appropriate platform." % package
            )
        distributions.put(package, dist)
    dist = distributions.get(package)
    return dist.requires(extras=requirement.extras)


# Traceback (OSError)
mba=pex=; pex -r pytest -r setuptools -r py==1.4.25 -o /tmp/pt.pex --cache-ttl=3600 -v -v -v -v -v
pex: Package cache hit (inexact): pytest
pex: Package cache hit (inexact): setuptools
pex: Package cache miss: py==1.4.25
pex: Resolving distributions :: Fetching https://pypi.python.org/packages/source/p/py/py-1.4.25.tar.gz#md5pex: Validated py-1.4.25.tar.gz (md5=1f0b84dab1681fc1bf07c0528e091efb)
pex: Validated py-1.4.25.tar.gz (md5=1f0b84dab1681fc1bf07c0528e091efb)
pex: Resolving distributions :: Packaging py :: Installing /var/folders/rd/_tjz8zts3g14md1kmf38z6w80000gn/pex: Resolving distributions :: Packaging pytest                                                          pex: Resolving distributions :: Packaging pytest :: Installing /var/folders/rd/_tjz8zts3g14md1kmf38z6w8000pex: Resolving distributions :: Resolving py>=1.4.25                                                      Traceback (most recent call last):
File "/Users/wickman/Local/bin/pex/.bootstrap/_pex/pex.py", line 272, in execute
self.execute_entry(entry_point, args)
File "/Users/wickman/Local/bin/pex/.bootstrap/_pex/pex.py", line 320, in execute_entry
runner(entry_point)
File "/Users/wickman/Local/bin/pex/.bootstrap/_pex/pex.py", line 343, in execute_pkg_resources
runner()
File "/Users/wickman/.pex/install/pex-0.8.0.dev0-py2.py3-none-any.whl.0d5be588022f0aad6de2b84b77a8a890c43ad942/pex-0.8.0.dev0-py2.py3-none-any.whl/pex/bin/pex.py", line 325, in main
pex_builder = build_pex(args, options)
File "/Users/wickman/.pex/install/pex-0.8.0.dev0-py2.py3-none-any.whl.0d5be588022f0aad6de2b84b77a8a890c43ad942/pex-0.8.0.dev0-py2.py3-none-any.whl/pex/bin/pex.py", line 303, in build_pex
cache_ttl=options.cache_ttl)
File "/Users/wickman/.pex/install/pex-0.8.0.dev0-py2.py3-none-any.whl.0d5be588022f0aad6de2b84b77a8a890c43ad942/pex-0.8.0.dev0-py2.py3-none-any.whl/pex/resolver.py", line 215, in resolve
existing=distribution_set.get(requirement.key))
File "/Users/wickman/.pex/install/pex-0.8.0.dev0-py2.py3-none-any.whl.0d5be588022f0aad6de2b84b77a8a890c43ad942/pex-0.8.0.dev0-py2.py3-none-any.whl/pex/resolver.py", line 94, in packages_from_requirement_cached
packages = [package for package in packages if (now - os.path.getmtime(package.path)) < ttl]
File "/Users/wickman/Python/CPython-2.7.8/lib/python2.7/genericpath.py", line 54, in getmtime
return os.stat(filename).st_mtime
OSError: [Errno 2] No such file or directory: '/packages/source/p/py/py-1.4.25.tar.gz'

# Fixed code
def requires(package, requirement):
    if not distributions.has(package):
        with TRACER.timed("Fetching %s" % package.url, V=2):
            local_package = Package.from_href(context.fetch(package, into=cache))
        if package.remote:
            # this was a remote resolution -- so if we copy from remote to local but the
            # local already existed, update the mtime of the local so that it is correct
            # with respect to cache_ttl.
            os.utime(local_package.path, None)
        with TRACER.timed("Translating %s into distribution" % local_package.path, V=2):
            dist = translator.translate(local_package, into=cache)
        if dist is None:
            raise Untranslateable("Package %s is not translateable." % package)
        if not distribution_compatible(dist, interpreter, platform):
            raise Untranslateable(
                "Could not get distribution for %s on appropriate platform." % package
            )
        distributions.put(package, dist)
    dist = distributions.get(package)
    return dist.requires(extras=requirement.extras)