def plugins_iter(plugin_dir, ep_name): """ @type plugin_dir : C{str} @param plugin_dir : The fqname of the plugin directory @type ep_name : C{str} @param ep_name : The name of the Entry Point to be loaded @yield: The loaded Entry Point (C{obj}) """ working_set.add_entry(plugin_dir) pkg_env = Environment([plugin_dir]) for env_name in pkg_env: egg = pkg_env[env_name][0] LOG.debug("Activating egg: %s"%(egg)) egg.activate() for name in egg.get_entry_map(ep_name): entry_point = egg.get_entry_info(ep_name, name) LOG.debug("Loading entry point: %s"%(entry_point)) cls = entry_point.load() yield cls for entry_point in working_set.iter_entry_points(ep_name): LOG.debug("Loading entry point: %s"%(entry_point)) cls = entry_point.load() yield cls
def setUpModule(): # # Install a fake distribution that we can use to inject entry # points at runtime. # # The side effects from this are pretty severe, but they (very # probably) only impact this test, and they are undone as soon as # the process terminates. # working_set.add_entry(dirname(__file__))
def add_to_sys_path(package): site_packages_dir = os.path.dirname(os.__file__) + "/site-packages/" for path in os.listdir(site_packages_dir): if path.startswith(package): newpath = site_packages_dir + path if path.endswith(".egg-link"): newpath = open(newpath).readline().strip() sys.path.append(newpath) working_set.add_entry(newpath) return
def test_setup_requires_with_transitive_extra_dependency( self, monkeypatch): # Use case: installing a package with a build dependency on # an already installed `dep[extra]`, which in turn depends # on `extra_dep` (whose is not already installed). with contexts.save_pkg_resources_state(): with contexts.tempdir() as temp_dir: # Create source distribution for `extra_dep`. make_trivial_sdist( os.path.join(temp_dir, 'extra_dep-1.0.tar.gz'), 'extra_dep', '1.0') # Create source tree for `dep`. dep_pkg = os.path.join(temp_dir, 'dep') os.mkdir(dep_pkg) build_files( { 'setup.py': DALS(""" import setuptools setuptools.setup( name='dep', version='2.0', extras_require={'extra': ['extra_dep']}, ) """), 'setup.cfg': '', }, prefix=dep_pkg) # "Install" dep. run_setup(os.path.join(dep_pkg, 'setup.py'), [str('dist_info')]) working_set.add_entry(dep_pkg) # Create source tree for test package. test_pkg = os.path.join(temp_dir, 'test_pkg') test_setup_py = os.path.join(test_pkg, 'setup.py') test_setup_cfg = os.path.join(test_pkg, 'setup.cfg') os.mkdir(test_pkg) with open(test_setup_py, 'w') as fp: fp.write( DALS(''' from setuptools import installer, setup setup(setup_requires='dep[extra]') ''')) # Check... monkeypatch.setenv(str('PIP_FIND_LINKS'), str(temp_dir)) monkeypatch.setenv(str('PIP_NO_INDEX'), str('1')) monkeypatch.setenv(str('PIP_RETRIES'), str('0')) monkeypatch.setenv(str('PIP_TIMEOUT'), str('0')) run_setup(test_setup_py, [str('--version')])
def install_pip(): """Installs pip, easy_installs better behaved younger brother""" root = sys.prefix global pip try: import pip except ImportError: sh(easy_install_path+' pip') site_packages_dir = os.path.dirname(os.__file__) +'/site-packages/' for path in os.listdir(site_packages_dir): if path.startswith('pip'): sys.path.append(site_packages_dir+path) working_set.add_entry(site_packages_dir+path) return import pip
def resolve(requirements, parent=None): for req in requirements: qualreq = parent and '%s->%s' % (req, parent) or req print("Resolving setup requirement %s:" % qualreq) try: dist = get_distribution(req) print(repr(dist)) except (DistributionNotFound, VersionConflict): dist = installer(req) sys.path.insert(0, dist.location) working_set.add_entry(dist.location) extras = re.match(r'[^#\[]*\[([^#\]]*)\]', req) if extras: extras = list(map(str.strip, extras.group(1).split(','))) resolve((str(req).split(';')[0] for req in dist.requires(extras=extras or ())), qualreq)
def fakeapp(): test_dir = os.path.dirname(__file__) egg_info_dir = os.path.join( test_dir, 'fake_packages', 'FakeApp.egg', 'EGG-INFO') info_dir = os.path.join( test_dir, 'fake_packages', 'FakeApp.egg', 'FakeApp.egg-info-dir') if not os.path.exists(egg_info_dir): try: os.symlink(info_dir, egg_info_dir) except: shutil.copytree(info_dir, egg_info_dir) sys.path.append(os.path.dirname(egg_info_dir)) working_set.add_entry(os.path.dirname(egg_info_dir)) require('FakeApp') import fakeapp.apps return fakeapp
def _resolve(requirements, parent=None): """ The actual recursive `requirements` resolver `parent` string is used for printing fully qualified requirement chains """ for req in requirements: qualreq = parent and '%s->%s' % (req, parent) or req print("Resolving setup requirement %s:" % qualreq) try: dist = get_distribution(req) except (DistributionNotFound, VersionConflict): dist = INSTALLER(req) sys.path.insert(0, dist.location) working_set.add_entry(dist.location) print(repr(dist)) extras = re.match(r'[^#\[]*\[([^#\]]*)\]', req) if extras: extras = list(map(str.strip, extras.group(1).split(','))) _resolve((str(req).split(';')[0] for req in dist.requires(extras=extras or ())), qualreq)
def __init__(self): self._plugins = {} plugins_dir = os.path.join(site_settings["HIGGINS_DIR"], "plugins") self.log_info("added '%s' to plugin search path" % plugins_dir) working_set.add_entry(plugins_dir) env = Environment([plugins_dir,]) self._eggs,errors = working_set.find_plugins(env) # load plugin eggs for p in self._eggs: working_set.add(p) self.log_info("loaded plugin egg '%s'" % p) for e in errors: self.log_error("failed to load plugin egg '%s'" % e) # load all discovered plugins for ep in working_set.iter_entry_points('higgins.plugin'): try: factory = ep.load() if issubclass(factory, Service): self.log_info("found service plugin '%s'" % ep.name) self._plugins[ep.name] = factory else: self.log_warning("ignoring plugin '%s': unknown plugin type" % ep.name) except Exception, e: self.log_error("failed to load plugin '%s': %s" % (ep.name, e))
def setup_module(): entry = resource_filename(__name__, 'fixtures/TestMe.egg') working_set.add_entry(entry)
def setup_module(): # This egg has [wex] entry points we use for testing entry = resource_filename(__name__, 'fixtures/TestMe.egg') working_set.add_entry(entry)
def configure(self, settings): """ Finds all discoverable plugins and configures them. Plugins are discoverable if they are in the normal python module path, or in the path specified by 'plugin directory'. """ # load plugins section = settings.section('server') self.pluginsdir = os.path.join(section.getPath("plugin directory")) if self.pluginsdir: logger.debug("loading plugins from %s" % self.pluginsdir) working_set.add_entry(self.pluginsdir) env = Environment([self.pluginsdir,]) else: env = Environment([]) self._eggs,errors = working_set.find_plugins(env) # load plugin eggs for p in self._eggs: working_set.add(p) logger.info("loaded plugin egg '%s'" % p) for e in errors: logger.info("failed to load plugin egg '%s'" % e) # load all discovered plugins for each type for ep in working_set.iter_entry_points("terane.plugin"): # if no config section exists, then don't load the plugin if not settings.hasSection("plugin:%s" % ep.name): continue try: # load and configure the plugin _Plugin = ep.load() if not IPlugin.implementedBy(_Plugin): raise Exception("plugin '%s' doesn't implement IPlugin" % ep.name) plugin = _Plugin() plugin.setName(ep.name) plugin.setServiceParent(self) section = settings.section("plugin:%s" % ep.name) plugin.configure(section) logger.info("loaded plugin '%s'" % ep.name) # find all plugin components for impl,spec,name in plugin.listComponents(): if not ILoadable.implementedBy(impl): raise Exception("component %s:%s in plugin %s doesn't implement ILoadable" % (spec.__name__, name, ep.name)) if not isinstance(spec, InterfaceClass): raise TypeError("spec must be an Interface") if (spec,name) in self._components: raise KeyError("component %s:%s already exists" % (spec.__name__,name)) # a little extra syntax here to make sure the lambda expression # passed as the factory function has the appropriate variables bound # in its scope def _makeTrampoline(impl=impl, plugin=plugin): def _trampoline(*args, **kwds): logger.trace("allocating new %s from plugin %s" % (impl.__name__,plugin.name)) return impl(plugin, *args, **kwds) return _trampoline self._components[(spec,name)] = _makeTrampoline(impl, plugin) logger.trace("added component %s:%s" % (spec.__name__, name)) except ConfigureError: raise except Exception, e: logger.exception(e) logger.warning("failed to load plugin '%s'" % ep.name)
def configure(self, settings): """ Finds all discoverable plugins and configures them. Plugins are discoverable if they are in the normal python module path, or in the path specified by 'plugin directory'. """ # load plugins section = settings.section('server') self.pluginsdir = os.path.join(section.getPath("plugin directory")) if self.pluginsdir: logger.debug("loading plugins from %s" % self.pluginsdir) working_set.add_entry(self.pluginsdir) env = Environment([ self.pluginsdir, ]) else: env = Environment([]) self._eggs, errors = working_set.find_plugins(env) # load plugin eggs for p in self._eggs: working_set.add(p) logger.info("loaded plugin egg '%s'" % p) for e in errors: logger.info("failed to load plugin egg '%s'" % e) # load all discovered plugins for each type for ep in working_set.iter_entry_points("terane.plugin"): # if no config section exists, then don't load the plugin if not settings.hasSection("plugin:%s" % ep.name): continue try: # load and configure the plugin _Plugin = ep.load() if not IPlugin.implementedBy(_Plugin): raise Exception("plugin '%s' doesn't implement IPlugin" % ep.name) plugin = _Plugin() plugin.setName(ep.name) plugin.setServiceParent(self) section = settings.section("plugin:%s" % ep.name) plugin.configure(section) logger.info("loaded plugin '%s'" % ep.name) # find all plugin components for impl, spec, name in plugin.listComponents(): if not ILoadable.implementedBy(impl): raise Exception( "component %s:%s in plugin %s doesn't implement ILoadable" % (spec.__name__, name, ep.name)) if not isinstance(spec, InterfaceClass): raise TypeError("spec must be an Interface") if (spec, name) in self._components: raise KeyError("component %s:%s already exists" % (spec.__name__, name)) # a little extra syntax here to make sure the lambda expression # passed as the factory function has the appropriate variables bound # in its scope def _makeTrampoline(impl=impl, plugin=plugin): def _trampoline(*args, **kwds): logger.trace("allocating new %s from plugin %s" % (impl.__name__, plugin.name)) return impl(plugin, *args, **kwds) return _trampoline self._components[(spec, name)] = _makeTrampoline(impl, plugin) logger.trace("added component %s:%s" % (spec.__name__, name)) except ConfigureError: raise except Exception, e: logger.exception(e) logger.warning("failed to load plugin '%s'" % ep.name)
ENTRY_NAME = '.git_archival.txt' ENTRY_POINT = ENTRY_NAME + ' = setuptools_scm_git_archive:parse' meta = dict( name='setuptools_scm_git_archive', description='setuptools_scm plugin for git archives', author='Changaco', author_email='*****@*****.**', url='https://github.com/Changaco/setuptools_scm_git_archive/', license='MIT', packages=find_packages(), long_description=open(join(dirname(__file__), 'README.rst')).read(), keywords='scm vcs version tags git archive', setup_requires=['setuptools-scm'], entry_points={ ENTRY_GROUP: ENTRY_POINT, ENTRY_GROUP_FALLBACK: ENTRY_POINT, }, ) # Clean up first, old eggs seem to confuse setuptools_scm rmtree(meta['name']+'.egg-info', ignore_errors=True) # Bootstrap try: load_entry_point(meta['name'], ENTRY_GROUP, ENTRY_NAME) except (DistributionNotFound, ImportError): working_set.add_entry('.') setup(use_scm_version=True, **meta)
setup_requires=["setuptools-scm"], entry_points={ENTRY_GROUP: ENTRY_POINT}, classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Version Control", "Topic :: System :: Software Distribution", "Topic :: Utilities", ], ) # Clean up first, old eggs seem to confuse setuptools_scm rmtree(setup_params["name"] + ".egg-info", ignore_errors=True) # Bootstrap try: load_entry_point(setup_params["name"], ENTRY_GROUP, ENTRY_NAME) except (DistributionNotFound, ImportError): working_set.add_entry(".") if __name__ == "__main__": setuptools.setup(**setup_params)
from pkg_resources import DistributionNotFound, load_entry_point, working_set from setuptools import find_packages, setup ENTRY_GROUP = 'setuptools_scm.parse_scm' ENTRY_NAME = '.git_archival.txt' ENTRY_POINT = ENTRY_NAME + ' = setuptools_scm_git_archive:parse' meta = dict( name='setuptools_scm_git_archive', description='setuptools_scm plugin for git archives', author='Changaco', author_email='*****@*****.**', url='https://github.com/Changaco/setuptools_scm_git_archive/', license='MIT', packages=find_packages(), long_description=open(join(dirname(__file__), 'README.rst')).read(), keywords='scm vcs version tags git archive', setup_requires=['setuptools_scm'], entry_points={ENTRY_GROUP: ENTRY_POINT}, ) # Bootstrap try: load_entry_point(meta['name'], ENTRY_GROUP, ENTRY_NAME) except (DistributionNotFound, ImportError): setup(version='0', **meta) working_set.add_entry('.') setup(use_scm_version=True, **meta)
"produceroverlay": "p2ner.%s.produceroverlay", "overlay": "p2ner.%s.overlay", "serveroverlay": "p2ner.%s.serveroverlay", "pipeelement": "p2ner.%s.pipeelement", "ui": "p2ner.%s.ui", 'interface': 'p2ner.%s.interface', "input": "p2ner.%s.input", "output": "p2ner.%s.output", "plugin": "p2ner.%s.plugin", "stats": "p2ner.%s.stats", "flowcontrol": "p2ner.%s.flowcontrol" } COMPONENTS_DIR = os.path.dirname(os.path.abspath(sys.argv[0])) USER_COMPONENTS_DIR = "" working_set.add_entry(COMPONENTS_DIR) pkg_env = Environment([COMPONENTS_DIR]) for name in pkg_env: working_set.require(pkg_env[name][0].key) sys.path.append(COMPONENTS_DIR) def getComponents(ctype): """Get all the components of a given type :param ctype: the component's type :type ctype: string :returns: {"ComponentName":ComponentClass,...} :rtype: dict
from setuptools import find_packages, setup ENTRY_GROUP = "setuptools_scm.parse_scm" ENTRY_GROUP_FALLBACK = "setuptools_scm.parse_scm_fallback" ENTRY_NAME = ".git_archival.txt" ENTRY_POINT = ENTRY_NAME + " = setuptools_scm_git_archive:parse" meta = dict( name="setuptools_scm_git_archive", description="setuptools_scm plugin for git archives", author="Changaco", author_email="*****@*****.**", url="https://github.com/Changaco/setuptools_scm_git_archive/", license="MIT", packages=find_packages(), long_description=open(join(dirname(__file__), "README.rst")).read(), keywords="scm vcs version tags git archive", setup_requires=["setuptools_scm"], entry_points={ENTRY_GROUP: ENTRY_POINT, ENTRY_GROUP_FALLBACK: ENTRY_POINT}, ) # Bootstrap try: load_entry_point(meta["name"], ENTRY_GROUP, ENTRY_NAME) except (DistributionNotFound, ImportError): setup(version="0", **meta) working_set.add_entry(".") setup(use_scm_version=True, **meta)