simion / pip-upgrader

An interactive pip requirements upgrader. It also updates the version in your requirements.txt file.
Apache License 2.0
512 stars 35 forks source link

Add support for -r inclusion #5

Closed jhermann closed 7 years ago

jhermann commented 7 years ago

"dev" requirements typically also load the install requirements via -r requirements.txt – load and expand those lines as-if the inclusion appeared at that place. This has to work recursively.

Best implemented as a pre-processor that resolves any "-r" line until none are there any more, and THEN parses the list of requirements.

jhermann commented 7 years ago

This is working code for resolving the (relative) inclusion path. base_url is the containing document, url the thing after -r. Note that whitespace after -r is optional.

        # Ensure file: URLs are absolute
        if url.startswith("file:"):
            file_url = urlparse.urlparse(url)
            if file_url.netloc:
                raise RuntimeError("Unsupported file: URL %r with non-empty location %r" % (url, file_url.netloc))
            url = "file://" + os.path.abspath(file_url.path)

        # Fix Windows peculiarities
        url = url.replace('\\', '/')
        if IS_WIN32 and os.path.exists(base_url):
            base_url = 'file:///' + os.path.abspath(base_url).replace('\\', '/')

        # Now join it to resolve relative URLs
        url = urlparse.urljoin(base_url, url)
simion commented 7 years ago

I agree with requirements inclusion support. I'll check your code tonight, thanks for contributing.

simion commented 7 years ago

Done, first of all, upgrade this package to 1.4.2: pip-upgrade -p pip-upgrader Then run pip-upgrade <my-requirements-file>.

I've used python's os.path to handle file paths for all platforms.

Waiting confirmation to close this issue.

simion commented 7 years ago

Closing the issues, if there are problems with -r support, please reopen.