Esempio n. 1
0
    def run(self, options, args):
        with self._build_session(options) as session:
            reqs_to_uninstall = {}
            for name in args:
                req = install_req_from_line(
                    name,
                    isolated=options.isolated_mode,
                )
                if req.name:
                    reqs_to_uninstall[canonicalize_name(req.name)] = req
            for filename in options.requirements:
                for req in parse_requirements(filename,
                                              options=options,
                                              session=session):
                    if req.name:
                        reqs_to_uninstall[canonicalize_name(req.name)] = req
            if not reqs_to_uninstall:
                raise InstallationError(
                    'You must give at least one requirement to %(name)s (see '
                    '"pip help %(name)s")' % dict(name=self.name))

            protect_pip_from_modification_on_windows(
                modifying_pip="pip" in reqs_to_uninstall)

            for req in reqs_to_uninstall.values():
                uninstall_pathset = req.uninstall(
                    auto_confirm=options.yes,
                    verbose=self.verbosity > 0,
                )
                if uninstall_pathset:
                    uninstall_pathset.commit()
Esempio n. 2
0
def deduce_helpful_msg(req):
    # type: (str) -> str
    """Returns helpful msg in case requirements file does not exist,
    or cannot be parsed.

    :params req: Requirements file path
    """
    msg = ""
    if os.path.exists(req):
        msg = " It does exist."
        # Try to parse and check if it is a requirements file.
        try:
            with open(req, 'r') as fp:
                # parse first line only
                next(parse_requirements(fp.read()))
                msg += " The argument you provided " + \
                    "(%s) appears to be a" % (req) + \
                    " requirements file. If that is the" + \
                    " case, use the '-r' flag to install" + \
                    " the packages specified within it."
        except RequirementParseError:
            logger.debug("Cannot parse '%s' as requirements \
            file" % (req),
                         exc_info=True)
    else:
        msg += " File '%s' does not exist." % (req)
    return msg
