Python pkg_resources.DistributionNotFound() Examples
The following are 30
code examples of pkg_resources.DistributionNotFound().
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 File: test_dist.py From calmjs with GNU General Public License v2.0 | 6 votes |
def tests_flatten_egginfo_json_missing_deps(self): """ Missing dependencies should not cause a hard failure. """ make_dummy_dist(self, ( ('requires.txt', '\n'.join([ 'uilib>=1.0', ])), ), 'app', '2.0') working_set = pkg_resources.WorkingSet([self._calmjs_testing_tmpdir]) # Python dependency acquisition failures should fail hard. with self.assertRaises(pkg_resources.DistributionNotFound): calmjs_dist.flatten_egginfo_json(['app'], working_set=working_set)
Example #2
Source File: main.py From phonemizer with GNU General Public License v3.0 | 6 votes |
def __call__(self): """Executes the wrapped function and catch common exceptions""" try: self.function() except (IOError, ValueError, OSError, RuntimeError, AssertionError) as err: self.exit('fatal error: {}'.format(err)) except pkg_resources.DistributionNotFound: self.exit( 'fatal error: phonemizer package not found\n' 'please install phonemizer on your system') except KeyboardInterrupt: self.exit('keyboard interruption, exiting')
Example #3
Source File: session_info.py From reprexpy with 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 #4
Source File: main.py From sawtooth-core with 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 #5
Source File: sawset.py From sawtooth-core with 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 File: test_version_it.py From python-pilosa with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_get_version_setup(self): def mock1(*args, **kwargs): raise OSError try: backup1 = subprocess.check_output except AttributeError: backup1 = None subprocess.check_output = mock1 def mock2(*args, **kwargs): raise pkg_resources.DistributionNotFound backup2 = pkg_resources.require pkg_resources.require = mock2 try: self.assertEquals("0.0.0-unversioned", _get_version_setup()) finally: if backup1: subprocess.check_output = backup1 pkg_resources.require = backup2
Example #7
Source File: sawnet.py From sawtooth-core with 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 File: sawadm.py From sawtooth-core with 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 File: setup.py From pysplit with BSD 3-Clause "New" or "Revised" License | 6 votes |
def check_requirements(): if sys.version_info < PYTHON_VERSION: raise SystemExit('Python version %d.%d required; found %d.%d.' % (PYTHON_VERSION[0], PYTHON_VERSION[1], sys.version_info[0], sys.version_info[1])) for package_name, min_version in DEPENDENCIES.items(): dep_err = False try: package_version = pkg_resources.require(package_name)[0].version except pkg_resources.DistributionNotFound: dep_err = True else: package_version = get_package_version(package_version) if not dep_err: if min_version > package_version: dep_err = True if dep_err: raise ImportError('`%s` version %d.%d or later required.' % ((package_name, ) + min_version))
Example #10
Source File: format_manager.py From ipymd with BSD 3-Clause "New" or "Revised" License | 6 votes |
def register_entrypoints(self): """Look through the `setup_tools` `entry_points` and load all of the formats. """ for spec in iter_entry_points(self.entry_point_group): format_properties = {"name": spec.name} try: format_properties.update(spec.load()) except (DistributionNotFound, ImportError) as err: self.log.info( "ipymd format {} could not be loaded: {}".format( spec.name, err)) continue self.register(**format_properties) return self
Example #11
Source File: version.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def _get_version_from_pkg_resources(self): """Obtain a version from pkg_resources or setup-time logic if missing. This will try to get the version of the package from the pkg_resources record associated with the package, and if there is no such record falls back to the logic sdist would use. """ try: requirement = pkg_resources.Requirement.parse(self.package) provider = pkg_resources.get_provider(requirement) result_string = provider.version except pkg_resources.DistributionNotFound: # The most likely cause for this is running tests in a tree # produced from a tarball where the package itself has not been # installed into anything. Revert to setup-time logic. from pbr import packaging result_string = packaging.get_version(self.package) return SemanticVersion.from_pip_string(result_string)
Example #12
Source File: ez_setup.py From Adafruit_Python_MCP9808 with MIT License | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15): to_dir = os.path.abspath(to_dir) rep_modules = 'pkg_resources', 'setuptools' imported = set(sys.modules).intersection(rep_modules) try: import pkg_resources except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("setuptools>=" + version) return except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.VersionConflict as VC_err: if imported: msg = textwrap.dedent(""" The required version of setuptools (>={version}) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U setuptools'. (Currently using {VC_err.args[0]!r}) """).format(VC_err=VC_err, version=version) sys.stderr.write(msg) sys.exit(2) # otherwise, reload ok del pkg_resources, sys.modules['pkg_resources'] return _do_download(version, download_base, to_dir, download_delay)
Example #13
Source File: client.py From razorpay-python with MIT License | 5 votes |
def _get_version(self): version = "" try: version = pkg_resources.require("razorpay")[0].version except DistributionNotFound: # pragma: no cover pass return version
Example #14
Source File: setup.py From mmcv with Apache License 2.0 | 5 votes |
def choose_requirement(primary, secondary): """If some version of primary requirement installed, return primary, else return secondary.""" try: name = re.split(r'[!<>=]', primary)[0] get_distribution(name) except DistributionNotFound: return secondary return str(primary)
Example #15
Source File: setup.py From chainer with MIT License | 5 votes |
def find_any_distribution(pkgs): for pkg in pkgs: try: return pkg_resources.get_distribution(pkg) except pkg_resources.DistributionNotFound: pass return None
Example #16
Source File: version.py From hcipy with MIT License | 5 votes |
def get_version(): if get_version._version is None: from pkg_resources import get_distribution, DistributionNotFound try: get_version._version = get_distribution('hcipy').version except DistributionNotFound: # package is not installed pass return get_version._version
Example #17
Source File: ez_setup.py From cot with MIT License | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15): to_dir = os.path.abspath(to_dir) rep_modules = 'pkg_resources', 'setuptools' imported = set(sys.modules).intersection(rep_modules) try: import pkg_resources except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("setuptools>=" + version) return except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.VersionConflict as VC_err: if imported: msg = textwrap.dedent(""" The required version of setuptools (>={version}) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U setuptools'. (Currently using {VC_err.args[0]!r}) """).format(VC_err=VC_err, version=version) sys.stderr.write(msg) sys.exit(2) # otherwise, reload ok del pkg_resources, sys.modules['pkg_resources'] return _do_download(version, download_base, to_dir, download_delay)
Example #18
Source File: ez_setup.py From concurrent-log-handler with Apache License 2.0 | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15): # making sure we use the absolute path to_dir = os.path.abspath(to_dir) was_imported = 'pkg_resources' in sys.modules or \ 'setuptools' in sys.modules try: import pkg_resources except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("setuptools>=" + version) return except pkg_resources.VersionConflict: e = sys.exc_info()[1] if was_imported: sys.stderr.write( "The required version of setuptools (>=%s) is not available,\n" "and can't be installed while this script is running. Please\n" "install a more recent version first, using\n" "'easy_install -U setuptools'." "\n\n(Currently using %r)\n" % (version, e.args[0])) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay)
Example #19
Source File: __init__.py From dnsrobocert with MIT License | 5 votes |
def get_version(): try: distribution = pkg_resources.get_distribution(__name__) except pkg_resources.DistributionNotFound: return "dev" else: return distribution.version
Example #20
Source File: cli.py From CrawlBox with The Unlicense | 5 votes |
def main(): '''tldextract CLI main command.''' import argparse logging.basicConfig() try: __version__ = pkg_resources.get_distribution('tldextract').version # pylint: disable=no-member except pkg_resources.DistributionNotFound as _: __version__ = '(local)' parser = argparse.ArgumentParser( prog='tldextract', description='Parse hostname from a url or fqdn') parser.add_argument('--version', action='version', version='%(prog)s ' + __version__) # pylint: disable=no-member parser.add_argument('input', metavar='fqdn|url', type=unicode, nargs='*', help='fqdn or url') parser.add_argument('-u', '--update', default=False, action='store_true', help='force fetch the latest TLD definitions') parser.add_argument('-c', '--cache_file', help='use an alternate TLD definition file') parser.add_argument('-p', '--private_domains', default=False, action='store_true', help='Include private domains') args = parser.parse_args() tld_extract = TLDExtract(include_psl_private_domains=args.private_domains) if args.cache_file: tld_extract.cache_file = args.cache_file if args.update: tld_extract.update(True) elif len(args.input) is 0: parser.print_usage() exit(1) for i in args.input: print(' '.join(tld_extract(i))) # pylint: disable=superfluous-parens
Example #21
Source File: ez_setup.py From ec2-cost-tools with MIT License | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15): to_dir = os.path.abspath(to_dir) rep_modules = 'pkg_resources', 'setuptools' imported = set(sys.modules).intersection(rep_modules) try: import pkg_resources except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("setuptools>=" + version) return except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.VersionConflict as VC_err: if imported: msg = textwrap.dedent(""" The required version of setuptools (>={version}) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U setuptools'. (Currently using {VC_err.args[0]!r}) """).format(VC_err=VC_err, version=version) sys.stderr.write(msg) sys.exit(2) # otherwise, reload ok del pkg_resources, sys.modules['pkg_resources'] return _do_download(version, download_base, to_dir, download_delay)
Example #22
Source File: req.py From oss-ftp with MIT License | 5 votes |
def check_if_exists(self): """Find an installed distribution that satisfies or conflicts with this requirement, and set self.satisfied_by or self.conflicts_with appropriately.""" if self.req is None: return False try: # DISTRIBUTE TO SETUPTOOLS UPGRADE HACK (1 of 3 parts) # if we've already set distribute as a conflict to setuptools # then this check has already run before. we don't want it to # run again, and return False, since it would block the uninstall # TODO: remove this later if (self.req.project_name == 'setuptools' and self.conflicts_with and self.conflicts_with.project_name == 'distribute'): return True else: self.satisfied_by = pkg_resources.get_distribution(self.req) except pkg_resources.DistributionNotFound: return False except pkg_resources.VersionConflict: existing_dist = pkg_resources.get_distribution(self.req.project_name) if self.use_user_site: if dist_in_usersite(existing_dist): self.conflicts_with = existing_dist elif running_under_virtualenv() and dist_in_site_packages(existing_dist): raise InstallationError("Will not install to the user site because it will lack sys.path precedence to %s in %s" %(existing_dist.project_name, existing_dist.location)) else: self.conflicts_with = existing_dist return True
Example #23
Source File: distribute_setup.py From poclbm with GNU General Public License v3.0 | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15, no_fake=True): # making sure we use the absolute path to_dir = os.path.abspath(to_dir) was_imported = 'pkg_resources' in sys.modules or \ 'setuptools' in sys.modules try: try: import pkg_resources if not hasattr(pkg_resources, '_distribute'): if not no_fake: _fake_setuptools() raise ImportError except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("distribute>=" + version) return except pkg_resources.VersionConflict: e = sys.exc_info()[1] if was_imported: sys.stderr.write( "The required version of distribute (>=%s) is not available,\n" "and can't be installed while this script is running. Please\n" "install a more recent version first, using\n" "'easy_install -U distribute'." "\n\n(Currently using %r)\n" % (version, e.args[0])) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay) finally: if not no_fake: _create_fake_setuptools_pkg_info(to_dir)
Example #24
Source File: version.py From courseraprogramming with Apache License 2.0 | 5 votes |
def command_version(args): "Implements the version subcommand" # See http://stackoverflow.com/questions/17583443 from pkg_resources import get_distribution, DistributionNotFound import os.path try: _dist = get_distribution('courseraprogramming') # Normalize case for Windows systems dist_loc = os.path.normcase(_dist.location) here = os.path.normcase(__file__) if not here.startswith(os.path.join(dist_loc, 'courseraprogramming')): # not installed, but there is another version that *is* raise DistributionNotFound except DistributionNotFound: __version__ = 'Please install this project with setup.py' else: __version__ = _dist.version if args.quiet and args.quiet > 0: print(__version__) else: print("Your %(prog)s's version is:\n\t%(version)s" % { "prog": sys.argv[0], "version": __version__ })
Example #25
Source File: helper.py From twtxt with MIT License | 5 votes |
def generate_user_agent(): try: version = pkg_resources.require("twtxt")[0].version except pkg_resources.DistributionNotFound: version = "unknown" conf = click.get_current_context().obj["conf"] if conf.disclose_identity and conf.nick and conf.twturl: user_agent = "twtxt/{version} (+{url}; @{nick})".format( version=version, url=conf.twturl, nick=conf.nick) else: user_agent = "twtxt/{version}".format(version=version) return {"User-Agent": user_agent}
Example #26
Source File: ez_setup.py From topical_word_embeddings with MIT License | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15): # making sure we use the absolute path to_dir = os.path.abspath(to_dir) was_imported = 'pkg_resources' in sys.modules or \ 'setuptools' in sys.modules try: import pkg_resources except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("setuptools>=" + version) return except pkg_resources.VersionConflict: e = sys.exc_info()[1] if was_imported: sys.stderr.write( "The required version of setuptools (>=%s) is not available,\n" "and can't be installed while this script is running. Please\n" "install a more recent version first, using\n" "'easy_install -U setuptools'." "\n\n(Currently using %r)\n" % (version, e.args[0])) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay)
Example #27
Source File: ez_setup.py From topical_word_embeddings with MIT License | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15): # making sure we use the absolute path to_dir = os.path.abspath(to_dir) was_imported = 'pkg_resources' in sys.modules or \ 'setuptools' in sys.modules try: import pkg_resources except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("setuptools>=" + version) return except pkg_resources.VersionConflict: e = sys.exc_info()[1] if was_imported: sys.stderr.write( "The required version of setuptools (>=%s) is not available,\n" "and can't be installed while this script is running. Please\n" "install a more recent version first, using\n" "'easy_install -U setuptools'." "\n\n(Currently using %r)\n" % (version, e.args[0])) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay)
Example #28
Source File: ez_setup.py From topical_word_embeddings with MIT License | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15): # making sure we use the absolute path to_dir = os.path.abspath(to_dir) was_imported = 'pkg_resources' in sys.modules or \ 'setuptools' in sys.modules try: import pkg_resources except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("setuptools>=" + version) return except pkg_resources.VersionConflict: e = sys.exc_info()[1] if was_imported: sys.stderr.write( "The required version of setuptools (>=%s) is not available,\n" "and can't be installed while this script is running. Please\n" "install a more recent version first, using\n" "'easy_install -U setuptools'." "\n\n(Currently using %r)\n" % (version, e.args[0])) sys.exit(2) else: del pkg_resources, sys.modules['pkg_resources'] # reload ok return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay)
Example #29
Source File: ez_setup.py From Adafruit_Python_PCA9685 with MIT License | 5 votes |
def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, download_delay=15): to_dir = os.path.abspath(to_dir) rep_modules = 'pkg_resources', 'setuptools' imported = set(sys.modules).intersection(rep_modules) try: import pkg_resources except ImportError: return _do_download(version, download_base, to_dir, download_delay) try: pkg_resources.require("setuptools>=" + version) return except pkg_resources.DistributionNotFound: return _do_download(version, download_base, to_dir, download_delay) except pkg_resources.VersionConflict as VC_err: if imported: msg = textwrap.dedent(""" The required version of setuptools (>={version}) is not available, and can't be installed while this script is running. Please install a more recent version first, using 'easy_install -U setuptools'. (Currently using {VC_err.args[0]!r}) """).format(VC_err=VC_err, version=version) sys.stderr.write(msg) sys.exit(2) # otherwise, reload ok del pkg_resources, sys.modules['pkg_resources'] return _do_download(version, download_base, to_dir, download_delay)
Example #30
Source File: test_resources.py From oss-ftp with MIT License | 5 votes |
def testResolve(self): ad = pkg_resources.Environment([]) ws = WorkingSet([]) # Resolving no requirements -> nothing to install self.assertEqual(list(ws.resolve([],ad)), []) # Request something not in the collection -> DistributionNotFound self.assertRaises( pkg_resources.DistributionNotFound, ws.resolve, parse_requirements("Foo"), ad ) Foo = Distribution.from_filename( "/foo_dir/Foo-1.2.egg", metadata=Metadata(('depends.txt', "[bar]\nBaz>=2.0")) ) ad.add(Foo) ad.add(Distribution.from_filename("Foo-0.9.egg")) # Request thing(s) that are available -> list to activate for i in range(3): targets = list(ws.resolve(parse_requirements("Foo"), ad)) self.assertEqual(targets, [Foo]) list(map(ws.add,targets)) self.assertRaises(VersionConflict, ws.resolve, parse_requirements("Foo==0.9"), ad) ws = WorkingSet([]) # reset # Request an extra that causes an unresolved dependency for "Baz" self.assertRaises( pkg_resources.DistributionNotFound, ws.resolve,parse_requirements("Foo[bar]"), ad ) Baz = Distribution.from_filename( "/foo_dir/Baz-2.1.egg", metadata=Metadata(('depends.txt', "Foo")) ) ad.add(Baz) # Activation list now includes resolved dependency self.assertEqual( list(ws.resolve(parse_requirements("Foo[bar]"), ad)), [Foo,Baz] ) # Requests for conflicting versions produce VersionConflict self.assertRaises(VersionConflict, ws.resolve, parse_requirements("Foo==1.2\nFoo!=1.2"), ad)