本文整理汇总了Python中vsc.utils.missing.get_subclasses函数的典型用法代码示例。如果您正苦于以下问题:Python get_subclasses函数的具体用法?Python get_subclasses怎么用?Python get_subclasses使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_subclasses函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: avail_job_backends
def avail_job_backends(check_usable=True):
"""
Return all known job execution backends.
"""
import_available_modules('easybuild.tools.job')
class_dict = dict([(x.__name__, x) for x in get_subclasses(JobBackend)])
return class_dict
开发者ID:cyiops,项目名称:easybuild-framework,代码行数:7,代码来源:backend.py
示例2: avail_package_naming_schemes
def avail_package_naming_schemes():
"""
Returns the list of valed naming schemes that are in the easybuild.package.package_naming_scheme namespace
"""
import_available_modules('easybuild.tools.package.package_naming_scheme')
class_dict = dict([(x.__name__, x) for x in get_subclasses(PackageNamingScheme)])
return class_dict
开发者ID:jgphpc,项目名称:easybuild-framework,代码行数:7,代码来源:utilities.py
示例3: what_sched
def what_sched(requested):
"""Return the scheduler class """
def sched_to_key(klass):
"""Return key for specified scheduler class which can be used for sorting."""
# use lowercase class name for sorting
key = klass.__name__.lower()
# prefix key for SLURM scheduler class with '_'
# this is done to consider SLURM before PBS, since $PBS* environment variables may be defined in SLURM job env
if key == 'slurm':
key = '_' + key
return key
# exclude Coupler class which also is a subclass of Sched, since it's not an actual scheduler
found_sched = sorted([c for c in get_subclasses(Sched) if c.__name__ != 'Coupler'], key=sched_to_key)
# Get local scheduler
local_sched = get_local_sched(found_sched)
# first, try to use the scheduler that was requested
if requested:
for sched in found_sched:
if sched._is_sched_for(requested):
return sched, found_sched
LOGGER.warn("%s scheduler was requested, but mympirun failed to find an implementation", requested)
# next, try to use the scheduler defined by environment variables
for sched in found_sched:
if sched.SCHED_ENVIRON_NODE_INFO in os.environ and sched.SCHED_ENVIRON_ID in os.environ:
return sched, found_sched
# If that fails, try to force the local scheduler
LOGGER.debug("No scheduler found in environment, trying local")
return local_sched, found_sched
开发者ID:hpcugent,项目名称:vsc-mympirun,代码行数:35,代码来源:sched.py
示例4: get_convert_class
def get_convert_class(class_name):
"""Return the Convert class with specified class name class_name"""
res = [x for x in nub(get_subclasses(Convert)) if x.__name__ == class_name]
if len(res) == 1:
return res[0]
else:
raise EasyBuildError("More than one Convert subclass found for name %s: %s", class_name, res)
开发者ID:LiangFr,项目名称:easybuild-framework,代码行数:7,代码来源:convert.py
示例5: pingpongfactory
def pingpongfactory(pptype, comm, p, log):
"""a factory for creating PingPong objects"""
for cls in get_subclasses(PingPongSR, include_base_class=True):
if "PingPong%s" % pptype == cls.__name__:
return cls(comm, p, log)
raise KeyError
开发者ID:stdweird,项目名称:mympingpong,代码行数:7,代码来源:pingpongers.py
示例6: get_format_version_classes
def get_format_version_classes(version=None):
"""Return the (usable) subclasses from EasyConfigFormat that have a matching version."""
all_classes = get_subclasses(EasyConfigFormat)
if version is None:
return all_classes
else:
return [x for x in all_classes if x.VERSION == version and x.USABLE]
开发者ID:akesandgren,项目名称:easybuild-framework,代码行数:7,代码来源:format.py
示例7: what_sched
def what_sched(requested):
"""Return the scheduler class """
# import all modules in this dir: http://stackoverflow.com/a/16853487
for loader, modulename, _ in pkgutil.walk_packages([os.path.dirname(__file__)]):
loader.find_module(modulename).load_module(modulename)
found_sched = get_subclasses(Sched)
# first, try to use the scheduler that was requested
if requested:
for sched in found_sched:
if sched._is_sched_for(requested):
return sched, found_sched
LOGGER.warn("%s scheduler was requested, but mympirun failed to find an implementation", requested)
# next, try to use the scheduler defined by environment variables
for sched in found_sched:
if sched.SCHED_ENVIRON_ID in os.environ:
return sched, found_sched
# If that fails, try to force the local scheduler
for sched in found_sched:
LOGGER.debug("No scheduler found in environment, trying local")
if sched._is_sched_for("local"):
return sched, found_sched
# if there is no local scheduler, return None
return None, found_sched
开发者ID:Iepoev,项目名称:vsc-mympirun,代码行数:30,代码来源:sched.py
示例8: whatMPI
def whatMPI(name):
"""
Return the scriptname and the MPI class
"""
fullscriptname = os.path.abspath(name)
scriptname = os.path.basename(fullscriptname)
found_mpi = get_subclasses(MPI)
# check on scriptname
for mpi in found_mpi:
if mpi._is_mpiscriptname_for(scriptname):
stripfake() # mandatory before return at this point
return scriptname, mpi, found_mpi
# not called through alias
# stripfake is in which
mpirunname = which(['mpirun'])
if mpirunname is None:
return None, None, found_mpi
for mpi in found_mpi:
if mpi._is_mpirun_for(mpirunname):
return scriptname, mpi, found_mpi
# return found mpirunname
return mpirunname, None, found_mpi
开发者ID:wpoely86,项目名称:vsc-mympirun,代码行数:27,代码来源:mpi.py
示例9: get_convert_class
def get_convert_class(class_name):
"""Return the Convert class with specified class name class_name"""
res = [x for x in nub(get_subclasses(Convert)) if x.__name__ == class_name]
if len(res) == 1:
return res[0]
else:
_log.error('More then one Convert subclass found for name %s: %s' % (class_name, res))
开发者ID:JackPerdue,项目名称:easybuild-framework,代码行数:7,代码来源:convert.py
示例10: search_toolchain
def search_toolchain(name):
"""
Obtain a Toolchain instance for the toolchain with specified name, next to a list of available toolchains.
:param name: toolchain name
:return: Toolchain instance (or None), found_toolchains
"""
package = easybuild.tools.toolchain
check_attr_name = '%s_PROCESSED' % TC_CONST_PREFIX
if not hasattr(package, check_attr_name) or not getattr(package, check_attr_name):
# import all available toolchains, so we know about them
tc_modules = import_available_modules('easybuild.toolchains')
# make sure all defined toolchain constants are available in toolchain module
tc_const_re = re.compile('^%s(.*)$' % TC_CONST_PREFIX)
for tc_mod in tc_modules:
# determine classes imported in this module
mod_classes = []
for elem in [getattr(tc_mod, x) for x in dir(tc_mod)]:
if hasattr(elem, '__module__'):
# exclude the toolchain class defined in that module
if not tc_mod.__file__ == sys.modules[elem.__module__].__file__:
_log.debug("Adding %s to list of imported classes used for looking for constants" % elem.__name__)
mod_classes.append(elem)
# look for constants in modules of imported classes, and make them available
for mod_class_mod in [sys.modules[mod_class.__module__] for mod_class in mod_classes]:
for elem in dir(mod_class_mod):
res = tc_const_re.match(elem)
if res:
tc_const_name = res.group(1)
tc_const_value = getattr(mod_class_mod, elem)
_log.debug("Found constant %s ('%s') in module %s, adding it to %s",
tc_const_name, tc_const_value, mod_class_mod.__name__, package.__name__)
if hasattr(package, tc_const_name):
cur_value = getattr(package, tc_const_name)
if not tc_const_value == cur_value:
raise EasyBuildError("Constant %s.%s defined as '%s', can't set it to '%s'.",
package.__name__, tc_const_name, cur_value, tc_const_value)
else:
setattr(package, tc_const_name, tc_const_value)
# indicate that processing of toolchain constants is done, so it's not done again
setattr(package, check_attr_name, True)
else:
_log.debug("Skipping importing of toolchain modules, processing of toolchain constants is already done.")
# obtain all subclasses of toolchain
found_tcs = nub(get_subclasses(Toolchain))
# filter found toolchain subclasses based on whether they can be used a toolchains
found_tcs = [tc for tc in found_tcs if tc._is_toolchain_for(None)]
for tc in found_tcs:
if tc._is_toolchain_for(name):
return tc, found_tcs
return None, found_tcs
开发者ID:hpcugent,项目名称:easybuild-framework,代码行数:59,代码来源:utilities.py
示例11: what_licenses
def what_licenses():
"""Return a dict of License subclasses names and license instances"""
res = {}
for lic in get_subclasses(License):
if lic.HIDDEN:
continue
res[lic.__name__] = lic
return res
开发者ID:ULHPC,项目名称:easybuild-framework,代码行数:9,代码来源:licenses.py
示例12: avail_modules_tools
def avail_modules_tools():
"""
Return all known modules tools.
"""
class_dict = dict([(x.__name__, x) for x in get_subclasses(ModulesTool)])
# filter out legacy Modules class
if 'Modules' in class_dict:
del class_dict['Modules']
return class_dict
开发者ID:JensTimmerman,项目名称:easybuild-framework,代码行数:9,代码来源:modules.py
示例13: get_job
def get_job(classname, options):
"""
This is a job factory.
Returns an instance of classname initialized with options
"""
for cls in get_subclasses(Job):
if cls._is_job_for(classname):
return cls(options)
getLogger().error("No job class found for %s", classname)
开发者ID:ehiggs,项目名称:hanythingondemand,代码行数:10,代码来源:job.py
示例14: avail_repositories
def avail_repositories(check_useable=True):
"""
Return all available repositories.
check_useable: boolean, if True, only return usable repositories
"""
class_dict = dict([(x.__name__, x) for x in get_subclasses(Repository) if x.USABLE or not check_useable])
if not 'FileRepository' in class_dict:
_log.error('avail_repositories: FileRepository missing from list of repositories')
return class_dict
开发者ID:damienfrancois,项目名称:easybuild-framework,代码行数:11,代码来源:repository.py
示例15: avail_repositories
def avail_repositories(check_useable=True):
"""
Return all available repositories.
check_useable: boolean, if True, only return usable repositories
"""
import_available_modules('easybuild.tools.repository')
class_dict = dict([(x.__name__, x) for x in get_subclasses(Repository) if x.USABLE or not check_useable])
if not 'FileRepository' in class_dict:
raise EasyBuildError("avail_repositories: FileRepository missing from list of repositories")
return class_dict
开发者ID:ULHPC,项目名称:easybuild-framework,代码行数:13,代码来源:repository.py
示例16: test_mympirun_aliases_setup
def test_mympirun_aliases_setup(self):
"""Make sure that list of mympirun aliases included in setup.py is synced"""
from setup import MYMPIRUN_ALIASES
# make sure all modules in vsc.mympirun.mpi are imported
for loader, modname, _ in pkgutil.walk_packages([os.path.dirname(mpim.__file__)]):
loader.find_module(modname).load_module(modname)
# determine actual list of mympirun aliases
mympirun_aliases = ['myscoop']
for mpiclass in get_subclasses(mpim.MPI):
mympirun_aliases.extend(mpiclass._mpiscriptname_for)
self.assertEqual(MYMPIRUN_ALIASES, nub(sorted(mympirun_aliases)))
开发者ID:hpcugent,项目名称:vsc-mympirun,代码行数:14,代码来源:mpi.py
示例17: what_mpi
def what_mpi(name):
"""
Return the path of the selected mpirun and its class.
@param name: The name of the executable used to run mympirun
@return: A triplet containing the following variables:
- The path to the executable used to run mympirun (should be the path to an mpirun implementation)
- The corresponding python class of the MPI variant
- The python classes of the supported MPI flavors (from the various .py files in mympirun/mpi)
"""
# import all modules in this dir: http://stackoverflow.com/a/16853487
for loader, modulename, _ in pkgutil.walk_packages([os.path.dirname(__file__)]):
loader.find_module(modulename).load_module(modulename)
supp_mpi_impl = get_subclasses(MPI) # supported MPI implementations
# remove fake mpirun from $PATH
stripfake()
# get the path of the mpirun executable
mpirun_path = which('mpirun')
if mpirun_path is None:
# no MPI implementation installed
LOGGER.warn("no mpirun command found")
return None, None, supp_mpi_impl
scriptname = os.path.basename(os.path.abspath(name))
# check if mympirun was called by a known mpirun alias (like
# ompirun for OpenMPI or mhmpirun for mpich)
for mpi in supp_mpi_impl:
if mpi._is_mpiscriptname_for(scriptname):
LOGGER.debug("%s was used to call mympirun", scriptname)
return scriptname, mpi, supp_mpi_impl
# mympirun was not called through a known alias, so find out which MPI
# implementation the user has installed
for mpi in supp_mpi_impl:
if mpi._is_mpirun_for(mpirun_path):
return scriptname, mpi, supp_mpi_impl
# no specific flavor found, default to mpirun_path
LOGGER.warn("The executable that called mympirun (%s) isn't supported"
", defaulting to %s", name, mpirun_path)
return mpirun_path, None, supp_mpi_impl
开发者ID:Iepoev,项目名称:vsc-mympirun,代码行数:47,代码来源:mpi.py
示例18: avail_module_naming_schemes
def avail_module_naming_schemes():
"""
Returns a list of available module naming schemes.
"""
mns_attr = 'AVAIL_MODULE_NAMING_SCHEMES'
if not hasattr(module_naming_scheme, mns_attr):
# all subclasses of ModuleNamingScheme available in the easybuild.tools.module_naming_scheme namespace are eligible
import_available_modules('easybuild.tools.module_naming_scheme')
# construct name-to-class dict of available module naming scheme
avail_mnss = dict([(x.__name__, x) for x in get_subclasses(ModuleNamingScheme)])
# cache dict of available module naming scheme in module constant
setattr(module_naming_scheme, mns_attr, avail_mnss)
return avail_mnss
else:
return getattr(module_naming_scheme, mns_attr)
开发者ID:lsuhpchelp,项目名称:easybuild_smic,代码行数:17,代码来源:module_generator.py
示例19: what_mpi
def what_mpi(name):
"""
Return the path of the selected mpirun and its class.
@param name: The name of the executable used to run mympirun
@return: A triplet containing the following variables:
- The path to the executable used to run mympirun (should be the path to an mpirun implementation)
- The corresponding python class of the MPI variant
- The python classes of the supported MPI flavors (from the various .py files in mympirun/mpi)
"""
# The coupler is also a subclass of MPI, but it isn't and MPI implementation
supp_mpi_impl = [x for x in get_subclasses(MPI) if x.__name__ != 'Coupler'] # supported MPI implementations
# remove fake mpirun from $PATH
stripfake()
# get the path of the mpirun executable
mpirun_path = which('mpirun')
if mpirun_path is None:
# no MPI implementation installed
LOGGER.warn("no mpirun command found")
return None, None, supp_mpi_impl
scriptname = os.path.basename(os.path.abspath(name))
# check if mympirun was called by a known mpirun alias (like
# ompirun for OpenMPI or mhmpirun for mpich)
for mpi in supp_mpi_impl:
if mpi._is_mpiscriptname_for(scriptname) and mpi._is_mpirun_for(mpirun_path):
LOGGER.debug("%s was used to call mympirun", scriptname)
return scriptname, mpi, supp_mpi_impl
# mympirun was not called through a known alias, so find out which MPI
# implementation the user has installed
for mpi in supp_mpi_impl:
if mpi._is_mpirun_for(mpirun_path):
return scriptname, mpi, supp_mpi_impl
# no specific flavor found, default to mpirun_path
LOGGER.warn("The executable that called mympirun (%s) isn't supported, defaulting to %s", name, mpirun_path)
return mpirun_path, None, supp_mpi_impl
开发者ID:hpcugent,项目名称:vsc-mympirun,代码行数:43,代码来源:mpi.py
示例20: make_init
def make_init(self):
""" add all the options to generaloption, so it can correctly parse the command line arguments """
opts = {
# long option: (description, type, action, default, short option)
"basepath": ("Directory (preferably shared) to use for temporary mympirun files (default: HOME).",
"str", "store", None),
'branchcount': ("Set the hydra branchcount", "int", "store", None),
"debuglvl": ("Specify debug level", "int", "store", 0),
"debugmpi": ("Enable MPI level debugging", None, "store_true", False),
"dry-run": ("Dry run mode, just print command that will be executed", None, 'store_true', False, 'D'),
"double": ("Run double the amount of processes (equivalent to --multi 2)", None, "store_true", False),
"hybrid": ("Run in hybrid mode, specify number of processes per node.", "int", "store", None, 'h'),
"launcher": ("The launcher to be used by Hydra (used in recent Intel MPI versions (> 4.1))"
"for example: ssh, pbsdsh, ..", "str", "store", None),
"logtofile": ("redirect the logging of mympirun to a file (instead of stdout/stderr)",
"str", "store", None),
"mpdbootverbose": ("Run verbose mpdboot", None, "store_true", False),
"mpirunoptions": ("String with options to pass to mpirun (will be appended to generate command)",
"str", "store", None),
"multi": ("Run the amount of processes multiplied by the given integer", "int", "store", None),
"noenvmodules": ("Don't pass the environment modules variables",
None, "store_true", False),
"order": ("Reorder the generated nodelist (default: normal. supports: sort, random[_<seed>])",
"str", "store", None),
"output": ("redirect the output of mpirun to a file (instead of stdout/stderr)",
"str", "store", None),
"output-check-timeout": ("Warn when no stdout/stderr was seen after start (in seconds; negative number "
"disables this test", "int", "store", DEFAULT_TIMEOUT),
"output-check-fatal": ("Exit with code %s instead of warn in case of output check timeout" % TIMEOUT_CODE,
None, "store_true", False),
"overridepin": (("Let mympriun set the affinity (default: disabled, left over to MPI implementation). "
"Supported types: 'compact','spread','cycle' (add 'pin' postfix for single core pinning, "
"e.g. 'cyclepin')."), "str", "store", None),
# don't set it by default. It will be set if needed (eg ipath)
"pinmpi": ("Disable MPI pinning", None, "store_true", True),
"rdma": ("Force rdma device", None, "store_true", None),
"schedtype": ("Specify scheduler (eg local, pbs...; will try to guess by default).",
"str", "store", None, "S"),
"setmpi": ("Specify MPI flavor (eg mpich2, openmpi...; will try to guess by default).",
"str", "store", None, "M"),
"showmpi": ("Print the known MPI classes and exit", None, "store_true", False, 'm'),
"showsched": ("Print the known Sched classes and exit", None, "store_true", False, 's'),
"sockets-per-node": ("Number of sockets per node (default: 0, i.e. try to detect #sockets "
"from /proc/cpuinfo)", "int", "store", 0),
"ssh": ("Force ssh for mpd startup (will try to use optimised method by default)",
None, "store_false", True),
"stats": ("Set MPI statistics level", "int", "store", 0),
"universe": (("Start only this number of processes instead of all (e.g. for MPI_Spawn) Total size of the "
"universe is all requested processes.)"), "int", "store", None),
'use_psm': ("Use Performance Scaled Messaging", None, "store_true", None),
"variablesprefix": (("Comma-separated list of exact names or prefixes to match environment variables "
"(<prefix>_ should match) to pass through."), "string", "extend", []),
}
descr = ["mympirun options", "General advanced mympirun options"]
prefix = ''
self.log.debug("Add advanced option parser: options %s, description %s, prefix %s", opts, descr, prefix)
self.add_group_parser(opts, descr, prefix=prefix)
# for all MPI classes, get the additional options
for mpi in get_subclasses(MPI):
if mpi.RUNTIMEOPTION is not None:
# don't try to add the same set of options twice (based on prefix)
prefix = mpi.RUNTIMEOPTION['prefix']
if prefix not in self.dict_by_prefix():
opts = mpi.RUNTIMEOPTION['options']
descr = mpi.RUNTIMEOPTION['description']
#.........这里部分代码省略.........
开发者ID:hpcugent,项目名称:vsc-mympirun,代码行数:101,代码来源:option.py
注:本文中的vsc.utils.missing.get_subclasses函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论