Esempio n. 3
0
def main():
    usage = "usage: %prog release"
    parser = OptionParser(usage)
    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error("Please provide a release version, e.g. 0.7.0beta1")
    release = args[0]

    scripts_dir = os.path.dirname(__file__)

    download_dir = os.path.normpath(
        os.path.join(scripts_dir, '..', 'requirements', release))
    if not os.path.exists(download_dir):
        os.makedirs(download_dir)

    release_reqs = os.path.join(download_dir, 'release.txt')
    if not os.path.exists(release_reqs):
        parser.error("%s could not be found. Please make sure you created the file before." % release_reqs)

    complete_log = []
    level = 1
    level = pip.Logger.level_for_integer(4-level)
    logger = pip.Logger([(level, sys.stdout), (pip.Logger.DEBUG, complete_log.append)])
    pip.logger = logger

    finder = pip.PackageFinder(
        find_links=['http://pypi.pinaxproject.com'], index_urls=[pip.pypi_url])

    req_set = pip.RequirementSet(build_dir=download_dir, src_dir=download_dir)
    unmet_requirements= []

    for req in pip.parse_requirements(release_reqs, finder=finder):
        req_set.add_requirement(req)

    reqs = list(req_set.unnamed_requirements) + req_set.requirements.values()
    if not reqs:
        parser.error("No requirements were found in %s. Are you sure it contains something?" % release_reqs)

    for req in reqs:
        try:
            if req.name:
                logger.notify('Searching for: %s' % req.name)
            if req.editable:
                unmet_requirements.append(req)
            else:
                location = req.build_location(download_dir)
                if req.url is None:
                    link = finder.find_requirement(req, upgrade=False)
                else:
                    link = pip.Link(req.url)
                if link:
                    try:
                        md5_hash = link.md5_hash
                        target_url = link.url.split('#', 1)[0]
                        target_file = None
                        try:
                            resp = urllib2.urlopen(target_url)
                        except urllib2.HTTPError, e:
                            logger.fatal("HTTP error %s while getting %s" % (e.code, link))
                            raise
                        except IOError, e:
                            # Typically an FTP error
                            logger.fatal("Error %s while getting %s" % (e, link))
                            raise
                        content_type = resp.info()['content-type']
                        if content_type.startswith('text/html'):
                            unmet_requirements.append(req)
                            continue
                        filename = link.filename
                        ext = pip.splitext(filename)
                        if not ext:
                            ext = mimetypes.guess_extension(content_type)
                            filename += ext
                        temp_location = os.path.join(download_dir, filename)
                        if os.path.exists(temp_location):
                            logger.notify('Skipping %s. File exists.' % filename)
                            continue
                        fp = open(temp_location, 'wb')
                        if md5_hash:
                            download_hash = md5()
                        try:
                            total_length = int(resp.info()['content-length'])
                        except (ValueError, KeyError):
                            total_length = 0
                        downloaded = 0
                        show_progress = total_length > 40*1000 or not total_length
                        show_url = link.show_url
                        try:
                            if show_progress:
                                if total_length:
                                    logger.start_progress('Downloading %s (%s): ' % (show_url, pip.format_size(total_length)))
                                else:
                                    logger.start_progress('Downloading %s (unknown size): ' % show_url)
                            else:
                                logger.notify('Downloading %s' % show_url)
                            logger.debug('Downloading from URL %s' % link)
                            while 1:
                                chunk = resp.read(4096)
                                if not chunk:
                                    break
                                downloaded += len(chunk)
                                if show_progress:
                                    if not total_length:
                                        logger.show_progress('%s' % pip.format_size(downloaded))
                                    else:
                                        logger.show_progress('%3i%%  %s' % (100*downloaded/total_length, pip.format_size(downloaded)))
                                if md5_hash:
                                    download_hash.update(chunk)
                                fp.write(chunk)
                            fp.close()
                        finally:
                            if show_progress:
                                logger.end_progress('%s downloaded' % pip.format_size(downloaded))
                        if md5_hash:
                            download_hash = download_hash.hexdigest()
                            if download_hash != md5_hash:
                                logger.fatal("MD5 hash of the package %s (%s) doesn't match the expected hash %s!"
                                             % (link, download_hash, md5_hash))
                                raise pip.InstallationError('Bad MD5 hash for package %s' % link)
                    except urllib2.HTTPError, e:
                        logger.fatal('Could not install requirement %s because of error %s'
                                     % (req, e))
                        raise InstallationError(
                            'Could not install requirement %s because of HTTP error %s for URL %s'
                            % (req, e, url))
