本文整理汇总了Python中traitlets.List方法的典型用法代码示例。如果您正苦于以下问题:Python traitlets.List方法的具体用法?Python traitlets.List怎么用?Python traitlets.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traitlets
的用法示例。
在下文中一共展示了traitlets.List方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_check_clusters
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def do_check_clusters(self, clusters):
"""Check the status of multiple clusters.
This is periodically called to check the status of pending clusters.
Once a cluster is running this will no longer be called.
Parameters
----------
clusters : List[Cluster]
The clusters to be checked.
Returns
-------
statuses : List[bool]
The status for each cluster. Return False if the cluster has
stopped or failed, True if the cluster is pending start or running.
"""
raise NotImplementedError
示例2: do_check_workers
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def do_check_workers(self, workers):
"""Check the status of multiple workers.
This is periodically called to check the status of pending workers.
Once a worker is running this will no longer be called.
Parameters
----------
workers : List[Worker]
The workers to be checked.
Returns
-------
statuses : List[bool]
The status for each worker. Return False if the worker has
stopped or failed, True if the worker is pending start or running.
"""
raise NotImplementedError
示例3: _update_atom_colors
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def _update_atom_colors(colors, atoms, styles):
""" Updates list of atoms with the given colors. Colors will be translated to hex.
Args:
color (List[str]): list of colors for each atom
atoms (List[moldesign.Atom]): list of atoms to apply the colors to
styles (dict): old style dictionary
"""
styles = dict(styles)
if len(colors) != len(atoms):
raise ValueError("Number of colors provided does not match number of atoms provided")
for atom, color in zip(atoms, colors):
if str(atom.index) in styles:
styles[str(atom.index)] = dict(styles[str(atom.index)])
else:
styles[str(atom.index)] = {}
styles[str(atom.index)]['color'] = translate_color(color, prefix='#')
return styles
# some convenience synonyms
示例4: _get_changed_cells
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def _get_changed_cells(self, nb: NotebookNode) -> typing.List:
changed = []
for cell in nb.cells:
if not (utils.is_grade(cell) or utils.is_locked(cell)):
continue
# if we're ignoring checksums, then remove the checksum from the
# cell metadata
if self.ignore_checksums and 'checksum' in cell.metadata.nbgrader:
del cell.metadata.nbgrader['checksum']
# verify checksums of cells
if utils.is_locked(cell) and 'checksum' in cell.metadata.nbgrader:
old_checksum = cell.metadata.nbgrader['checksum']
new_checksum = utils.compute_checksum(cell)
if old_checksum != new_checksum:
changed.append(cell)
return changed
示例5: _get_failed_cells
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def _get_failed_cells(self, nb: NotebookNode) -> typing.List[NotebookNode]:
failed = []
for cell in nb.cells:
if not (self.validate_all or utils.is_grade(cell) or utils.is_locked(cell)):
continue
# if it's a grade cell, the check the grade
if utils.is_grade(cell):
score, max_score = utils.determine_grade(cell, self.log)
# it's a markdown cell, so we can't do anything
if score is None:
pass
elif score < max_score:
failed.append(cell)
elif self.validate_all and cell.cell_type == 'code':
for output in cell.outputs:
if output.output_type == 'error':
failed.append(cell)
break
return failed
示例6: _get_passed_cells
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def _get_passed_cells(self, nb: NotebookNode) -> typing.List[NotebookNode]:
passed = []
for cell in nb.cells:
if not (utils.is_grade(cell) or utils.is_locked(cell)):
continue
# if it's a grade cell, the check the grade
if utils.is_grade(cell):
score, max_score = utils.determine_grade(cell, self.log)
# it's a markdown cell, so we can't do anything
if score is None:
pass
elif score == max_score:
passed.append(cell)
return passed
示例7: test_tool_command_line_precedence
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def test_tool_command_line_precedence():
"""
ensure command-line has higher priority than config file
"""
from ctapipe.core.tool import run_tool
class SubComponent(Component):
component_param = Float(10.0, help="some parameter").tag(config=True)
class MyTool(Tool):
description = "test"
userparam = Float(5.0, help="parameter").tag(config=True)
classes = List([SubComponent,])
aliases = Dict({"component_param": "SubComponent.component_param"})
def setup(self):
self.sub = self.add_component(SubComponent(parent=self))
config = Config(
{"MyTool": {"userparam": 12.0}, "SubComponent": {"component_param": 15.0}}
)
tool = MyTool(config=config) # sets component_param to 15.0
run_tool(tool, ["--component_param", "20.0"])
assert tool.sub.component_param == 20.0
assert tool.userparam == 12.0
示例8: set_colors
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def set_colors(self, colormap):
"""
Args:
colormap(Mapping[str,List[Atoms]]): mapping of colors to atoms
"""
for color, atoms in colormap.items():
self.set_color(atoms=atoms, color=color)
示例9: selected_atoms
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def selected_atoms(self):
""" List[moldesign.Atom]: list of selected atoms
"""
return [self.mol.atoms[i] for i in self.selected_atom_indices]
示例10: set_color
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def set_color(self, colors, atoms=None, save=True):
""" Set atom colors
May be called in several different ways:
- ``set_color(color, atoms=list_of_atoms_or_None)``
where all passed atoms are to be colored a single color
- ``set_color(list_of_colors, atoms=list_of_atoms_or_None)``
with a list of colors for each atom
- ``set_color(dict_from_atoms_to_colors)``
a dictionary that maps atoms to colors
- ``set_color(f, atoms=list_of_atoms_or_None)``
where f is a function that maps atoms to colors
Args:
colors (see note for allowable types): list of colors for each atom, or map
from atoms to colors, or a single color for all atoms
atoms (List[moldesign.Atom]): list of atoms (if None, assumed to be mol.atoms; ignored
if a dict is passed for "color")
save (bool): always color these atoms this way (until self.unset_color is called)
See Also:
:method:`GeometryViewer.color_by`` - to automatically color atoms using numerical
and categorical data
"""
if hasattr(colors, 'items'):
atoms, colors = zip(*colors.items())
elif atoms is None:
atoms = self.mol.atoms
if callable(colors):
colors = map(colors, atoms)
elif isinstance(colors, basestring) or not hasattr(colors, '__iter__'):
colors = [colors for atom in atoms]
for atom,color in zip(atoms, colors):
c = translate_color(color, '#')
if save:
self.atom_colors[atom] = c
self.styles[str(atom.index)]['color'] = c
self.send_state('styles')
示例11: unset_color
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def unset_color(self, atoms=None):
""" Resets atoms to their default colors
Args:
atoms (List[moldesign.Atom]): list of atoms to color (if None, this is applied to
all atoms)
"""
if atoms is None:
atoms = self.mol.atoms
for atom in atoms:
self.atom_colors.pop(atom, None)
self.styles[str(atom.index)].pop('color', None)
self.send_state('styles')
示例12: hide
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def hide(self, atoms=None):
""" Make these atoms invisible
Args:
atoms (List[moldesign.Atom]): atoms to apply this style to
(if not passed, uses all atoms)
"""
return self.set_style(None,atoms=atoms)
示例13: _get_type_changed_cells
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def _get_type_changed_cells(self, nb: NotebookNode) -> typing.List[NotebookNode]:
changed = []
for cell in nb.cells:
if not (utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell)):
continue
if 'cell_type' not in cell.metadata.nbgrader:
continue
new_type = cell.metadata.nbgrader.cell_type
old_type = cell.cell_type
if new_type and (old_type != new_type):
changed.append(cell)
return changed
示例14: start
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def start(self):
# check: is there a subapp given?
if self.subapp is None:
print("No assignment command given. List of subcommands:\n")
for key, (app, desc) in self.subcommands.items():
print(" {}\n{}\n".format(key, desc))
# This starts subapps
super(DbAssignmentApp, self).start()
示例15: validate
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import List [as 别名]
def validate(self, filename: str) -> typing.Dict[str, typing.List[typing.Dict[str, str]]]:
self.log.info("Validating '{}'".format(os.path.abspath(filename)))
basename = os.path.basename(filename)
dirname = os.path.dirname(filename)
with utils.chdir(dirname):
nb = read_nb(basename, as_version=current_nbformat)
type_changed = self._get_type_changed_cells(nb)
if len(type_changed) > 0:
results = {}
results['type_changed'] = [{
"source": cell.source.strip(),
"old_type": cell.cell_type,
"new_type": cell.metadata.nbgrader.cell_type
} for cell in type_changed]
return results
with utils.chdir(dirname):
nb = self._preprocess(nb)
changed = self._get_changed_cells(nb)
passed = self._get_passed_cells(nb)
failed = self._get_failed_cells(nb)
results = {}
if not self.ignore_checksums and len(changed) > 0:
results['changed'] = [{
"source": cell.source.strip()
} for cell in changed]
elif self.invert:
if len(passed) > 0:
results['passed'] = [{
"source": cell.source.strip()
} for cell in passed]
else:
if len(failed) > 0:
results['failed'] = [{
"source": cell.source.strip(),
"error": ansi2html(self._extract_error(cell)),
"raw_error": self._extract_error(cell)
} for cell in failed]
return results