How to use the flit.installfrom.BadInput function in flit

To help you get started, we’ve selected a few flit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github takluyver / flit / flit / installfrom.py View on Github external
def installfrom(address, user=None, python=sys.executable):
    if user is None:
        user = site.ENABLE_USER_SITE \
               and not os.access(sysconfig.get_path('purelib'), os.W_OK)

    try:
        return install_local(fetch(*parse_address(address)), user=user, python=python)
    except BadInput as e:
        print(e, file=sys.stderr)
        return 2
github takluyver / flit / flit / installfrom.py View on Github external
class InvalidAddress(BadInput):
    def __init__(self, address):
        self.address = address

    def __str__(self):  # pragma: no cover
        return "Invalid address: {!r}".format(self.address)

class UnknownAddressType(BadInput):
    def __init__(self, address_type):
        self.address_type = address_type

    def __str__(self):  # pragma: no cover
        return "Unknown address type: {}".format(self.address_type)

class InvalidAddressLocation(BadInput):
    def __init__(self, address_type, location, expected_pattern):
        self.address_type = address_type
        self.location = location
        self.expected_pattern = expected_pattern

    def __str__(self):  # pragma: no cover
        return "Invalid location: {!r}\n{}: addresses should look like {}".format(
            self.location, self.address_type, self.expected_pattern
        )

def parse_address(address):
    if os.path.isfile(address):
        return 'local_file', address
    elif address.startswith(('http://', 'https://')):
        return 'url', address
github takluyver / flit / flit / installfrom.py View on Github external
import tempfile
from urllib.parse import urlparse
import zipfile

from requests_download import download
from .install import Installer

address_formats = {
    'github': (r'([\w\d_-]+)/([\w\d_-]+)(/(.+))?$', 'user/project[/commit-tag-or-branch]'),
}

class BadInput(Exception):
    """An error resulting from invalid input"""
    pass

class InvalidAddress(BadInput):
    def __init__(self, address):
        self.address = address

    def __str__(self):  # pragma: no cover
        return "Invalid address: {!r}".format(self.address)

class UnknownAddressType(BadInput):
    def __init__(self, address_type):
        self.address_type = address_type

    def __str__(self):  # pragma: no cover
        return "Unknown address type: {}".format(self.address_type)

class InvalidAddressLocation(BadInput):
    def __init__(self, address_type, location, expected_pattern):
        self.address_type = address_type
github takluyver / flit / flit / installfrom.py View on Github external
address_formats = {
    'github': (r'([\w\d_-]+)/([\w\d_-]+)(/(.+))?$', 'user/project[/commit-tag-or-branch]'),
}

class BadInput(Exception):
    """An error resulting from invalid input"""
    pass

class InvalidAddress(BadInput):
    def __init__(self, address):
        self.address = address

    def __str__(self):  # pragma: no cover
        return "Invalid address: {!r}".format(self.address)

class UnknownAddressType(BadInput):
    def __init__(self, address_type):
        self.address_type = address_type

    def __str__(self):  # pragma: no cover
        return "Unknown address type: {}".format(self.address_type)

class InvalidAddressLocation(BadInput):
    def __init__(self, address_type, location, expected_pattern):
        self.address_type = address_type
        self.location = location
        self.expected_pattern = expected_pattern

    def __str__(self):  # pragma: no cover
        return "Invalid location: {!r}\n{}: addresses should look like {}".format(
            self.location, self.address_type, self.expected_pattern
        )