Esempio n. 4
0
def main():
    usage = "usage: %prog release"
    parser = OptionParser(usage)
    (options, args) = parser.parse_args()
    if len(args) != 1:
        parser.error("Please provide a release version, e.g. 0.7.0beta3")
    release = args[0]

    scripts_dir = os.path.dirname(__file__)

    download_dir = os.path.normpath(
        os.path.join(scripts_dir, '..', 'requirements', release))
    if not os.path.exists(download_dir):
        os.makedirs(download_dir)

    release_reqs = os.path.join(download_dir, 'release.txt')
    if not os.path.exists(release_reqs):
        parser.error("%s could not be found. Please make sure you created the file before." % release_reqs)

    complete_log = []
    level = 1
    level = pip.Logger.level_for_integer(4-level)
    logger = pip.Logger([(level, sys.stdout), (pip.Logger.DEBUG, complete_log.append)])
    pip.logger = logger

    finder = pip.PackageFinder(
        find_links=['http://pypi.pinaxproject.com'], index_urls=[pip.pypi_url])

    req_set = pip.RequirementSet(build_dir=download_dir, src_dir=download_dir)
    unmet_requirements= []

    for req in pip.parse_requirements(release_reqs, finder=finder):
        req_set.add_requirement(req)

    reqs = list(req_set.unnamed_requirements) + req_set.requirements.values()
    if not reqs:
        parser.error("No requirements were found in %s. Are you sure it contains something?" % release_reqs)

    for req in reqs:
        try:
            if req.name:
                logger.notify('Searching for: %s' % req.name)
            if req.editable:
                unmet_requirements.append(req)
            else:
                location = req.build_location(download_dir)
                if req.url is None:
                    link = finder.find_requirement(req, upgrade=False)
                else:
                    link = pip.Link(req.url)
                if link:
                    try:
                        md5_hash = link.md5_hash
                        target_url = link.url.split('#', 1)[0]
                        target_file = None
                        try:
                            resp = urllib2.urlopen(target_url)
                        except urllib2.HTTPError, e:
                            logger.fatal("HTTP error %s while getting %s" % (e.code, link))
                            raise
                        except IOError, e:
                            # Typically an FTP error
                            logger.fatal("Error %s while getting %s" % (e, link))
                            raise
                        content_type = resp.info()['content-type']
                        if content_type.startswith('text/html'):
                            unmet_requirements.append(req)
                            continue
                        filename = link.filename
                        ext = pip.splitext(filename)
                        if not ext:
                            ext = mimetypes.guess_extension(content_type)
                            filename += ext
                        temp_location = os.path.join(download_dir, filename)
                        if os.path.exists(temp_location):
                            logger.notify('Skipping %s. File exists.' % filename)
                            continue
                        fp = open(temp_location, 'wb')
                        if md5_hash:
                            download_hash = md5()
                        try:
                            total_length = int(resp.info()['content-length'])
                        except (ValueError, KeyError):
                            total_length = 0
                        downloaded = 0
                        show_progress = total_length > 40*1000 or not total_length
                        show_url = link.show_url
                        try:
                            if show_progress:
                                if total_length:
                                    logger.start_progress('Downloading %s (%s): ' % (show_url, pip.format_size(total_length)))
                                else:
                                    logger.start_progress('Downloading %s (unknown size): ' % show_url)
                            else:
                                logger.notify('Downloading %s' % show_url)
                            logger.debug('Downloading from URL %s' % link)
                            while 1:
                                chunk = resp.read(4096)
                                if not chunk:
                                    break
                                downloaded += len(chunk)
                                if show_progress:
                                    if not total_length:
                                        logger.show_progress('%s' % pip.format_size(downloaded))
                                    else:
                                        logger.show_progress('%3i%%  %s' % (100*downloaded/total_length, pip.format_size(downloaded)))
                                if md5_hash:
                                    download_hash.update(chunk)
                                fp.write(chunk)
                            fp.close()
                        finally:
                            if show_progress:
                                logger.end_progress('%s downloaded' % pip.format_size(downloaded))
                        if md5_hash:
                            download_hash = download_hash.hexdigest()
                            if download_hash != md5_hash:
                                logger.fatal("MD5 hash of the package %s (%s) doesn't match the expected hash %s!"
                                             % (link, download_hash, md5_hash))
                                raise pip.InstallationError('Bad MD5 hash for package %s' % link)
                    except urllib2.HTTPError, e:
                        logger.fatal('Could not install requirement %s because of error %s'
                                     % (req, e))
                        raise InstallationError(
                            'Could not install requirement %s because of HTTP error %s for URL %s'
                            % (req, e, url))
Esempio n. 5
0
logger = pip.Logger([(level, sys.stdout), (pip.Logger.DEBUG, complete_log.append)])
pip.logger = logger

finder = pip.PackageFinder(find_links=[], index_urls=[pip.pypi_url])

scripts_dir = os.path.dirname(__file__)
download_dir = os.path.join(scripts_dir, '..', 'download')
filename = os.path.join(scripts_dir, '..', 'requirements', 'external_apps.txt')

if not os.path.exists(download_dir):
    os.makedirs(download_dir)

req_set = pip.RequirementSet(build_dir=download_dir, src_dir=download_dir)
unmet_requirements= []

for req in pip.parse_requirements(filename, finder=finder):
    req_set.add_requirement(req)

