示例#1
0
 def test_get(self, get_mock):
     # Python 2.6....
     try:
         get("test")
     except HTTPError as e:
         self.assertEqual(300, e.status_code)
         self.assertEqual(e.status_code, e.errno)
         self.assertEqual(e.reason, e.message)
示例#2
0
 def test_get(self, get_mock):
     # Python 2.6....
     try:
         get("test")
     except HTTPError as e:
         self.assertEqual(300, e.status_code)
         self.assertEqual(e.status_code, e.errno)
         self.assertEqual(e.reason, e.message)
示例#3
0
def pypi_wheels_in(requirements, skip_packages):
    """
    Return a list of the entries in requirements (distributed as wheels).

    Where requirements is a list of strings formatted like "name==version".
    """
    print("Checking for wheel availability at PyPI.")
    wheels = []
    for requirement in requirements:
        name, _, version = requirement.partition("==")
        # Needed to detect the package being installed from source
        # <package> @ <path to package>==<version>
        name = name.split('@')[0].strip()
        if name in skip_packages:
            print("-", requirement, "skipped")
        else:
            print("-", requirement, end=" ")
            package = yarg.get(name)
            releases = package.release(version)
            if not releases:
                raise RuntimeError(
                    "ABORTING: Did not find {!r} at PyPI. "
                    "(bad meta-data?)".format(
                        requirement
                    )
                )
            if any(r.package_type == "wheel" for r in releases):
                wheels.append(requirement)
                feedback = "ok"
            else:
                feedback = "missing"
            print(feedback)
    return wheels
示例#4
0
文件: pypi.py 项目: brechtm/pynsist
    def fetch(self):
        p = self.check_cache()
        if p is not None:
            return p

        release_list = yarg.get(self.name).release(self.version)
        preferred_release = self.pick_best_wheel(release_list)
        if preferred_release is None:
            raise NoWheelError(
                'No compatible wheels found for {0.name} {0.version}'.format(
                    self))

        download_to = get_cache_dir() / 'pypi' / self.name / self.version
        try:
            download_to.mkdir(parents=True)
        except OSError as e:
            # Py2 compatible equivalent of FileExistsError
            if e.errno != errno.EEXIST:
                raise
        target = download_to / preferred_release.filename

        from . import __version__
        hasher = HashTracker(hashlib.md5())
        headers = {'user-agent': 'pynsist/' + __version__}
        logger.info('Downloading wheel: %s', preferred_release.url)
        download(preferred_release.url,
                 str(target),
                 headers=headers,
                 trackers=(hasher, ))
        if hasher.hashobj.hexdigest() != preferred_release.md5_digest:
            target.unlink()
            raise ValueError('Downloaded wheel corrupted: {}'.format(
                preferred_release.url))

        return target
示例#5
0
    def fetch(self):
        p = self.check_cache()
        if p is not None:
            return p

        release_list = yarg.get(self.name).release(self.version)
        preferred_release = self.pick_best_wheel(release_list)
        if preferred_release is None:
            raise NoWheelError('No compatible wheels found for {0.name} {0.version}'.format(self))

        download_to = get_cache_dir() / 'pypi' / self.name / self.version
        try:
            download_to.mkdir(parents=True)
        except OSError as e:
            # Py2 compatible equivalent of FileExistsError
            if e.errno != errno.EEXIST:
                raise
        target = download_to / preferred_release.filename

        from . import __version__
        hasher = HashTracker(hashlib.md5())
        headers = {'user-agent': 'pynsist/'+__version__}
        logger.info('Downloading wheel: %s', preferred_release.url)
        download(preferred_release.url, str(target), headers=headers,
                 trackers=(hasher,))
        if hasher.hashobj.hexdigest() != preferred_release.md5_digest:
            target.unlink()
            raise ValueError('Downloaded wheel corrupted: {}'.format(preferred_release.url))

        return target
示例#6
0
 def get_ordered_package_versions(package_name, pypi_server=None):
     # imported here so that it's only needed in packaging time
     import yarg
     yarg_kw = {}
     if pypi_server is not None:
         yarg_kw['pypi_server'] = pypi_server
     available_versions = yarg.get(package_name, **yarg_kw).release_ids
     return available_versions
