Beispiel #1
0
def test_run_method_should_return_no_matches_found_when_does_not_find_pkgs():
    """
    Test SearchCommand.run for no matches
    """
    command = SearchCommand()
    cmdline = "--index=https://pypi.python.org/pypi nonexistentpackage"
    options, args = command.parse_args(cmdline.split())
    status = command.run(options, args)
    assert status == NO_MATCHES_FOUND
Beispiel #2
0
def test_run_method_should_return_success_when_find_packages():
    """
    Test SearchCommand.run for found package
    """
    command = SearchCommand()
    cmdline = "--index=https://pypi.python.org/pypi pip"
    options, args = command.parse_args(cmdline.split())
    status = command.run(options, args)
    assert status == SUCCESS
Beispiel #3
0
def test_run_method_should_return_no_matches_found_when_does_not_find_pkgs():
    """
    Test SearchCommand.run for no matches
    """
    command = SearchCommand()
    cmdline = "--index=https://pypi.python.org/pypi nonexistentpackage"
    options, args = command.parse_args(cmdline.split())
    status = command.run(options, args)
    assert status == NO_MATCHES_FOUND
Beispiel #4
0
def test_run_method_should_return_success_when_find_packages():
    """
    Test SearchCommand.run for found package
    """
    command = SearchCommand()
    cmdline = "--index=https://pypi.python.org/pypi pip"
    options, args = command.parse_args(cmdline.split())
    status = command.run(options, args)
    assert status == SUCCESS
Beispiel #5
0
    def _package_exists_in_pypi(self, fullname):
        searcher = SearchCommand()
        options, args = searcher.parse_args([fullname])
        matches = searcher.search(args, options)
        found_match = None
        for match in matches:
            if match["name"] == fullname:
                return True
                break

        return False
Beispiel #6
0
 def search_packages(package_name):
     """
     query pip package repository
     """
     versions = []
     search = SearchCommand()
     pypi = search.search(package_name,
                          search.parse_args([package_name])[0])
     for hit in transform_hits(pypi):
         if hit['name'] == package_name:
             versions = hit['versions']
             break
     return versions
Beispiel #7
0
 def search_packages(package_name):
     """
     query pip package repository
     """
     versions = []
     search = SearchCommand()
     pypi = search.search(package_name,
                          search.parse_args([package_name])[0])
     for hit in transform_hits(pypi):
         if hit['name'] == package_name:
             versions = hit['versions']
             break
     return versions
Beispiel #8
0
    def run(self):
        pkg_name = self.distribution.get_name()
        pkg_version = self.distribution.get_version()
        search = SearchCommand()
        options, _ = search.parse_args([pkg_name])
        pypi_hits = search.search(pkg_name, options)
        hits = transform_hits(pypi_hits)

        remote_version = None
        for hit in hits:
            if hit['name'] == pkg_name:
                remote_version = highest_version(hit['versions'])
                self.announce("Found %s version %s on PyPi" % (pkg_name, remote_version), log.INFO)
        if remote_version is None:
            raise RuntimeError("Could not found %s on PyPi" % pkg_name)
        if StrictVersion(VERSION) <= StrictVersion(remote_version):
            raise VersionError("Local version %s not greater than PyPi version %s" % (pkg_version, remote_version))
        self.announce("Local version %s higher than PyPi version" % pkg_version)
Beispiel #9
0
def search(terms):
    _ensure_search_logger()
    cmd = SearchCommand()
    args = terms
    options, query = cmd.parse_args(args)
    return cmd.search(query, options)