for req in list(req_set.unnamed_requirements) + req_set.requirements.values():
    try:
        if req.name:
            logger.notify('Searching for: %s' % req.name)
        if req.editable:
            unmet_requirements.append(req)
        else:
            location = req.build_location(download_dir)
            if req.url is None:
                link = finder.find_requirement(req, upgrade=False)
            else:
                link = pip.Link(req.url)
            if link:
Esempio n. 6
0
    def populate_requirement_set(
            requirement_set,  # type: RequirementSet
            args,  # type: List[str]
            options,  # type: Values
            finder,  # type: PackageFinder
            session,  # type: PipSession
            name,  # type: str
            wheel_cache  # type: Optional[WheelCache]
    ):
        # type: (...) -> None
        """
        Marshal cmd line args into a requirement set.
        """
        # NOTE: As a side-effect, options.require_hashes and
        #       requirement_set.require_hashes may be updated

        for filename in options.constraints:
            for req_to_add in parse_requirements(filename,
                                                 constraint=True,
                                                 finder=finder,
                                                 options=options,
                                                 session=session,
                                                 wheel_cache=wheel_cache):
                req_to_add.is_direct = True
                requirement_set.add_requirement(req_to_add)

        for req in args:
            req_to_add = install_req_from_line(req,
                                               None,
                                               isolated=options.isolated_mode,
                                               use_pep517=options.use_pep517,
                                               wheel_cache=wheel_cache)
            req_to_add.is_direct = True
            requirement_set.add_requirement(req_to_add)

        for req in options.editables:
            req_to_add = install_req_from_editable(
                req,
                isolated=options.isolated_mode,
                use_pep517=options.use_pep517,
                wheel_cache=wheel_cache)
            req_to_add.is_direct = True
            requirement_set.add_requirement(req_to_add)

        for filename in options.requirements:
            for req_to_add in parse_requirements(
                    filename,
                    finder=finder,
                    options=options,
                    session=session,
                    wheel_cache=wheel_cache,
                    use_pep517=options.use_pep517):
                req_to_add.is_direct = True
                requirement_set.add_requirement(req_to_add)
        # If --require-hashes was a line in a requirements file, tell
        # RequirementSet about it:
        requirement_set.require_hashes = options.require_hashes

        if not (args or options.editables or options.requirements):
            opts = {'name': name}
            if options.find_links:
                raise CommandError(
                    'You must give at least one requirement to %(name)s '
                    '(maybe you meant "pip %(name)s %(links)s"?)' %
                    dict(opts, links=' '.join(options.find_links)))
            else:
                raise CommandError(
                    'You must give at least one requirement to %(name)s '
                    '(see "pip help %(name)s")' % opts)
Esempio n. 7
0
    from loginsightwebhookdemo import __version__ as loginsightwebhookdemoversion  # TODO Replace with a static variant?
except ImportError:
    loginsightwebhookdemoversion = "0.dev0"

# Hack from https://stackoverflow.com/questions/14399534/how-can-i-reference-requirements-txt-for-the-install-requires-kwarg-in-setuptool
# parse_requirements() returns generator of pip.req.InstallRequirement objects
try:
    if os.environ['PYTHONPATH']:
        HDIR = os.environ['PYTHONPATH']
except:
    try:
        if os.environ['TRAVIS_BUILD_DIR']:
            HDIR = os.environ['TRAVIS_BUILD_DIR']
    except:
        HDIR = '.'
install_reqs = parse_requirements(HDIR + '/requirements.txt', session='hack')
test_reqs = parse_requirements(HDIR + '/test-requirements.txt', session='hack')

# reqs is a list of requirement
# e.g. ['django==1.5.1', 'mezzanine==1.4.6']
reqs = [str(ir.req) for ir in install_reqs]
treqs = [str(ir.req) for ir in test_reqs]

class PyTest(TestCommand):
    user_options = [('pytest-args=', 'a', "Arguments to pass to pytest")]
    description = "Run tests in the current environment"

    def initialize_options(self):
        TestCommand.initialize_options(self)
        self.args = []