示例#7
0
文件: main.py 项目: cllbck/reqcreate
def create_requirements_file(packages, dir):
    logging.info(f'Starting creating requirements.txt')
    file = os.path.join(dir, 'requirements.txt')
    try:
        with open(file, 'x') as f:
            for item in packages:
                package = yarg.get(item)
                f.write(f'{package.name}=={package.latest_release_id}\n')
                logging.info(f'File  requirements.txt is created')
    except FileExistsError:
        logging.error('File requirements.txt already exist')
示例#8
0
def get_imports_info(imports):
    result = []
    for item in imports:
        try:
            data = yarg.get(item)
        except HTTPError:
            logging.debug(
                'Package %s does not exist or network problems', item)
            continue
        result.append({'name': item, 'version': data.latest_release_id})
    return result
示例#9
0
def get_imports_info(imports):
    result = []
    for item in imports:
        try:
            data = yarg.get(item)
        except HTTPError:
            logging.debug('Package %s does not exist or network problems',
                          item)
            continue
        result.append({'name': item, 'version': data.latest_release_id})
    return result
示例#10
0
def get_imports_info(imports):
    result = []
    for item in imports:
        try:
            data = yarg.get(item)
        except HTTPError:
            logging.debug('Package does not exist or network problems')
            continue
        if not data or not data.release_ids:
            continue
        last_release = data.release_ids[-1]
        result.append({'name': item, 'version': last_release})
    return result
示例#11
0
def get_imports_info(imports):
    result = []
    for item in imports:
        try:
            data = yarg.get(item)
        except HTTPError:
            logging.debug('Package does not exist or network problems')
            continue
        if not data or not data.release_ids:
            continue
        last_release = data.release_ids[-1]
        result.append({'name': item, 'version': last_release})
    return result
示例#12
0
    def get_from_pypi(self):
        """Download a compatible wheel from PyPI.

        Downloads to the cache directory and returns the destination as a Path.
        Raises NoWheelError if no compatible wheel is found.
        """
        try:
            pypi_pkg = yarg.get(self.name)
        except yarg.HTTPError as e:
            if e.status_code == 404:
                raise NoWheelError("No package named {} found on PyPI".format(
                    self.name))
            raise

        release_list = pypi_pkg.release(self.version)
        if release_list is None:
            raise NoWheelError(
                "No release {0.version} for package {0.name}".format(self))

        preferred_release = self.pick_best_wheel(release_list)
        if preferred_release is None:
            raise NoWheelError(
                'No compatible wheels found for {0.name} {0.version}'.format(
                    self))

        download_to = get_cache_dir() / 'pypi' / self.name / self.version
        try:
            download_to.mkdir(parents=True)
        except OSError:
            # Ignore OSError only if the directory exists
            if not download_to.is_dir():
                raise
        target = download_to / preferred_release.filename

        from . import __version__
        hasher = HashTracker(hashlib.md5())
        headers = {'user-agent': 'pynsist/' + __version__}
        logger.info('Downloading wheel: %s', preferred_release.url)
        download(preferred_release.url,
                 str(target),
                 headers=headers,
                 trackers=(hasher, ))
        if hasher.hashobj.hexdigest() != preferred_release.md5_digest:
            target.unlink()
            raise ValueError('Downloaded wheel corrupted: {}'.format(
                preferred_release.url))

        return target
示例#13
0
def pypi_wheels_in(requirements):
    """
    Returns a list of the entries in requirements which are distributed as
    wheels in PyPI (where requirements is a list of strings formatted like
    "name==version").
    """
    print('Checking for wheel availability at PyPI.')
    wheels = []
    for requirement in requirements:
        name, _, version = requirement.partition('==')
        print('-', requirement, end=' ')
        package = yarg.get(name)
        releases = package.release(version)
        if any(r.package_type == 'wheel' for r in releases):
            wheels.append(requirement)
            feedback = 'ok'
        else:
            feedback = 'missing'
        print(feedback)
    return wheels
