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)
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
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
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
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
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')
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
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
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
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
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
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
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
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 = "???"
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
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)