def tagged_version(self): version = self.distribution.get_version() # egg_info may be called more than once for a distribution, # in which case the version string already contains all tags. if self.vtags and version.endswith(self.vtags): return safe_version(version) return safe_version(version + self.vtags)
def _parse_wheel_filename(basename, project_name=None, return_tags=False): components = basename.split('-') distname = components[0] if (project_name is not None and distname != _wheel_escape(project_name)): raise ValueError('File %s.whl does not match project name %s' % (basename, project_name)) if len(components) < 3 or not len(components[2]) >= 4: raise ValueError('Invalid wheel filename %s.whl' % basename) version = components[1] pytag = components[2] abitag = components[3] platformtag = components[4] if pytag == 'py2.py3': # special handling of the universal Python version tag: pyversion = '.'.join(str(x) for x in sys.version_info[:2]) elif pytag[:2] == 'py' and len(pytag) == 4: pyversion = '%s.%s' % (pytag[2], pytag[3]) elif pytag[:2] == 'cp': pyversion = '%s.%s' % (pytag[2], pytag[3]) else: raise ValueError('Invalid or unsupported Python version tag in ' 'filename %s.whl' % basename) if return_tags: tags = { 'python': pytag, 'abi': abitag, 'platform': platformtag, } return (distname, safe_version(version), pyversion, 'bdist_wheel', tags) else: return (distname, safe_version(version), pyversion, 'bdist_wheel')
def _parse_source_filename(basename, project_name=None, return_tags=True): distname, version = basename.rsplit('-', 1) distname = _wheel_escape(distname) if project_name is not None and _wheel_escape(project_name): raise ValueError('File %s does not match expected project name %s' % (basename, project_name)) if return_tags: return (distname, safe_version(version), '', 'sdist', {}) return (distname, safe_version(version), '', 'sdist')
def research_package(name, version=None): f = urlopen("https://pypi.python.org/pypi/{}/json".format(name)) reader = codecs.getreader("utf-8") pkg_data = json.load(reader(f)) f.close() d = {} d['name'] = pkg_data['info']['name'] d['homepage'] = pkg_data['info'].get('home_page', '') artefact = None if version: for pypi_version in pkg_data['releases']: if pkg_resources.safe_version(pypi_version) == version: for version_artefact in pkg_data['releases'][pypi_version]: if version_artefact['packagetype'] == 'sdist': artefact = version_artefact break if artefact is None: warnings.warn("Could not find an exact version match for " "{} version {}; using newest instead". format(name, version), PackageVersionNotFoundWarning) if artefact is None: # no version given or exact match not found for url in pkg_data['urls']: if url['packagetype'] == 'sdist': artefact = url break d['url'] = artefact['url'] f = urlopen(artefact['url']) d['checksum'] = sha256(f.read()).hexdigest() d['checksum_type'] = 'sha256' f.close() return d
def download_artifacts(index_url, folder, project_name, version=None, max_workers=4): if version is not None: version = safe_version(version) artifacts, found_versions = _parse_html(index_url, folder, project_name, version=version) if not artifacts: print('Could not find any matching artifact for project "%s" on %s' % (project_name, index_url)) if version is not None: print("Requested version: %s" % version) print("Available versions: %s" % ", ".join(sorted(found_versions))) return print('Found %d artifacts to download from %s' % (len(artifacts), index_url)) if not os.path.exists(folder): os.makedirs(folder) with ThreadPoolExecutor(max_workers=max_workers) as e: # Dispatch the file download in threads futures = [e.submit(download, url_, filepath) for url_, filepath in artifacts] for future in as_completed(futures): # We don't expect any returned results be we want to raise # an exception early in case if problem future.result()
def _parse_exe_filename(basename, project_name=None, return_tags=True): remainder, pythontag = basename.rsplit('-', 1) name_and_version, platform = remainder.rsplit('.', 1) distname, version = name_and_version.rsplit('-', 1) distname = _wheel_escape(distname) if project_name is not None and distname != _wheel_escape(project_name): raise ValueError('File %s.exe does not match project name %s' % (basename, project_name)) pyversion = pythontag[2:] if return_tags: tags = { 'python': pythontag.replace('.', ''), 'platform': _wheel_escape(platform), } return (distname, safe_version(version), pyversion, 'bdist_wininst', tags) return (distname, safe_version(version), pyversion, 'bdist_wininst')
def scan(link): # Process a URL to see if it's for a package page if link.startswith(self.index_url): parts = list(map(urllib.parse.unquote, link[len(self.index_url) :].split("/"))) if len(parts) == 2 and "#" not in parts[1]: # it's a package page, sanitize and index it pkg = safe_name(parts[0]) ver = safe_version(parts[1]) self.package_pages.setdefault(pkg.lower(), {})[link] = True return to_filename(pkg), to_filename(ver) return None, None
def get_package_info(self, dir, develop=False): python = self.python rc, lines = self.process.popen( '"%(python)s" setup.py --name --version' % locals(), echo=False) if rc == 0 and len(lines) == 2: name, version = lines if develop: parser = ConfigParser(warn) parser.read('setup.cfg') version += parser.get('egg_info', 'tag_build', '').strip() return name, pkg_resources.safe_version(version) err_exit('Bad setup.py')
def patch_missing_pkg_info(self, attrs): # Fake up a replacement for the data that would normally come from # PKG-INFO, but which might not yet be built if this is a fresh # checkout. # if not attrs or 'name' not in attrs or 'version' not in attrs: return key = pkg_resources.safe_name(str(attrs['name'])).lower() dist = pkg_resources.working_set.by_key.get(key) if dist is not None and not dist.has_metadata('PKG-INFO'): dist._version = pkg_resources.safe_version(str(attrs['version'])) self._patched_dist = dist
def scan(link): # Process a URL to see if it's for a package page if link.startswith(self.index_url): parts = list( map(urllib.parse.unquote, link[len(self.index_url):].split('/'))) if len(parts) == 2 and '#' not in parts[1]: # it's a package page, sanitize and index it pkg = safe_name(parts[0]) ver = safe_version(parts[1]) self.package_pages.setdefault(pkg.lower(), {})[link] = True return to_filename(pkg), to_filename(ver) return None, None
def _parse_exe_filename(basename, project_name=None, return_tags=True): remainder, pythontag = basename.rsplit('-', 1) if not pythontag.startswith('py'): # There was no python tag with this file, therefore it must be # python version independent pythontag = 'py' + '.'.join(str(x) for x in sys.version_info[:2]) remainder = basename name_and_version, platform = remainder.rsplit('.', 1) distname, version = name_and_version.rsplit('-', 1) distname = _wheel_escape(distname) if project_name is not None and distname != _wheel_escape(project_name): raise ValueError('File %s.exe does not match project name %s' % (basename, project_name)) pyversion = pythontag[2:] if return_tags: tags = { 'python': pythontag.replace('.', ''), 'platform': _wheel_escape(platform), } return (distname, safe_version(version), pyversion, 'bdist_wininst', tags) return (distname, safe_version(version), pyversion, 'bdist_wininst')
def egg_name(self): wheel = self.wheel name = pkg_resources.safe_name(wheel.name) version = pkg_resources.safe_version(wheel.version) pyver = 'py%d.%d' % sys.version_info[:2] bits = [pkg_resources.to_filename(name), pkg_resources.to_filename(version), pyver] if any(abi != 'none' or arch != 'any' for pyver, abi, arch in wheel.tags): # not pure python bits.append(pkg_resources.get_build_platform()) return '-'.join(bits) + '.egg'
def write_egg(project, version_info, egg_data, destdir='.'): """Write an egg file, formatting its name per the egg specifications.""" filename = '{0}-{1}-py{2[0]}.{2[1]}.egg'.format( pkg_resources.to_filename(pkg_resources.safe_name(project.name)), pkg_resources.to_filename(pkg_resources.safe_version(project.version)), version_info) f = open(os.path.join(destdir, filename), 'w') try: f.write(egg_data) finally: f.close() return filename
def matched_by_list(package, version, requirements): """ Verify whether the given version of the package is matched by the given requirements file. :param package: Name of the package to look for :param version: Version of the package to look for :param requirements: A list of requirements as read by read_raw() :return: True if the package can be used to fulfil on of the requirements in the file, False otherwise """ version = pkg_resources.safe_version('{}'.format(version)) package = pkg_resources.safe_name(package) matches = (package == requirement.project_name and version in requirement for requirement in requirements) return any(matches)
def tagged_version(self): using_hg_version = ( force_hg_version or getattr(self.distribution, 'use_hg_version', False) ) if force_hg_version: # disable patched `tagged_version` to avoid affecting # subsequent installs in the same interpreter instance. egg_info.tagged_version = orig_ver if using_hg_version: result = safe_version(self.distribution.get_version()) else: result = orig_ver(self) self.tag_build = result return result
def _parse_wheel_filename(basename, project_name=None, return_tags=False): components = basename.split('-') distname = components[0] if (project_name is not None and distname != _wheel_escape(project_name)): raise ValueError('File %s.whl does not match project name %s' % (basename, project_name)) if len(components) < 3 or not len(components[2]) >= 3: raise ValueError('Invalid wheel filename %s.whl' % basename) version = components[1] pytag = components[2] abitag = components[3] platformtag = components[4] if pytag == 'py2.py3': # special handling of the universal Python version tag: pyversion = '.'.join(str(x) for x in sys.version_info[:2]) elif pytag[:2] == 'py' and len(pytag) == 3: pyversion = '%s' % pytag[2] elif pytag[:2] in ['pp', 'py'] and len(pytag) == 4: pyversion = '%s.%s' % (pytag[2], pytag[3]) elif pytag[:2] == 'cp': pyversion = '%s.%s' % (pytag[2], pytag[3]) else: raise ValueError('Invalid or unsupported Python version tag in ' 'filename %s.whl' % basename) if return_tags: tags = { 'python': pytag, 'abi': abitag, 'platform': platformtag, } return (distname, safe_version(version), pyversion, 'bdist_wheel', tags) else: return (distname, safe_version(version), pyversion, 'bdist_wheel')
def extract_requirement(pkg_info): p_name = pkg_info.get('name', '') p_name = p_name.strip() p_name = pkg_resources.safe_name(p_name) if not p_name: raise ValueError("Pip requirement provided with an empty name") p_version = pkg_info.get('version') if p_version is not None: if isinstance(p_version, (int, float, long)): p_version = str(p_version) if isinstance(p_version, (str, basestring)): p_version = pkg_resources.safe_version(p_version) else: raise TypeError("Pip requirement version must be a string or numeric type") return pip_helper.Requirement(p_name, p_version)
def _scan(self, link): # Process a URL to see if it's for a package page NO_MATCH_SENTINEL = None, None if not link.startswith(self.index_url): return NO_MATCH_SENTINEL parts = list( map(urllib.parse.unquote, link[len(self.index_url):].split('/'))) if len(parts) != 2 or '#' in parts[1]: return NO_MATCH_SENTINEL # it's a package page, sanitize and index it pkg = safe_name(parts[0]) ver = safe_version(parts[1]) self.package_pages.setdefault(pkg.lower(), {})[link] = True return to_filename(pkg), to_filename(ver)
def extract_requirement(pkg_info): p_name = pkg_info.get('name', '') p_name = p_name.strip() p_name = pkg_resources.safe_name(p_name) if not p_name: raise ValueError("Pip requirement provided with an empty name") p_version = pkg_info.get('version') if p_version is not None: if isinstance(p_version, (int, float, long)): p_version = str(p_version) if isinstance(p_version, (str, basestring)): p_version = pkg_resources.safe_version(p_version) else: raise TypeError( "Pip requirement version must be a string or numeric type") return pip_helper.Requirement(p_name, p_version)
def matched_by_list(package, version, requirements): """ Verify whether the given version of the package is matched by the given requirements file. :param package: Name of the package to look for :param version: Version of the package to look for :param requirements: A list of requirements as read by read_raw() :return: True if the package can be used to fulfil on of the requirements in the file, False otherwise """ version = pkg_resources.safe_version('{}'.format(version)) package = pkg_resources.safe_name(package) matches = ( package == requirement.project_name and version in requirement for requirement in requirements ) return any(matches)
def update(self, instance, validated_data): for k in [ "display_name", "tagline", "short_description", "publish_date", "metadata", "labels", "docs", "links", "comments", ]: setattr(instance, k, validated_data.get(k, getattr(instance, k))) instance.version = str( safe_version(validated_data.get("version", instance.version))) instance.save()
def scan(link): # Process a URL to see if it's for a package page if link.startswith(self.index_url): parts = list(map( <<<<<<< HEAD unquote, link[len(self.index_url):].split('/') ======= urllib.parse.unquote, link[len(self.index_url):].split('/') >>>>>>> 54eef0be98b1b67c8507db91f4cfa90b64991027 )) if len(parts)==2 and '#' not in parts[1]: # it's a package page, sanitize and index it pkg = safe_name(parts[0]) ver = safe_version(parts[1]) self.package_pages.setdefault(pkg.lower(),{})[link] = True return to_filename(pkg), to_filename(ver) return None, None
def matched_by_file(package, version, filename): """ Verify whether the given version of the package is matched by the given requirements file. :param package: Name of the package to look for :param version: Version of the package to look for :param filename: Filename of the requirements-style file. :return: True if the package can be used to fulfil on of the requirements in the file, False otherwise """ version = pkg_resources.safe_version('{}'.format(version)) package = pkg_resources.safe_name(package) with open(filename) as input_file: parsed_requirements = list(pkg_resources.parse_requirements(input_file)) matches = [ package == requirement.project_name and version in requirement for requirement in parsed_requirements ] return any(matches)
def any_to_version(obj): """ Convert any python object to a version string. https://github.com/pypa/setuptools/blob/ba209a15247b9578d565b7491f88dc1142ba29e4/setuptools/config.py#L535 :param any obj: object to convert to version :rtype: str """ version = obj if not isinstance(version, str): if hasattr(version, "__iter__"): version = ".".join(map(str, version)) else: version = str(version) return pkg_resources.safe_version(version)
def research_package(name, version=None): with closing(urlopen("https://pypi.io/pypi/{}/json".format(name))) as f: reader = codecs.getreader("utf-8") pkg_data = json.load(reader(f)) d = {} d['name'] = pkg_data['info']['name'] d['homepage'] = pkg_data['info'].get('home_page', '') artefact = None if version: for pypi_version in pkg_data['releases']: if pkg_resources.safe_version(pypi_version) == version: for version_artefact in pkg_data['releases'][pypi_version]: if version_artefact['packagetype'] == 'sdist': artefact = version_artefact break if artefact is None: warnings.warn( "Could not find an exact version match for " "{} version {}; using newest instead".format(name, version), PackageVersionNotFoundWarning) if artefact is None: # no version given or exact match not found for url in pkg_data['urls']: if url['packagetype'] == 'sdist': artefact = url break if artefact: d['url'] = artefact['url'] if 'digests' in artefact and 'sha256' in artefact['digests']: logging.debug("Using provided checksum for %s", name) d['checksum'] = artefact['digests']['sha256'] else: logging.debug("Fetching sdist to compute checksum for %s", name) with closing(urlopen(artefact['url'])) as f: d['checksum'] = sha256(f.read()).hexdigest() logging.debug("Done fetching %s", name) else: # no sdist found d['url'] = '' d['checksum'] = '' warnings.warn("No sdist found for %s" % name) d['checksum_type'] = 'sha256' return d
def matched_by_file(package, version, filename): """ Verify whether the given version of the package is matched by the given requirements file. :param package: Name of the package to look for :param version: Version of the package to look for :param filename: Filename of the requirements-style file. :return: True if the package can be used to fulfil on of the requirements in the file, False otherwise """ version = pkg_resources.safe_version('{}'.format(version)) package = pkg_resources.safe_name(package) with open(filename) as input_file: parsed_requirements = list( pkg_resources.parse_requirements(input_file)) matches = [ package == requirement.project_name and version in requirement for requirement in parsed_requirements ] return any(matches)
def get_version(): import sys from datetime import datetime VERSION = '0.4.3.dev' if len(sys.argv) > 1 and sys.argv[1] == 'develop': # 'pip install -e' or 'python setup.py develop' print('Installing in develop mode') return '0.0.0.dev' version = version_from_pkginfo() is_dirty = git('status', '--porcelain') if version: # source distribution assert is_dirty is None return version exact_tag = git('describe', '--exact-match', '--tags', 'HEAD') describe = git('describe', '--tags', '--always', 'HEAD') if exact_tag: print('Working directory is a checkout of git tag {}...'.format( exact_tag)) assert exact_tag[0] == 'v' version = exact_tag[1:] assert (version.startswith(VERSION) if VERSION.endswith('.dev') else version == VERSION) elif describe: print('Working directory is a git checkout: {}...'.format(describe)) version = describe if describe[0] == 'v': version = version[1:].replace('-', '+', 1) else: print('Missing specific version information...') version = VERSION if is_dirty: print('Git checkout is dirty, adding timestamp to version string...') now = datetime.utcnow() sep = '-' if '+' in version else '+' version += '{}dirty{}'.format(sep, now.strftime('%Y%m%d%H%M%S')) return safe_version(version)
def get_local_dist_metadata_filepath(dist): # Dist filename syntax # name ["-" version ["-py" pyver ["-" required_platform]]] "." ext # https://setuptools.readthedocs.io/en/latest/formats.html#filename-embedded-metadata def valid_component(component): return component[1] # Stop taking filename components at the first missing/invalid component filename_component = takewhile(valid_component, ( ('', pkg_resources.to_filename(pkg_resources.safe_name( dist.project_name))), ('-', pkg_resources.to_filename(pkg_resources.safe_version(dist.version))), ('-py', dist.py_version), ('-', dist.platform), )) filename = ''.join(chain(*filename_component)) if isinstance(dist, pkg_resources.EggInfoDistribution): ext = 'egg-info' metadata_file = 'PKG-INFO' elif isinstance(dist, pkg_resources.DistInfoDistribution): ext = 'dist-info' metadata_file = 'METADATA' elif isinstance(dist, pkg_resources.Distribution): ext = os.path.join('egg', 'EGG-INFO') metadata_file = 'PKG-INFO' else: ext = None metadata_file = None filename = '{}.{}'.format(filename, ext) path = os.path.join(dist.location, filename, metadata_file) if ext: return path else: return None
def build(self, build_dir: str, **kwargs): if not os.path.exists(build_dir): os.makedirs(build_dir, exist_ok=True) context.io.echo("- Building {}...".format(context.io.cyan("sdist"))) version = to_filename(safe_version(self.meta.version)) target = os.path.join( build_dir, "{}-{}.tar.gz".format(self.meta.project_name, version)) tar = tarfile.open(target, mode="w:gz", format=tarfile.PAX_FORMAT) try: tar_dir = "{}-{}".format(self.meta.project_name, version) files_to_add = self.find_files_to_add(True) for relpath in files_to_add: tar.add( relpath, arcname=os.path.join(tar_dir, str(relpath)), recursive=False, ) context.io.echo(f" - Adding: {relpath}", verbosity=context.io.DETAIL) fd, temp_name = tempfile.mkstemp(prefix="pkg-info") pkg_info = self.format_pkginfo(False).encode("utf-8") with open(fd, "wb") as f: f.write(pkg_info) tar.add(temp_name, arcname=os.path.join(tar_dir, "PKG-INFO"), recursive=False) context.io.echo(" - Adding: PKG-INFO", verbosity=context.io.DETAIL) finally: tar.close() context.io.echo("- Built {}".format( context.io.cyan(os.path.basename(target)))) return target
def egg_filename(name, version): """ Returns name for egg file as generated by :mod:`setuptools`. name: string Must be alphanumeric. version: string Must be alphanumeric. """ assert name and isinstance(name, basestring) match = _EGG_NAME_RE.search(name) if match is None or match.group() != name: raise ValueError('Egg name must be alphanumeric') assert version and isinstance(version, basestring) match = _EGG_VERSION_RE.search(version) if match is None or match.group() != version: raise ValueError('Egg version must be alphanumeric') name = pkg_resources.to_filename(pkg_resources.safe_name(name)) version = pkg_resources.to_filename(pkg_resources.safe_version(version)) return '%s-%s-py%s.egg' % (name, version, sys.version[:3])
def run(self): metadata = self.distribution.metadata project_name = metadata.get_name() version = safe_version(metadata.get_version()) print("Collecting artifacts for %s==%s in 'dist' folder:" % (project_name, version)) dist_files = [] for filename in os.listdir('dist'): try: _, file_version, pyversion, command = parse_filename( filename, project_name=project_name) if file_version != version: continue except ValueError: continue filepath = os.path.join('dist', filename) dist_files.append((command, pyversion, filepath)) if not dist_files: raise DistutilsOptionError( "No file collected from the 'dist' folder") for command, pyversion, filepath in dist_files: self.upload_file(command, pyversion, filepath)
def tagged_version(self): return safe_version(self.distribution.get_version() + self.vtags)
Based on the original 'suds' project by Jeff Ortel (jortel at redhat dot com) hosted at 'https://fedorahosted.org/suds'. 'Suds' is a lightweight SOAP-based web service client for Python licensed under LGPL (see the LICENSE.txt file included in the distribution). This is hopefully just a temporary fork of the original suds Python library project created because the original project development seems to have stalled. Should be reintegrated back into the original project if it ever gets revived again. """ package_name = "suds-philpem" version_tag = pkg_resources.safe_version(__version__) project_url = "https://github.com/EnetModa/suds-philpem" base_download_url = project_url + "/releases" download_distribution_name = "%s-%s.zip" % (package_name, version_tag) download_url = "%s/%s" % (base_download_url, download_distribution_name) packages_excluded_from_build = [] # We generally do not want the tests package or any of its subpackages # included in our non-source package builds (source distribution content gets # specified separately via the MANIFEST.ini configuration file). Comment out # the following line to include the test code anyway, e.g. if you want to run # Python 3 based tests from the package build folder. packages_excluded_from_build += ["tests", "tests.*"] setup( name=package_name,
# source_encoding = 'utf-8-sig' # The master toctree document. master_doc = "index" # General information about the project. project = "StagPy" copyright = "2016, Adrien Morison, Martina Ulvrova, Stéphane Labrosse" author = "Adrien Morison, Martina Ulvrova, Stéphane Labrosse" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The full version, including alpha/beta/rc tags. release = safe_version(__version__) # The short X.Y version. version = ".".join(release.split(".")[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: # today = '' # Else, today_fmt is used as the format for a strftime call. # today_fmt = '%B %d, %Y'
def python_package_resource(name, version=None, url=None, reload_after_install=False, **kwargs): name = safe_name(name) if version: version = safe_version(version) if url: if not version: raise Exception( 'python package version not specified for <{}> with url <{}>'. format(name, url)) if version not in url: LOGGER.warn( 'please double check and ensure python package version is consistent with url: %(version)s, %(url)s', { 'version': version, 'url': url }) upgrading = is_upgrading() installed_version = get_python_package_installed_version(name) downloaded_version = get_downloaded_python_package_version(name, version) latest_version = get_resource_latest_version(to_resource_key(name)) if upgrading: may_update_resource_latest_version = VEIL_ENV.is_dev or VEIL_ENV.is_test if installed_version: if version: if version == installed_version: need_install = False need_download = False action = None else: need_install = True need_download = downloaded_version != version action = 'UPGRADE' else: need_install = None need_download = True action = 'UPGRADE' else: need_install = True need_download = not version or downloaded_version != version action = 'INSTALL' else: may_update_resource_latest_version = ( VEIL_ENV.is_dev or VEIL_ENV.is_test) and ( not latest_version or version and version != latest_version or not version and latest_version < installed_version) need_install = not installed_version or ( version or latest_version ) and (version or latest_version) != installed_version need_download = need_install and ( not downloaded_version or (version or latest_version) and (version or latest_version) != downloaded_version) if need_install: action = 'UPGRADE' if installed_version else 'INSTALL' else: action = None dry_run_result = get_dry_run_result() if dry_run_result is not None: if need_download and is_downloading_while_dry_run(): new_downloaded_version = download_python_package( name, version or (None if upgrading else latest_version), url=url, **kwargs) if new_downloaded_version != downloaded_version: LOGGER.debug( 'python package with new version downloaded: %(name)s, %(installed_version)s, %(latest_version)s, %(downloaded_version)s, %(new_downloaded_version)s, %(url)s', { 'name': name, 'installed_version': installed_version, 'latest_version': latest_version, 'downloaded_version': downloaded_version, 'new_downloaded_version': new_downloaded_version, 'url': url }) downloaded_version = new_downloaded_version if upgrading and action == 'UPGRADE' and installed_version == downloaded_version: action = None dry_run_result['python_package?{}'.format(name)] = action or '-' return if need_download: new_downloaded_version = download_python_package( name, version or (None if upgrading else latest_version), url=url, **kwargs) if new_downloaded_version != downloaded_version: LOGGER.debug( 'python package with new version downloaded: %(name)s, %(installed_version)s, %(latest_version)s, %(downloaded_version)s, %(new_downloaded_version)s, %(url)s', { 'name': name, 'installed_version': installed_version, 'latest_version': latest_version, 'downloaded_version': downloaded_version, 'new_downloaded_version': new_downloaded_version, 'url': url }) downloaded_version = new_downloaded_version if upgrading and need_install is None: need_install = installed_version != downloaded_version if need_install: if installed_version: LOGGER.info( 'upgrading python package: %(name)s, %(latest_version)s, %(installed_version)s, %(version_to_install)s', { 'name': name, 'latest_version': latest_version, 'installed_version': installed_version, 'version_to_install': downloaded_version }) else: LOGGER.info( 'installing python package: %(name)s, %(latest_version)s, %(version_to_install)s', { 'name': name, 'latest_version': latest_version, 'version_to_install': downloaded_version }) installed_version = install_python_package(name, downloaded_version, url=url, **kwargs) if reload_after_install: reload_python_package(name) if may_update_resource_latest_version and installed_version and installed_version != latest_version: set_resource_latest_version(to_resource_key(name), installed_version) LOGGER.info( 'updated python package resource latest version: %(name)s, %(latest_version)s, %(new_latest_version)s', { 'name': name, 'latest_version': latest_version, 'new_latest_version': installed_version })
def testSafeVersion(self): self.assertEqual(safe_version("1.2-1"), "1.2-1") self.assertEqual(safe_version("1.2 alpha"), "1.2.alpha") self.assertEqual(safe_version("2.3.4 20050521"), "2.3.4.20050521") self.assertEqual(safe_version("Money$$$Maker"), "Money-Maker") self.assertEqual(safe_version("peak.web"), "peak.web")
def raw_version(self): return safe_version(self._raw_version)
from os import path from pkg_resources import safe_version from setuptools import setup, find_packages version = {} with open( path.join(path.dirname(path.realpath(__file__)), 'jacquard', 'version.py')) as fp: exec(fp.read(), {}, version) version_string = safe_version(version['__version__']) setup(name='wsp-jacquard', version=version_string, description='JSON-based configuration handler for models', url='https://github.com/wsp-sag/wsp-jacquard', author='WSP', maintatiner='Brian Cheung', maintainer_email='*****@*****.**', classifiers=['License :: OSI Approved :: MIT License'], packages=find_packages(), install_requires=['six>=1.10'], python_requires='>=2.7')
def testSafeVersion(self): assert safe_version("1.2-1") == "1.2.post1" assert safe_version("1.2 alpha") == "1.2.alpha" assert safe_version("2.3.4 20050521") == "2.3.4.20050521" assert safe_version("Money$$$Maker") == "Money-Maker" assert safe_version("peak.web") == "peak.web"
class InfoCommon: tag_build = None tag_date = None @property def name(self): return safe_name(self.distribution.get_name()) def tagged_version(self): <<<<<<< HEAD version = self.distribution.get_version() # egg_info may be called more than once for a distribution, # in which case the version string already contains all tags. if self.vtags and version.endswith(self.vtags): return safe_version(version) return safe_version(version + self.vtags) ======= return safe_version(self._maybe_tag(self.distribution.get_version())) def _maybe_tag(self, version): """ egg_info may be called more than once for a distribution, in which case the version string already contains all tags. """ return ( version if self.vtags and version.endswith(self.vtags) else version + self.vtags ) >>>>>>> 7e5c5fbd6c824de4d4c2b62da3f7cae87d462119
def clean_version (self, ) : _v = self.cleaned_data.get("version") if pkg_resources.safe_version(_v, ) != _v : raise forms.ValidationError("version is not safe") return _v
def python_package_resource(name, version=None, url=None, reload_after_install=False, **kwargs): name = safe_name(name) if version: version = safe_version(version) if url: if not version: raise Exception('python package version not specified for <{}> with url <{}>'.format(name, url)) if version not in url: LOGGER.warn('please double check and ensure python package version is consistent with url: %(version)s, %(url)s', { 'version': version, 'url': url }) upgrading = is_upgrading() installed_version = get_python_package_installed_version(name) downloaded_version = get_downloaded_python_package_version(name, version) latest_version = get_resource_latest_version(to_resource_key(name)) if upgrading: may_update_resource_latest_version = VEIL_ENV.is_dev or VEIL_ENV.is_test if installed_version: if version: if version == installed_version: need_install = False need_download = False action = None else: need_install = True need_download = downloaded_version != version action = 'UPGRADE' else: need_install = None need_download = True action = 'UPGRADE' else: need_install = True need_download = not version or downloaded_version != version action = 'INSTALL' else: may_update_resource_latest_version = (VEIL_ENV.is_dev or VEIL_ENV.is_test) and (not latest_version or version and version != latest_version or not version and latest_version < installed_version) need_install = not installed_version or (version or latest_version) and (version or latest_version) != installed_version need_download = need_install and (not downloaded_version or (version or latest_version) and (version or latest_version) != downloaded_version) if need_install: action = 'UPGRADE' if installed_version else 'INSTALL' else: action = None dry_run_result = get_dry_run_result() if dry_run_result is not None: if need_download and is_downloading_while_dry_run(): new_downloaded_version = download_python_package(name, version or (None if upgrading else latest_version), url=url, **kwargs) if new_downloaded_version != downloaded_version: LOGGER.debug('python package with new version downloaded: %(name)s, %(installed_version)s, %(latest_version)s, %(downloaded_version)s, %(new_downloaded_version)s, %(url)s', { 'name': name, 'installed_version': installed_version, 'latest_version': latest_version, 'downloaded_version': downloaded_version, 'new_downloaded_version': new_downloaded_version, 'url': url }) downloaded_version = new_downloaded_version if upgrading and action == 'UPGRADE' and installed_version == downloaded_version: action = None dry_run_result['python_package?{}'.format(name)] = action or '-' return if need_download: new_downloaded_version = download_python_package(name, version or (None if upgrading else latest_version), url=url, **kwargs) if new_downloaded_version != downloaded_version: LOGGER.debug('python package with new version downloaded: %(name)s, %(installed_version)s, %(latest_version)s, %(downloaded_version)s, %(new_downloaded_version)s, %(url)s', { 'name': name, 'installed_version': installed_version, 'latest_version': latest_version, 'downloaded_version': downloaded_version, 'new_downloaded_version': new_downloaded_version, 'url': url }) downloaded_version = new_downloaded_version if upgrading and need_install is None: need_install = installed_version != downloaded_version if need_install: if installed_version: LOGGER.info('upgrading python package: %(name)s, %(latest_version)s, %(installed_version)s, %(version_to_install)s', { 'name': name, 'latest_version': latest_version, 'installed_version': installed_version, 'version_to_install': downloaded_version }) else: LOGGER.info('installing python package: %(name)s, %(latest_version)s, %(version_to_install)s', { 'name': name, 'latest_version': latest_version, 'version_to_install': downloaded_version }) installed_version = install_python_package(name, downloaded_version, url=url, **kwargs) if reload_after_install: reload_python_package(name) if may_update_resource_latest_version and installed_version and installed_version != latest_version: set_resource_latest_version(to_resource_key(name), installed_version) LOGGER.info('updated python package resource latest version: %(name)s, %(latest_version)s, %(new_latest_version)s', { 'name': name, 'latest_version': latest_version, 'new_latest_version': installed_version })
''' Created on Oct 6, 2011 @author: Mudassar Ali ''' from setuptools import setup, find_packages import pkg_resources from pkg_resources import require, DistributionNotFound, VersionConflict import sys version = pkg_resources.safe_version("0.1") #try: # require('ConflictingDistribution') # # print 'You have ConflictingDistribution installed.' # print 'You need to remove ConflictingDistribution from your site-packages' # print 'before installing this software, or conflicts may result.' # sys.exit() # #except (DistributionNotFound, VersionConflict): # pass setup(name='Custom-etl', version=version, #namespace_packages=['company'], install_requires=["MySQL-python",
def normalize_version(version): return safe_version(version)
def dist_info_name(self) -> str: name = to_filename(self.meta.project_name) version = to_filename(safe_version(self.meta.version)) return f"{name}-{version}.dist-info"
def write(name, version, doc, entry_map, src_files, distributions, modules, dst_dir, logger, observer=None, compress=True): """ Write egg in the manner of :mod:`setuptools`, with some differences: - Writes directly to the zip file, avoiding some intermediate copies. - Doesn't compile any Python modules. name: string Must be an alphanumeric string. version: string Must be an alphanumeric string. doc: string Used for the `Summary` and `Description` entries in the egg's metadata. entry_map: dict A :mod:`pkg_resources` :class:`EntryPoint` map: a dictionary mapping group names to dictionaries mapping entry point names to :class:`EntryPoint` objects. src_files: list List of non-Python files to include. distributions: list List of Distributions this egg depends on. It is used for the `Requires` entry in the egg's metadata. modules: list List of module names not found in a distribution that this egg depends on. It is used for the `Requires` entry in the egg's metadata and is also recorded in the 'openmdao_orphans.txt' resource. dst_dir: string The directory to write the egg to. logger: Logger Used for recording progress, etc. observer: callable Will be called via an :class:`EggObserver` intermediary. Returns the egg's filename. """ observer = eggobserver.EggObserver(observer, logger) egg_name = egg_filename(name, version) egg_path = os.path.join(dst_dir, egg_name) distributions = sorted(distributions, key=lambda dist: dist.project_name) modules = sorted(modules) sources = [] files = [] size = 0 # Approximate (uncompressed) size. Used to set allowZip64 flag. # Collect src_files. for path in src_files: path = os.path.join(name, path) files.append(path) size += os.path.getsize(path) # Collect Python modules. for dirpath, dirnames, filenames in os.walk('.', followlinks=True): dirs = copy.copy(dirnames) for path in dirs: if not os.path.exists(os.path.join(dirpath, path, '__init__.py')): dirnames.remove(path) for path in filenames: if path.endswith('.py'): path = os.path.join(dirpath[2:], path) # Skip leading './' files.append(path) size += os.path.getsize(path) sources.append(path) # Package info -> EGG-INFO/PKG-INFO pkg_info = [] pkg_info.append('Metadata-Version: 1.1') pkg_info.append('Name: %s' % pkg_resources.safe_name(name)) pkg_info.append('Version: %s' % pkg_resources.safe_version(version)) pkg_info.append('Summary: %s' % doc.strip().split('\n')[0]) pkg_info.append('Description: %s' % doc.strip()) pkg_info.append('Author-email: UNKNOWN') pkg_info.append('License: UNKNOWN') pkg_info.append('Platform: UNKNOWN') for dist in distributions: pkg_info.append('Requires: %s (%s)' % (dist.project_name, dist.version)) for module in modules: pkg_info.append('Requires: %s' % module) pkg_info = '\n'.join(pkg_info) + '\n' sources.append(name + '.egg-info/PKG-INFO') size += len(pkg_info) # Dependency links -> EGG-INFO/dependency_links.txt dependency_links = '\n' sources.append(name + '.egg-info/dependency_links.txt') size += len(dependency_links) # Entry points -> EGG-INFO/entry_points.txt entry_points = [] for entry_group in sorted(entry_map.keys()): entry_points.append('[%s]' % entry_group) for entry_name in sorted(entry_map[entry_group].keys()): entry_points.append('%s' % entry_map[entry_group][entry_name]) entry_points.append('') entry_points = '\n'.join(entry_points) + '\n' sources.append(name + '.egg-info/entry_points.txt') size += len(entry_points) # Unsafe -> EGG-INFO/not-zip-safe not_zip_safe = '\n' sources.append(name + '.egg-info/not-zip-safe') size += len(not_zip_safe) # Requirements -> EGG-INFO/requires.txt requirements = [str(dist.as_requirement()) for dist in distributions] requirements = '\n'.join(requirements) + '\n' sources.append(name + '.egg-info/requires.txt') size += len(requirements) # Modules not part of a distribution -> EGG-INFO/openmdao_orphans.txt orphans = '\n'.join(modules) + '\n' sources.append(name + '.egg-info/openmdao_orphans.txt') size += len(orphans) # Top-level names -> EGG-INFO/top_level.txt top_level = '%s\n' % name sources.append(name + '.egg-info/top_level.txt') size += len(top_level) # Manifest -> EGG-INFO/SOURCES.txt sources.append(name + '.egg-info/SOURCES.txt') sources = '\n'.join(sorted(sources)) + '\n' size += len(sources) # Open zipfile. logger.debug('Creating %s', egg_path) zip64 = size > zipfile.ZIP64_LIMIT compression = zipfile.ZIP_DEFLATED if compress else zipfile.ZIP_STORED egg = zipfile.ZipFile(egg_path, 'w', compression, zip64) stats = { 'completed_files': 0., 'total_files': float(8 + len(files)), 'completed_bytes': 0., 'total_bytes': float(size) } # Write egg info. _write_info(egg, 'PKG-INFO', pkg_info, observer, stats) _write_info(egg, 'dependency_links.txt', dependency_links, observer, stats) _write_info(egg, 'entry_points.txt', entry_points, observer, stats) _write_info(egg, 'not-zip-safe', not_zip_safe, observer, stats) _write_info(egg, 'requires.txt', requirements, observer, stats) _write_info(egg, 'openmdao_orphans.txt', orphans, observer, stats) _write_info(egg, 'top_level.txt', top_level, observer, stats) _write_info(egg, 'SOURCES.txt', sources, observer, stats) # Write collected files. for path in sorted(files): _write_file(egg, path, observer, stats) observer.complete(egg_name) egg.close() if os.path.getsize(egg_path) > zipfile.ZIP64_LIMIT: logger.warning('Egg zipfile requires Zip64 support to unzip.') return egg_name
def wheel_filename(self) -> str: name = to_filename(self.meta.project_name) version = to_filename(safe_version(self.meta.version)) return f"{name}-{version}-{self.tag}.whl"
def write(name, version, doc, entry_map, src_files, distributions, modules, dst_dir, logger, observer=None, compress=True): """ Write egg in the manner of :mod:`setuptools`, with some differences: - Writes directly to the zip file, avoiding some intermediate copies. - Doesn't compile any Python modules. name: string Must be an alphanumeric string. version: string Must be an alphanumeric string. doc: string Used for the `Summary` and `Description` entries in the egg's metadata. entry_map: dict A :mod:`pkg_resources` :class:`EntryPoint` map: a dictionary mapping group names to dictionaries mapping entry point names to :class:`EntryPoint` objects. src_files: list List of non-Python files to include. distributions: list List of Distributions this egg depends on. It is used for the `Requires` entry in the egg's metadata. modules: list List of module names not found in a distribution that this egg depends on. It is used for the `Requires` entry in the egg's metadata and is also recorded in the 'openmdao_orphans.txt' resource. dst_dir: string The directory to write the egg to. logger: Logger Used for recording progress, etc. observer: callable Will be called via an :class:`EggObserver` intermediary. Returns the egg's filename. """ observer = eggobserver.EggObserver(observer, logger) egg_name = egg_filename(name, version) egg_path = os.path.join(dst_dir, egg_name) distributions = sorted(distributions, key=lambda dist: dist.project_name) modules = sorted(modules) sources = [] files = [] size = 0 # Approximate (uncompressed) size. Used to set allowZip64 flag. # Collect src_files. for path in src_files: path = os.path.join(name, path) files.append(path) size += os.path.getsize(path) # Collect Python modules. for dirpath, dirnames, filenames in os.walk('.', followlinks=True): dirs = copy.copy(dirnames) for path in dirs: if not os.path.exists(os.path.join(dirpath, path, '__init__.py')): dirnames.remove(path) for path in filenames: if path.endswith('.py'): path = os.path.join(dirpath[2:], path) # Skip leading './' # No reason for a file to appear twice in our file list. if path not in files: files.append(path) size += os.path.getsize(path) sources.append(path) # Package info -> EGG-INFO/PKG-INFO pkg_info = [] pkg_info.append('Metadata-Version: 1.1') pkg_info.append('Name: %s' % pkg_resources.safe_name(name)) pkg_info.append('Version: %s' % pkg_resources.safe_version(version)) pkg_info.append('Summary: %s' % doc.strip().split('\n')[0]) pkg_info.append('Description: %s' % doc.strip()) pkg_info.append('Author-email: UNKNOWN') pkg_info.append('License: UNKNOWN') pkg_info.append('Platform: UNKNOWN') for dist in distributions: pkg_info.append('Requires: %s (%s)' % (dist.project_name, dist.version)) for module in modules: pkg_info.append('Requires: %s' % module) pkg_info = '\n'.join(pkg_info)+'\n' sources.append(name+'.egg-info/PKG-INFO') size += len(pkg_info) # Dependency links -> EGG-INFO/dependency_links.txt dependency_links = '\n' sources.append(name+'.egg-info/dependency_links.txt') size += len(dependency_links) # Entry points -> EGG-INFO/entry_points.txt entry_points = [] for entry_group in sorted(entry_map.keys()): entry_points.append('[%s]' % entry_group) for entry_name in sorted(entry_map[entry_group].keys()): entry_points.append('%s' % entry_map[entry_group][entry_name]) entry_points.append('') entry_points = '\n'.join(entry_points)+'\n' sources.append(name+'.egg-info/entry_points.txt') size += len(entry_points) # Unsafe -> EGG-INFO/not-zip-safe not_zip_safe = '\n' sources.append(name+'.egg-info/not-zip-safe') size += len(not_zip_safe) # Requirements -> EGG-INFO/requires.txt requirements = [str(dist.as_requirement()) for dist in distributions] requirements = '\n'.join(requirements)+'\n' sources.append(name+'.egg-info/requires.txt') size += len(requirements) # Modules not part of a distribution -> EGG-INFO/openmdao_orphans.txt orphans = '\n'.join(modules)+'\n' sources.append(name+'.egg-info/openmdao_orphans.txt') size += len(orphans) # Top-level names -> EGG-INFO/top_level.txt top_level = '%s\n' % name sources.append(name+'.egg-info/top_level.txt') size += len(top_level) # Manifest -> EGG-INFO/SOURCES.txt sources.append(name+'.egg-info/SOURCES.txt') sources = '\n'.join(sorted(sources))+'\n' size += len(sources) # Open zipfile. logger.debug('Creating %s', egg_path) zip64 = size > zipfile.ZIP64_LIMIT compression = zipfile.ZIP_DEFLATED if compress else zipfile.ZIP_STORED egg = zipfile.ZipFile(egg_path, 'w', compression, zip64) stats = {'completed_files': 0., 'total_files': float(8+len(files)), 'completed_bytes': 0., 'total_bytes': float(size)} # Write egg info. _write_info(egg, 'PKG-INFO', pkg_info, observer, stats) _write_info(egg, 'dependency_links.txt', dependency_links, observer, stats) _write_info(egg, 'entry_points.txt', entry_points, observer, stats) _write_info(egg, 'not-zip-safe', not_zip_safe, observer, stats) _write_info(egg, 'requires.txt', requirements, observer, stats) _write_info(egg, 'openmdao_orphans.txt', orphans, observer, stats) _write_info(egg, 'top_level.txt', top_level, observer, stats) _write_info(egg, 'SOURCES.txt', sources, observer, stats) # Write collected files. for path in sorted(files): _write_file(egg, path, observer, stats) observer.complete(egg_name) egg.close() if os.path.getsize(egg_path) > zipfile.ZIP64_LIMIT: logger.warning('Egg zipfile requires Zip64 support to unzip.') return egg_name
def tagged_version(self): return safe_version(self._maybe_tag(self.distribution.get_version()))
Based on the original 'suds' project by Jeff Ortel (jortel at redhat dot com) hosted at 'https://fedorahosted.org/suds'. 'Suds' is a lightweight SOAP-based web service client for Python licensed under LGPL (see the LICENSE.txt file included in the distribution). This is hopefully just a temporary fork of the original suds Python library project created because the original project development seems to have stalled. Should be reintegrated back into the original project if it ever gets revived again. """ package_name = "suds" version_tag = pkg_resources.safe_version(__version__) project_url = "https://bitbucket.org/philpem/suds" base_download_url = project_url + "/downloads" download_distribution_name = "%s-%s.tar.bz2" % (package_name, version_tag) download_url = "%s/%s" % (base_download_url, download_distribution_name) packages_excluded_from_build = [] # We generally do not want the tests package or any of its subpackages # included in our non-source package builds (source distribution content gets # specified separately via the MANIFEST.ini configuration file). Comment out # the following line to include the test code anyway, e.g. if you want to run # Python 3 based tests from the package build folder. packages_excluded_from_build += ["tests", "tests.*"] setup( name=package_name,