示例#14
0
    def get_package_versions_from_pypi(package):
        """
        Query PyPI for latest versions of package, return in order.

        return list: version info
        """

        try:
            yp = yarg.get(package)
            rels = yp.release_ids
        except Exception as e:
            maglog.debug("Unable to obtain {0} from PyPI; {1}."
                         .format(package, e))
            # log e
            return None

        rels = natsorted(rels)
        if not rels:
            maglog.info('No version info available for "{}" '
                        'at CheeseShop (PyPI)'.format(package))
            return None

        return rels
示例#15
0
    def get_package_versions_from_pypi(package):
        """
        Query PyPI for latest versions of package, return in order.

        return list: version info
        """

        try:
            yp = yarg.get(package)
            rels = yp.release_ids
        except Exception as e:
            maglog.debug("Unable to obtain {0} from PyPI; {1}."
                         .format(package, e))
            # log e
            return None

        rels = natsorted(rels)
        if not rels:
            maglog.info('No version info available for "{}" '
                        'at CheeseShop (PyPI)'.format(package))
            return None

        return rels
示例#16
0
def pypi_wheels_in(requirements):
    """
    Returns a list of the entries in requirements which are distributed as
    wheels in PyPI (where requirements is a list of strings formatted like
    "name==version").
    """
    print("Checking for wheel availability at PyPI.")
    wheels = []
    for requirement in requirements:
        name, _, version = requirement.partition("==")
        print("-", requirement, end=" ")
        package = yarg.get(name)
        releases = package.release(version)
        if not releases:
            raise RuntimeError(
                "ABORTING: Did not find {!r} at PyPI. (bad meta-data?)".format(
                    requirement))
        if any(r.package_type == "wheel" for r in releases):
            wheels.append(requirement)
            feedback = "ok"
        else:
            feedback = "missing"
        print(feedback)
    return wheels
示例#17
0
    return best

nsist.pypi.WheelDownloader.pick_best_wheel = pbw_patched

latest_python = 0
while requests.head("https://www.python.org/ftp/python/3.5.{0}/python-3.5.{0}-embed-win32.zip".format(latest_python + 1)).status_code == 200:
    latest_python += 1

latest_python = "3.5.{}".format(latest_python)

print("python version: {}".format(latest_python))

latest_commit = None

if "--stable" in sys.argv:
    releases = yarg.get("swood").latest_release
    version = releases[0].release_id
else:
    try:
        old_dir = os.getcwd()
        os.chdir("../..")
        latest_commit = subprocess.run(["git", "rev-parse", "--short=6", "HEAD", "-n=1"],
                                       stdout=subprocess.PIPE,
                                       check=True).stdout.decode("utf-8").rstrip("\n").rstrip("\r")
        branch_name = subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"],
                                     stdout=subprocess.PIPE,
                                     check=True).stdout.decode("utf-8").rstrip("\n").rstrip("\r")
        os.chdir(old_dir)
        version = "experimental ({}-{})".format(branch_name, latest_commit)
    except subprocess.CalledProcessError:
        version = "???"
示例#18
0
文件: pypi.py 项目: brechtm/pynsist
def find_pypi_release(requirement):
    if '==' in requirement:
        name, version = requirement.split('==', 1)
        return yarg.get(name).release(version)
    else:
        return yarg.get(requirement).latest_release
示例#19
0
 def test_end_slash(self, get_mock):
     get("test", pypi_server="https://mock.test.mock/test")
     self.assertEqual(call('https://mock.test.mock/test/test/json'),
                      get_mock.call_args)
示例#20
0
 def test_end_slash(self, get_mock):
     get("test", pypi_server="https://mock.test.mock/test")
     self.assertEqual(call('https://mock.test.mock/test/test/json'),
                      get_mock.call_args)
示例#21
0
def find_pypi_release(requirement):
    if '==' in requirement:
        name, version = requirement.split('==', 1)
        return yarg.get(name).release(version)
    else:
        return yarg.get(requirement).latest_release