Python pkg_resources.get_distribution() Examples
The following are 30
code examples of pkg_resources.get_distribution().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pkg_resources
, or try the search function
.

Example #1
Source Project: thingsboard-gateway Author: thingsboard File: tb_utility.py License: Apache License 2.0 | 6 votes |
def install_package(package, version="upgrade"): from sys import executable from subprocess import check_call result = False if version.lower() == "upgrade": result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "--user"]) else: from pkg_resources import get_distribution current_package_version = None try: current_package_version = get_distribution(package) except Exception: pass if current_package_version is None or current_package_version != version: installation_sign = "==" if ">=" not in version else "" result = check_call([executable, "-m", "pip", "install", package + installation_sign + version, "--user"]) return result
Example #2
Source Project: discord.py Author: Rapptz File: __main__.py License: MIT License | 6 votes |
def show_version(): entries = [] entries.append('- Python v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(sys.version_info)) version_info = discord.version_info entries.append('- discord.py v{0.major}.{0.minor}.{0.micro}-{0.releaselevel}'.format(version_info)) if version_info.releaselevel != 'final': pkg = pkg_resources.get_distribution('discord.py') if pkg: entries.append(' - discord.py pkg_resources: v{0}'.format(pkg.version)) entries.append('- aiohttp v{0.__version__}'.format(aiohttp)) entries.append('- websockets v{0.__version__}'.format(websockets)) uname = platform.uname() entries.append('- system info: {0.system} {0.release} {0.version}'.format(uname)) print('\n'.join(entries))
Example #3
Source Project: apio Author: FPGAwars File: upgrade.py License: GNU General Public License v2.0 | 6 votes |
def cli(ctx): """Check the latest Apio version.""" current_version = get_distribution('apio').version latest_version = get_pypi_latest_version() if latest_version is None: ctx.exit(1) if latest_version == current_version: click.secho('You\'re up-to-date!\nApio {} is currently the ' 'newest version available.'.format(latest_version), fg='green') else: click.secho('You\'re not updated\nPlease execute ' '`pip install -U apio` to upgrade.', fg="yellow")
Example #4
Source Project: jbox Author: jpush File: __init__.py License: MIT License | 6 votes |
def install_scripts(distributions): """ Regenerate the entry_points console_scripts for the named distribution. """ try: from setuptools.command import easy_install import pkg_resources except ImportError: raise RuntimeError("'wheel install_scripts' needs setuptools.") for dist in distributions: pkg_resources_dist = pkg_resources.get_distribution(dist) install = wheel.paths.get_install_command(dist) command = easy_install.easy_install(install.distribution) command.args = ['wheel'] # dummy argument command.finalize_options() command.install_egg_scripts(pkg_resources_dist)
Example #5
Source Project: sawtooth-core Author: hyperledger File: main.py License: Apache License 2.0 | 6 votes |
def create_parent_parser(prog_name): parent_parser = argparse.ArgumentParser(prog=prog_name, add_help=False) parent_parser.add_argument( '-v', '--verbose', action='count', help='enable more verbose output') try: version = pkg_resources.get_distribution(DISTRIBUTION_NAME).version except pkg_resources.DistributionNotFound: version = 'UNKNOWN' parent_parser.add_argument( '-V', '--version', action='version', version=(DISTRIBUTION_NAME + ' (Hyperledger Sawtooth) version {}') .format(version), help='display version information') return parent_parser
Example #6
Source Project: sawtooth-core Author: hyperledger File: sawset.py License: Apache License 2.0 | 6 votes |
def create_parent_parser(prog_name): parent_parser = argparse.ArgumentParser(prog=prog_name, add_help=False) parent_parser.add_argument( '-v', '--verbose', action='count', help='enable more verbose output') try: version = pkg_resources.get_distribution(DISTRIBUTION_NAME).version except pkg_resources.DistributionNotFound: version = 'UNKNOWN' parent_parser.add_argument( '-V', '--version', action='version', version=(DISTRIBUTION_NAME + ' (Hyperledger Sawtooth) version {}') .format(version), help='display version information') return parent_parser
Example #7
Source Project: sawtooth-core Author: hyperledger File: sawnet.py License: Apache License 2.0 | 6 votes |
def create_parent_parser(prog_name): parent_parser = argparse.ArgumentParser(prog=prog_name, add_help=False) parent_parser.add_argument( '-v', '--verbose', action='count', help='enable more verbose output') try: version = pkg_resources.get_distribution(DISTRIBUTION_NAME).version except pkg_resources.DistributionNotFound: version = 'UNKNOWN' parent_parser.add_argument( '-V', '--version', action='version', version=(DISTRIBUTION_NAME + ' (Hyperledger Sawtooth) version {}') .format(version), help='display version information') return parent_parser
Example #8
Source Project: sawtooth-core Author: hyperledger File: sawadm.py License: Apache License 2.0 | 6 votes |
def create_parent_parser(prog_name): parent_parser = argparse.ArgumentParser(prog=prog_name, add_help=False) parent_parser.add_argument( '-v', '--verbose', action='count', help='enable more verbose output') try: version = pkg_resources.get_distribution(DISTRIBUTION_NAME).version except pkg_resources.DistributionNotFound: version = 'UNKNOWN' parent_parser.add_argument( '-V', '--version', action='version', version=(DISTRIBUTION_NAME + ' (Hyperledger Sawtooth) version {}') .format(version), help='display version information') return parent_parser
Example #9
Source Project: auto-alt-text-lambda-api Author: abhisuri97 File: __init__.py License: MIT License | 6 votes |
def install_scripts(distributions): """ Regenerate the entry_points console_scripts for the named distribution. """ try: from setuptools.command import easy_install import pkg_resources except ImportError: raise RuntimeError("'wheel install_scripts' needs setuptools.") for dist in distributions: pkg_resources_dist = pkg_resources.get_distribution(dist) install = get_install_command(dist) command = easy_install.easy_install(install.distribution) command.args = ['wheel'] # dummy argument command.finalize_options() command.install_egg_scripts(pkg_resources_dist)
Example #10
Source Project: auto-alt-text-lambda-api Author: abhisuri97 File: main.py License: MIT License | 6 votes |
def _get_info(name): metadata = _get_metadata(name) version = pkg_resources.get_distribution(name).version if metadata: if metadata['is_release']: released = 'released' else: released = 'pre-release' sha = metadata['git_version'] else: version_parts = version.split('.') if version_parts[-1].startswith('g'): sha = version_parts[-1][1:] released = 'pre-release' else: sha = "" released = "released" for part in version_parts: if not part.isdigit(): released = "pre-release" return dict(name=name, version=version, sha=sha, released=released)
Example #11
Source Project: kobo-predict Author: awemulya File: __init__.py License: BSD 2-Clause "Simplified" License | 6 votes |
def install_scripts(distributions): """ Regenerate the entry_points console_scripts for the named distribution. """ try: from setuptools.command import easy_install import pkg_resources except ImportError: raise RuntimeError("'wheel install_scripts' needs setuptools.") for dist in distributions: pkg_resources_dist = pkg_resources.get_distribution(dist) install = wheel.paths.get_install_command(dist) command = easy_install.easy_install(install.distribution) command.args = ['wheel'] # dummy argument command.finalize_options() command.install_egg_scripts(pkg_resources_dist)
Example #12
Source Project: target-csv Author: singer-io File: target_csv.py License: GNU Affero General Public License v3.0 | 6 votes |
def send_usage_stats(): try: version = pkg_resources.get_distribution('target-csv').version conn = http.client.HTTPConnection('collector.singer.io', timeout=10) conn.connect() params = { 'e': 'se', 'aid': 'singer', 'se_ca': 'target-csv', 'se_ac': 'open', 'se_la': version, } conn.request('GET', '/i?' + urllib.parse.urlencode(params)) response = conn.getresponse() conn.close() except: logger.debug('Collection request failed')
Example #13
Source Project: models Author: IntelAI File: mlperf_helper.py License: Apache License 2.0 | 6 votes |
def get_mlperf_log(): """Shielded import of mlperf_log module.""" try: import mlperf_compliance def test_mlperf_log_pip_version(): """Check that mlperf_compliance is up to date.""" import pkg_resources version = pkg_resources.get_distribution("mlperf_compliance") version = tuple(int(i) for i in version.version.split(".")) if version < _MIN_VERSION: tf.compat.v1.logging.warning( "mlperf_compliance is version {}, must be >= {}".format( ".".join([str(i) for i in version]), ".".join([str(i) for i in _MIN_VERSION]))) raise ImportError return mlperf_compliance.mlperf_log mlperf_log = test_mlperf_log_pip_version() except ImportError: mlperf_log = None return mlperf_log
Example #14
Source Project: godot-gdscript-toolkit Author: Scony File: __main__.py License: MIT License | 6 votes |
def main(): arguments = docopt( __doc__, version="gdparse {}".format( pkg_resources.get_distribution("gdtoolkit").version ), ) if not isinstance(arguments, dict): print(arguments) sys.exit(0) for file_path in arguments["<file>"]: with open(file_path, "r") as fh: # TODO: handle exception content = fh.read() tree = parser.parse(content) # TODO: handle exception if arguments["--pretty"]: print(tree.pretty()) elif arguments["--verbose"]: print(tree)
Example #15
Source Project: reprexpy Author: crew102 File: session_info.py License: MIT License | 6 votes |
def _get_version_info(self, modname, all_dist_info): try: dist_info = pkg_resources.get_distribution(modname) return dist_info.project_name, dist_info.version except pkg_resources.DistributionNotFound: ml = modname.split('.') if len(ml) > 1: modname = '.'.join(ml[:-1]) return self._get_version_info(modname, all_dist_info) else: tmod = modname.split('.')[0] x = [ (i['project_name'], i['version']) for i in all_dist_info if tmod in i['mods'] ] if x: return x[0] else: return _, _
Example #16
Source Project: Safejumper-for-Desktop Author: proxysh File: __init__.py License: GNU General Public License v2.0 | 6 votes |
def install_scripts(distributions): """ Regenerate the entry_points console_scripts for the named distribution. """ try: from setuptools.command import easy_install import pkg_resources except ImportError: raise RuntimeError("'wheel install_scripts' needs setuptools.") for dist in distributions: pkg_resources_dist = pkg_resources.get_distribution(dist) install = wheel.paths.get_install_command(dist) command = easy_install.easy_install(install.distribution) command.args = ['wheel'] # dummy argument command.finalize_options() command.install_egg_scripts(pkg_resources_dist)
Example #17
Source Project: Gurux.DLMS.Python Author: Gurux File: main.py License: GNU General Public License v2.0 | 5 votes |
def __init__(self, args): try: print("gurux_dlms version: " + pkg_resources.get_distribution("gurux_dlms").version) print("gurux_net version: " + pkg_resources.get_distribution("gurux_net").version) print("gurux_serial version: " + pkg_resources.get_distribution("gurux_serial").version) except Exception: #It's OK if this fails. print("pkg_resources not found") settings = GXSettings() ret = settings.getParameters(args) if ret != 0: return #There might be several notify messages in GBT. self.notify = GXReplyData() self.client = settings.client self.translator = GXDLMSTranslator() self.reply = GXByteBuffer() settings.media.trace = settings.trace print(settings.media) #Start to listen events from the media. settings.media.addListener(self) #Set EOP for the media. if settings.client.interfaceType == InterfaceType.HDLC: settings.media.eop = 0x7e try: print("Press any key to close the application.") #Open the connection. settings.media.open() #Wait input. input() print("Closing") except (KeyboardInterrupt, SystemExit, Exception) as ex: print(ex) settings.media.close() settings.media.removeListener(self)
Example #18
Source Project: Paradrop Author: ParadropLabs File: system_info.py License: Apache License 2.0 | 5 votes |
def getPackageVersion(name): """ Get a python package version. Returns: a string or None """ try: pkg = pkg_resources.get_distribution(name) return pkg.version except: return None
Example #19
Source Project: jupyterlab_code_formatter Author: ryantam626 File: handlers.py License: MIT License | 5 votes |
def check_plugin_version(handler: APIHandler): server_extension_version = pkg_resources.get_distribution( "jupyterlab_code_formatter" ).version lab_extension_version = handler.request.headers.get("Plugin-Version") version_matches = server_extension_version == lab_extension_version if not version_matches: handler.set_status( 422, f"Mismatched versions of server extension ({server_extension_version}) " f"and lab extension ({lab_extension_version}). " f"Please ensure they are the same.", ) handler.finish() return version_matches
Example #20
Source Project: jupyterlab_code_formatter Author: ryantam626 File: handlers.py License: MIT License | 5 votes |
def get(self) -> None: """Show what version is this server plguin on.""" self.finish( json.dumps( { "version": pkg_resources.get_distribution( "jupyterlab_code_formatter" ).version } ) )
Example #21
Source Project: jupyterlab_code_formatter Author: ryantam626 File: test_handlers.py License: MIT License | 5 votes |
def _create_headers( self, plugin_version: t.Optional[str] = None ) -> t.Dict[str, str]: return { "Plugin-Version": plugin_version if plugin_version is not None else pkg_resources.get_distribution("jupyterlab_code_formatter").version }
Example #22
Source Project: JJMumbleBot Author: DuckBoss File: auto_updater_helper.py License: GNU General Public License v3.0 | 5 votes |
def update_available(package_name): packages = [dist.project_name for dist in pkg_resources.working_set] if package_name not in packages: dprint(f"The package: [{package_name}] is not a dependency of this software.", origin=L_DEPENDENCIES) return None vers = check_pypi_version(package_name) if vers is not None: dprint(f"{package_name} available: {vers}", origin=L_DEPENDENCIES) dprint(f"{package_name} current: {pkg_resources.get_distribution(package_name).version}", origin=L_DEPENDENCIES) if vers != pkg_resources.get_distribution(package_name).version: dprint(f"There is a newer version of: [{package_name}({vers})] available.", origin=L_DEPENDENCIES) return True return False
Example #23
Source Project: JJMumbleBot Author: DuckBoss File: auto_updater_helper.py License: GNU General Public License v3.0 | 5 votes |
def check_and_update(package_name, pip_cmd): vers = check_pypi_version(package_name) if vers != pkg_resources.get_distribution(package_name).version: dprint(f"There is a newer version of: [{package_name}({vers})] available. Updating...", origin=L_DEPENDENCIES) if update_package(package_name, pip_cmd): return vers return None
Example #24
Source Project: apsconnect-cli Author: cloudblue File: apsconnect.py License: Apache License 2.0 | 5 votes |
def get_version(): try: return pkg_resources.get_distribution('apsconnectcli').version except pkg_resources.DistributionNotFound: return bin_version()
Example #25
Source Project: lavatory Author: gogoair File: __main__.py License: Apache License 2.0 | 5 votes |
def version(): """Print version information.""" import pkg_resources lavatory_version = pkg_resources.get_distribution('lavatory').version click.echo(lavatory_version)
Example #26
Source Project: python-podman Author: containers File: system.py License: Apache License 2.0 | 5 votes |
def versions(self): """Access versions.""" with self._client() as podman: vers = podman.GetVersion() client = '0.0.0' try: client = pkg_resources.get_distribution('podman').version except Exception: # pylint: disable=broad-except pass vers['client_version'] = client return collections.namedtuple('Version', vers.keys())(**vers)
Example #27
Source Project: custodia Author: latchset File: test_misc.py License: GNU General Public License v3.0 | 5 votes |
def test_import_about(): from custodia import __about__ assert __about__.__title__ == 'custodia' dist = pkg_resources.get_distribution('custodia') assert dist.version == __about__.__version__ # pylint: disable=no-member
Example #28
Source Project: py Author: pytest-dev File: apipkg.py License: MIT License | 5 votes |
def distribution_version(name): """try to get the version of the named distribution, returs None on failure""" from pkg_resources import get_distribution, DistributionNotFound try: dist = get_distribution(name) except DistributionNotFound: pass else: return dist.version
Example #29
Source Project: thingsboard-gateway Author: thingsboard File: tb_updater.py License: Apache License 2.0 | 5 votes |
def __init__(self): super().__init__() self.__version = {"current_version": get_distribution('thingsboard_gateway').version, "latest_version": None} self.__instance_id = str(uuid1()) self.__platform = "deb" self.__os_version = platform() self.__previous_check = 0 self.__check_period = 3600.0 self.__request_timeout = 5 self.__stopped = True self.start()
Example #30
Source Project: moler Author: nokia File: loggers.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def _get_moler_version(): setup_py_path = os.path.join(os.path.dirname(__file__), "..", "..", "setup.py") if "site-packages" in setup_py_path: try: return pkg_resources.get_distribution("moler").version except pkg_resources.DistributionNotFound: return _get_moler_version_cloned_from_git_repository(setup_py_path) else: return _get_moler_version_cloned_from_git_repository(setup_py_path)