Unnamed: 0 int64 0 389k | code stringlengths 26 79.6k | docstring stringlengths 1 46.9k |
|---|---|---|
21,300 | def template_statemgr_yaml(cl_args, zookeepers):
statemgr_config_file_template = "%s/standalone/templates/statemgr.template.yaml" \
% cl_args["config_path"]
statemgr_config_file_actual = "%s/standalone/statemgr.yaml" % cl_args["config_path"]
template_file(statemgr_config_file... | Template statemgr.yaml |
21,301 | def get_file_size(fileobj):
currpos = fileobj.tell()
fileobj.seek(0, 2)
total_size = fileobj.tell()
fileobj.seek(currpos)
return total_size | Returns the size of a file-like object. |
21,302 | def pool_context(*args, **kwargs):
pool = Pool(*args, **kwargs)
try:
yield pool
except Exception as e:
raise e
finally:
pool.terminate() | Context manager for multiprocessing.Pool class (for compatibility with Python 2.7.x) |
21,303 | def dist_hamming(src, tar, diff_lens=True):
return Hamming().dist(src, tar, diff_lens) | Return the normalized Hamming distance between two strings.
This is a wrapper for :py:meth:`Hamming.dist`.
Parameters
----------
src : str
Source string for comparison
tar : str
Target string for comparison
diff_lens : bool
If True (default), this returns the Hamming di... |
21,304 | def set_target(self, target: EventDispatcherBase) -> None:
if self._target is not None:
raise PermissionError("The target property already has a valid value.")
if not isinstance(target, EventDispatcherBase):
raise TypeError("Invalid target type: {}".format(target)... | This method should be called by the event dispatcher that dispatches this event
to set its target property.
Args:
target (EventDispatcherBase): The event dispatcher that will dispatch this event.
Raises:
PermissionError: If the target property of the event has al... |
21,305 | def modify_conf(cfgfile, service_name, outfn):
if not cfgfile or not outfn:
print()
sys.exit(0)
options = service_options[service_name]
with open(cfgfile, ) as cf:
lines = cf.readlines()
for opt in options:
op = opt.get()
res = [line for line in lines if l... | Modify config file neutron and keystone to include enabler options. |
21,306 | def get_sample_times(self):
if self._epoch is None:
return Array(range(len(self))) * self._delta_t
else:
return Array(range(len(self))) * self._delta_t + float(self._epoch) | Return an Array containing the sample times. |
21,307 | def run(self, data_dir=None):
if data_dir:
centinel_home = data_dir
self.config[][] = os.path.join(centinel_home,
)
logging.info()
if not os.path.exists(self.config[][]):
loggin... | Note: this function will check the experiments directory for a
special file, scheduler.info, that details how often each
experiment should be run and the last time the experiment was
run. If the time since the experiment was run is shorter than
the scheduled interval in seconds, then the... |
21,308 | def from_path(path: str, encoding: str = , **kwargs) -> BELGraph:
log.info(, path)
graph = BELGraph(path=path)
with codecs.open(os.path.expanduser(path), encoding=encoding) as lines:
parse_lines(graph=graph, lines=lines, **kwargs)
return graph | Load a BEL graph from a file resource. This function is a thin wrapper around :func:`from_lines`.
:param path: A file path
:param encoding: the encoding to use when reading this file. Is passed to :code:`codecs.open`. See the python
`docs <https://docs.python.org/3/library/codecs.html#standard-encodings>`... |
21,309 | def compute_bleu(reference_corpus, translation_corpus, max_order=4,
smooth=False):
matches_by_order = [0] * max_order
possible_matches_by_order = [0] * max_order
reference_length = 0
translation_length = 0
for (references, translation) in zip(reference_corpus,
... | Computes BLEU score of translated segments against one or more references.
Args:
reference_corpus: list of lists of references for each translation. Each
reference should be tokenized into a list of tokens.
translation_corpus: list of translations to score. Each translation
should be tokenize... |
21,310 | def batch_means(x, f=lambda y: y, theta=.5, q=.95, burn=0):
try:
import scipy
from scipy import stats
except ImportError:
raise ImportError()
x = x[burn:]
n = len(x)
b = np.int(n ** theta)
a = n / b
t_quant = stats.t.isf(1 - q, a - 1)
Y = np.array([np.m... | TODO: Use Bayesian CI.
Returns the half-width of the frequentist confidence interval
(q'th quantile) of the Monte Carlo estimate of E[f(x)].
:Parameters:
x : sequence
Sampled series. Must be a one-dimensional array.
f : function
The MCSE of E[f(x)] will be computed.... |
21,311 | def execute_api_request(self):
if not self.auth.check_auth():
raise Exception()
if self.auth.is_authentified():
id_cookie = {BboxConstant.COOKIE_BBOX_ID: self.auth.get_cookie_id()}
if self.parameters is None:
resp = self.call_method(self.api_u... | Execute the request and return json data as a dict
:return: data dict |
21,312 | def reset_can(self, channel=Channel.CHANNEL_CH0, flags=ResetFlags.RESET_ALL):
UcanResetCanEx(self._handle, channel, flags) | Resets a CAN channel of a device (hardware reset, empty buffer, and so on).
:param int channel: CAN channel, to be reset (:data:`Channel.CHANNEL_CH0` or :data:`Channel.CHANNEL_CH1`).
:param int flags: Flags defines what should be reset (see enum :class:`ResetFlags`). |
21,313 | def GET_getitemvalues(self) -> None:
for item in state.getitems:
for name, value in item.yield_name2value(state.idx1, state.idx2):
self._outputs[name] = value | Get the values of all |Variable| objects observed by the
current |GetItem| objects.
For |GetItem| objects observing time series,
|HydPyServer.GET_getitemvalues| returns only the values within
the current simulation period. |
21,314 | def get_extrapolated_conductivity(temps, diffusivities, new_temp, structure,
species):
return get_extrapolated_diffusivity(temps, diffusivities, new_temp) \
* get_conversion_factor(structure, species, new_temp) | Returns extrapolated mS/cm conductivity.
Args:
temps ([float]): A sequence of temperatures. units: K
diffusivities ([float]): A sequence of diffusivities (e.g.,
from DiffusionAnalyzer.diffusivity). units: cm^2/s
new_temp (float): desired temperature. units: K
structure (... |
21,315 | def update_meta_data_for_state_view(graphical_editor_view, state_v, affects_children=False, publish=True):
from gaphas.item import NW
update_meta_data_for_port(graphical_editor_view, state_v, None)
if affects_children:
update_meta_data_for_name_view(graphical_editor_view, state_v.name_vi... | This method updates the meta data of a state view
:param graphical_editor_view: Graphical Editor view the change occurred in
:param state_v: The state view which has been changed/moved
:param affects_children: Whether the children of the state view have been resized or not
:param publish: Whether to pu... |
21,316 | def read_pandas (self, format=, **kwargs):
import pandas
reader = getattr (pandas, + format, None)
if not callable (reader):
raise PKError (,
format, format)
with self.open () as f:
return reader (f, **kwargs) | Read using :mod:`pandas`. The function ``pandas.read_FORMAT`` is called
where ``FORMAT`` is set from the argument *format*. *kwargs* are
passed to this function. Supported formats likely include
``clipboard``, ``csv``, ``excel``, ``fwf``, ``gbq``, ``html``,
``json``, ``msgpack``, ``pickl... |
21,317 | def patch_wheel(in_wheel, patch_fname, out_wheel=None):
in_wheel = abspath(in_wheel)
patch_fname = abspath(patch_fname)
if out_wheel is None:
out_wheel = in_wheel
else:
out_wheel = abspath(out_wheel)
if not exists(patch_fname):
raise ValueError("patch file {0} does not e... | Apply ``-p1`` style patch in `patch_fname` to contents of `in_wheel`
If `out_wheel` is None (the default), overwrite the wheel `in_wheel`
in-place.
Parameters
----------
in_wheel : str
Filename of wheel to process
patch_fname : str
Filename of patch file. Will be applied with ... |
21,318 | def show_system_info_output_show_system_info_stack_mac(self, **kwargs):
config = ET.Element("config")
show_system_info = ET.Element("show_system_info")
config = show_system_info
output = ET.SubElement(show_system_info, "output")
show_system_info = ET.SubElement(output, "... | Auto Generated Code |
21,319 | def time_stops(self):
if not self.supports_time:
return []
if self.service.calendar == :
units = self.service.time_interval_units
interval = self.service.time_interval
steps = [self.time_start]
if units in (, , ):
if... | Valid time steps for this service as a list of datetime objects. |
21,320 | def gene_id_of_associated_transcript(effect):
return apply_to_transcript_if_exists(
effect=effect,
fn=lambda t: t.gene_id,
default=None) | Ensembl gene ID of transcript associated with effect, returns
None if effect does not have transcript. |
21,321 | def create_trace(
turn_activity: Activity,
name: str,
value: object = None,
value_type: str = None,
label: str = None,
) -> Activity:
from_property = (
ChannelAccount(
id=turn_activity.recipient.id, name=turn_activity.recipient.na... | Creates a trace activity based on this activity.
:param turn_activity:
:type turn_activity: Activity
:param name: The value to assign to the trace activity's <see cref="Activity.name"/> property.
:type name: str
:param value: The value to assign to the trace activity's <see cref... |
21,322 | def or_(self, first_qe, *qes):
$orageage
res = first_qe
for qe in qes:
res = (res | qe)
self.filter(res)
return self | Add a $not expression to the query, negating the query expressions
given. The ``| operator`` on query expressions does the same thing
**Examples**: ``query.or_(SomeDocClass.age == 18, SomeDocClass.age == 17)`` becomes ``{'$or' : [{ 'age' : 18 }, { 'age' : 17 }]}``
:param query_exp... |
21,323 | def claim_pep_node(self, node_namespace, *,
register_feature=True, notify=False):
if node_namespace in self._pep_node_claims:
raise RuntimeError(
"claiming already claimed node"
)
registered_node = RegisteredPEPNode(
sel... | Claim node `node_namespace`.
:param node_namespace: the pubsub node whose events shall be
handled.
:param register_feature: Whether to publish the `node_namespace`
as feature.
:param notify: Whether to register the ``+notify`` feature to
receive notification ... |
21,324 | def enable(profile=):
*
cmd = [, , , profile, , ]
ret = __salt__[](cmd, python_shell=False, ignore_retcode=True)
if ret[] != 0:
raise CommandExecutionError(ret[])
return True | .. versionadded:: 2015.5.0
Enable firewall profile
Args:
profile (Optional[str]): The name of the profile to enable. Default is
``allprofiles``. Valid options are:
- allprofiles
- domainprofile
- privateprofile
- publicprofile
Returns:
... |
21,325 | def logical_chassis_fwdl_status_output_cluster_fwdl_entries_fwdl_entries_message(self, **kwargs):
config = ET.Element("config")
logical_chassis_fwdl_status = ET.Element("logical_chassis_fwdl_status")
config = logical_chassis_fwdl_status
output = ET.SubElement(logical_chassis_fwd... | Auto Generated Code |
21,326 | def issue_funds(ctx, amount=, rtgs_hash=, returns=STATUS):
"In the IOU fungible the supply is set by Issuer, who issue funds."
ctx.accounts[ctx.msg_sender] += amount
ctx.issued_amounts[ctx.msg_sender] += amount
ctx.Issuance(ctx.msg_sender, rtgs_hash, amount)
ret... | In the IOU fungible the supply is set by Issuer, who issue funds. |
21,327 | def select_point(action, action_space, select_point_act, screen):
select = spatial(action, action_space).unit_selection_point
screen.assign_to(select.selection_screen_coord)
select.type = select_point_act | Select a unit at a point. |
21,328 | def patch(self, url, data=None, **kwargs):
return self.oauth_request(url, , data=data, **kwargs) | Shorthand for self.oauth_request(url, 'patch')
:param str url: url to send patch oauth request to
:param dict data: patch data to update the service
:param kwargs: extra params to send to request api
:return: Response of the request
:rtype: requests.Response |
21,329 | def dump_registers(cls, registers, arch = None):
if registers is None:
return
if arch is None:
if in registers:
arch = win32.ARCH_I386
elif in registers:
arch = win32.ARCH_AMD64
else:
arch =
... | Dump the x86/x64 processor register values.
The output mimics that of the WinDBG debugger.
@type registers: dict( str S{->} int )
@param registers: Dictionary mapping register names to their values.
@type arch: str
@param arch: Architecture of the machine whose registers were... |
21,330 | def read_midc_raw_data_from_nrel(site, start, end):
args = {: site,
: start.strftime(),
: end.strftime()}
endpoint =
url = endpoint + .join([.format(k, v) for k, v in args.items()])
return read_midc(url, raw_data=True) | Request and read MIDC data directly from the raw data api.
Parameters
----------
site: string
The MIDC station id.
start: datetime
Start date for requested data.
end: datetime
End date for requested data.
Returns
-------
data:
Dataframe with DatetimeInde... |
21,331 | def is_github_repo_owner_the_official_one(context, repo_owner):
official_repo_owner = context.config[]
if not official_repo_owner:
raise ConfigError(
.format(official_repo_owner)
)
return official_repo_owner == repo_owner | Given a repo_owner, check if it matches the one configured to be the official one.
Args:
context (scriptworker.context.Context): the scriptworker context.
repo_owner (str): the repo_owner to verify
Raises:
scriptworker.exceptions.ConfigError: when no official owner was defined
Ret... |
21,332 | def Scale(self, factor):
new = self.Copy()
new.xs = [x * factor for x in self.xs]
return new | Multiplies the xs by a factor.
factor: what to multiply by |
21,333 | def login(self, email=None, password=None, user=None):
if user is not None:
data = {: user, : password}
elif email is not None:
data = {: email, : password}
else:
raise ValueError()
self.headers = {: }
response = self.post(, **data)
... | Logs the user in and setups the header with the private token
:param email: Gitlab user Email
:param user: Gitlab username
:param password: Gitlab user password
:return: True if login successful
:raise: HttpError
:raise: ValueError |
21,334 | def get_copyright_metadata(self):
metadata = dict(self._mdata[])
metadata.update({: self._my_map[]})
return Metadata(**metadata) | Gets the metadata for the copyright.
return: (osid.Metadata) - metadata for the copyright
*compliance: mandatory -- This method must be implemented.* |
21,335 | def download_file_by_name(url, target_folder, file_name, mkdir=False):
__hdr__ = {:
,
:
,
: ,
: ,
: ,
: }
if not os.path.isdir(target_folder):
if mkdir:
preparedir(targe... | Download a file to a directory.
Args:
url: A string to a valid URL.
target_folder: Target folder for download (e.g. c:/ladybug)
file_name: File name (e.g. testPts.zip).
mkdir: Set to True to create the directory if doesn't exist (Default: False) |
21,336 | def validate_properties_exist(self, classname, property_names):
schema_element = self.get_element_by_class_name(classname)
requested_properties = set(property_names)
available_properties = set(schema_element.properties.keys())
non_existent_properties = requested_properties - av... | Validate that the specified property names are indeed defined on the given class. |
21,337 | def _set_platform_specific_keyboard_shortcuts(self):
self.action_new_phrase.setShortcuts(QKeySequence.New)
self.action_save.setShortcuts(QKeySequence.Save)
self.action_close_window.setShortcuts(QKeySequence.Close)
self.action_quit.setShortcuts(QKeySequence.Quit)
self.ac... | QtDesigner does not support QKeySequence::StandardKey enum based default keyboard shortcuts.
This means that all default key combinations ("Save", "Quit", etc) have to be defined in code. |
21,338 | def hgetall(self, name):
with self.pipe as pipe:
f = Future()
res = pipe.hgetall(self.redis_key(name))
def cb():
data = {}
m_decode = self.memberparse.decode
v_decode = self._value_decode
for k, v in re... | Returns all the fields and values in the Hash.
:param name: str the name of the redis key
:return: Future() |
21,339 | def _manual_lookup(self, facebook_id, facebook_id_string):
resp = self._session.get(
% facebook_id,
allow_redirects=True, timeout=10
)
m = _MANUAL_NAME_MATCHER.search(resp.text)
if m:
name = m.group(1)
else:
... | People who we have not communicated with in a long time
will not appear in the look-ahead cache that Facebook keeps.
We must manually resolve them.
:param facebook_id: Profile ID of the user to lookup.
:return: |
21,340 | def _cleanup(self):
self._expkg = None
self._extmp = None
self._flag_e = True
self._ifile.close() | Cleanup after extraction & analysis. |
21,341 | def caldata(self, time):
if time.date() in self.__ocdate[]:
return False
elif time.date() in self.__ocdate[]:
return True
else:
if time.weekday() <= 4:
return True
else:
return False | Market open or not.
:param datetime time: 欲判斷的日期
:rtype: bool
:returns: True 為開市、False 為休市 |
21,342 | def collect(self):
def append_frames(frame_a, frame_b):
return frame_a.append(frame_b)
return self._custom_rdd_reduce(append_frames) | Collect the elements in an PRDD and concatenate the partition. |
21,343 | def OnMouseUp(self, event):
if not self.IsInControl:
self.IsDrag = False
elif self.IsDrag:
if not self.IsDrag:
self.hitIndex = self.HitTest(event.GetPosition())
self.dropIndex = self.hitIndex[0]
... | Generate a dropIndex.
Process: check self.IsInControl, check self.IsDrag, HitTest,
compare HitTest value
The mouse can end up in 5 different places:
Outside the Control
On itself
Above its starting point and on another item
Below its starting point and o... |
21,344 | def do_shell(self, args):
if _debug: ConsoleCmd._debug("do_shell %r", args)
os.system(args) | Pass command to a system shell when line begins with '! |
21,345 | def fanpower_watts(ddtt):
from eppy.bunch_subclass import BadEPFieldError
try:
fan_tot_eff = ddtt.Fan_Total_Efficiency
except BadEPFieldError as e:
fan_tot_eff = ddtt.Fan_Efficiency
pascal = float(ddtt.Pressure_Rise)
if str(ddtt.Maximum_Flow_Rate).lower() == :
re... | return fan power in bhp given the fan IDF object |
21,346 | def addattachments(message, template_path):
if not in message:
return message, 0
message = make_message_multipart(message)
attachment_filepaths = message.get_all(, failobj=[])
template_parent_dir = os.path.dirname(template_path)
for attachment_filepath in attachment_filepaths:
... | Add the attachments from the message from the commandline options. |
21,347 | def protein_subsequences_around_mutations(effects, padding_around_mutation):
protein_subsequences = {}
protein_subsequence_start_offsets = {}
for effect in effects:
protein_sequence = effect.mutant_protein_sequence
if protein_sequence:
mutation_start = effe... | From each effect get a mutant protein sequence and pull out a subsequence
around the mutation (based on the given padding). Returns a dictionary
of subsequences and a dictionary of subsequence start offsets. |
21,348 | def enterEvent(self, event):
if self.__checkable:
not self.__checked and self.setPixmap(self.__hover_pixmap)
else:
self.setPixmap(self.__hover_pixmap) | Reimplements the :meth:`QLabel.enterEvent` method.
:param event: QEvent.
:type event: QEvent |
21,349 | def flags(self, index):
column = index.column()
if index.isValid():
if column in [C.COL_START, C.COL_END]:
return Qt.ItemFlags(Qt.ItemIsEnabled)
else:
return Qt.ItemFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
else:
... | Override Qt method |
21,350 | def resolve_file_path_list(pathlist, workdir, prefix=,
randomize=False):
files = []
with open(pathlist, ) as f:
files = [line.strip() for line in f]
newfiles = []
for f in files:
f = os.path.expandvars(f)
if os.path.isfile(f):
newfiles... | Resolve the path of each file name in the file ``pathlist`` and
write the updated paths to a new file. |
21,351 | def fire_metric(metric_name, metric_value):
metric_value = float(metric_value)
metric = {metric_name: metric_value}
metric_client.fire_metrics(**metric)
return "Fired metric <{}> with value <{}>".format(metric_name, metric_value) | Fires a metric using the MetricsApiClient |
21,352 | def EXP_gas(self, base, exponent):
EXP_SUPPLEMENTAL_GAS = 10
def nbytes(e):
result = 0
for i in range(32):
result = Operators.ITEBV(512, Operators.EXTRACT(e, i * 8, 8) != 0, i + 1, result)
return result
return EXP_SUPPLEMENTAL_GAS ... | Calculate extra gas fee |
21,353 | def _parse_alt_title(html_chunk):
title = html_chunk.find("img", fn=has_param("alt"))
if not title:
raise UserWarning("Can't find alternative title source!")
return title[0].params["alt"].strip() | Parse title from alternative location if not found where it should be.
Args:
html_chunk (obj): HTMLElement containing slice of the page with details.
Returns:
str: Book's title. |
21,354 | def nice_number(number, thousands_separator=, max_ndigits_after_dot=None):
if isinstance(number, float):
if max_ndigits_after_dot is not None:
number = round(number, max_ndigits_after_dot)
int_part, frac_part = str(number).split()
return % (nice_number(int(int_part), thousa... | Return nicely printed number NUMBER in language LN.
Return nicely printed number NUMBER in language LN using
given THOUSANDS_SEPARATOR character.
If max_ndigits_after_dot is specified and the number is float, the
number is rounded by taking in consideration up to max_ndigits_after_dot
digit after t... |
21,355 | def data_properties(data, mask=None, background=None):
from ..segmentation import SourceProperties
segment_image = np.ones(data.shape, dtype=np.int)
return SourceProperties(data, segment_image, label=1, mask=mask,
background=background) | Calculate the morphological properties (and centroid) of a 2D array
(e.g. an image cutout of an object) using image moments.
Parameters
----------
data : array_like or `~astropy.units.Quantity`
The 2D array of the image.
mask : array_like (bool), optional
A boolean mask, with the s... |
21,356 | def set_video_crop(self, x1, y1, x2, y2):
crop = "%s %s %s %s" % (str(x1),str(y1),str(x2),str(y2))
self._player_interface.SetVideoCropPos(ObjectPath(), String(crop)) | Args:
x1 (int): Top left x coordinate (px)
y1 (int): Top left y coordinate (px)
x2 (int): Bottom right x coordinate (px)
y2 (int): Bottom right y coordinate (px) |
21,357 | def gaussian_gradient_magnitude(image, sigma = 5, voxelspacing = None, mask = slice(None)):
r
return _extract_feature(_extract_gaussian_gradient_magnitude, image, mask, sigma = sigma, voxelspacing = voxelspacing) | r"""
Computes the gradient magnitude (edge-detection) of the supplied image using gaussian
derivates and returns the intensity values.
Optionally a binary mask can be supplied to select the voxels for which the feature
should be extracted.
Parameters
----------
image : array_like o... |
21,358 | def param_map_rc_encode(self, target_system, target_component, param_id, param_index, parameter_rc_channel_index, param_value0, scale, param_value_min, param_value_max):
return MAVLink_param_map_rc_message(target_system, target_component, param_id, param_index, parameter_rc_channel_inde... | Bind a RC channel to a parameter. The parameter should change accoding
to the RC channel value.
target_system : System ID (uint8_t)
target_component : Component ID (uint8_t)
param_id : Onboard parameter id, terminated... |
21,359 | def transmute_sites( self, old_site_label, new_site_label, n_sites_to_change ):
selected_sites = self.select_sites( old_site_label )
for site in random.sample( selected_sites, n_sites_to_change ):
site.label = new_site_label
self.site_labels = set( [ site.label for site in s... | Selects a random subset of sites with a specific label and gives them a different label.
Args:
old_site_label (String or List(String)): Site label(s) of the sites to be modified..
new_site_label (String): Site label to be applied to the modified sites.
n_site... |
21,360 | def predict(self, x, distributed=True):
if is_distributed:
if isinstance(x, np.ndarray):
features = to_sample_rdd(x, np.zeros([x.shape[0]]))
elif isinstance(x, RDD):
features = x
else:
raise TypeError("Unsupported predi... | Use a model to do prediction.
# Arguments
x: Input data. A Numpy array or RDD of Sample.
distributed: Boolean. Whether to do prediction in distributed mode or local mode.
Default is True. In local mode, x must be a Numpy array. |
21,361 | def make_graph(pkg):
ignore = [, , , ]
pkg_deps = recursive_dependencies(pkg_resources.Requirement.parse(pkg))
dependencies = {key: {} for key in pkg_deps if key not in ignore}
installed_packages = pkg_resources.working_set
versions = {package.key: package.version for package in installed_pack... | Returns a dictionary of information about pkg & its recursive deps.
Given a string, which can be parsed as a requirement specifier, return a
dictionary where each key is the name of pkg or one of its recursive
dependencies, and each value is a dictionary returned by research_package.
(No, it's not real... |
21,362 | def start(self, ccallbacks=None):
self.__manage_g = gevent.spawn(self.__manage_connections, ccallbacks)
self.__ready_ev.wait() | Establish and maintain connections. |
21,363 | def add_resolved_requirements(self, reqs, platforms=None):
distributions = self._resolve_distributions_by_platform(reqs, platforms=platforms)
locations = set()
for platform, dists in distributions.items():
for dist in dists:
if dist.location not in locations:
self._log.debug(.fo... | Multi-platform dependency resolution for PEX files.
:param builder: Dump the requirements into this builder.
:param interpreter: The :class:`PythonInterpreter` to resolve requirements for.
:param reqs: A list of :class:`PythonRequirement` to resolve.
:param log: Use this logger.
:param platforms: A... |
21,364 | def get_code(self, *args, **kwargs):
callback = self._commands[args[0]]
source = _inspect.getsourcelines(callback)[0]
return "\n" + "".join(source) | get the python source code from callback |
21,365 | def _check_table(self):
cursor = self._db.execute("PRAGMA table_info(%s)"%self.table)
lines = cursor.fetchall()
if not lines:
return True
types = {}
keys = []
for line in lines:
keys.append(line[1])
types[line[1]] ... | Ensure that an incorrect table doesn't exist
If a bad (old) table does exist, return False |
21,366 | def db_type(self, connection):
conn_module = type(connection).__module__
if "mysql" in conn_module:
return "bigint AUTO_INCREMENT"
elif "postgres" in conn_module:
return "bigserial"
return super(BigAutoField, self).db_type(connection) | The type of the field to insert into the database. |
21,367 | def build(self):
pkg_security([self.name])
self.error_uns()
if self.FAULT:
print("")
self.msg.template(78)
print("| Package {0} {1} {2} {3}".format(self.prgnam, self.red,
self.FAULT, self.endc))
... | Only build and create Slackware package |
21,368 | def detect_voice(self, prob_detect_voice=0.5):
assert self.frame_rate in (48000, 32000, 16000, 8000), "Try resampling to one of the allowed frame rates."
assert self.sample_width == 2, "Try resampling to 16 bit."
assert self.channels == 1, "Try resampling to one channel."
class... | Returns self as a list of tuples:
[('v', voiced segment), ('u', unvoiced segment), (etc.)]
The overall order of the AudioSegment is preserved.
:param prob_detect_voice: The raw probability that any random 20ms window of the audio file
contains voice.
:... |
21,369 | def redis_key(cls, key):
keyspace = cls.keyspace
tpl = cls.keyspace_template
key = "%s" % key if keyspace is None else tpl % (keyspace, key)
return cls.keyparse.encode(key) | Get the key we pass to redis.
If no namespace is declared, it will use the class name.
:param key: str the name of the redis key
:return: str |
21,370 | def previous(self, day_of_week=None):
if day_of_week is None:
day_of_week = self.day_of_week
if day_of_week < SUNDAY or day_of_week > SATURDAY:
raise ValueError("Invalid day of week")
dt = self.subtract(days=1)
while dt.day_of_week != day_of_week:
... | Modify to the previous occurrence of a given day of the week.
If no day_of_week is provided, modify to the previous occurrence
of the current day of the week. Use the supplied consts
to indicate the desired day_of_week, ex. pendulum.MONDAY.
:param day_of_week: The previous day of week ... |
21,371 | def cropped(self, t0, t1):
if abs(self.delta*(t1 - t0)) <= 180:
new_large_arc = 0
else:
new_large_arc = 1
return Arc(self.point(t0), radius=self.radius, rotation=self.rotation,
large_arc=new_large_arc, sweep=self.sweep,
end=s... | returns a cropped copy of this segment which starts at
self.point(t0) and ends at self.point(t1). |
21,372 | def add_name(self, tax_id, tax_name, source_name=None, source_id=None,
name_class=, is_primary=False, is_classified=None,
execute=True, **ignored):
assert isinstance(is_primary, bool)
assert is_classified in {None, True, False}
if ignored:
... | Add a record to the names table corresponding to
``tax_id``. Arguments are as follows:
- tax_id (string, required)
- tax_name (string, required)
*one* of the following are required:
- source_id (int or string coercable to int)
- source_name (string)
``source_i... |
21,373 | def play(self, sgffile):
"Play a game"
global verbose
if verbose >= 1:
print "Setting boardsize and komi for black\n"
self.blackplayer.boardsize(self.size)
self.blackplayer.komi(self.komi)
if verbose >= 1:
print "Setting boardsize and komi for wh... | Play a game |
21,374 | def apply_range_set(self, hist: Hist) -> None:
axis = self.axis(hist)
assert not isinstance(self.min_val, float)
assert not isinstance(self.max_val, float)
min_val = self.min_val(axis)
max_val = self.max_val(axis)
... | Apply the associated range set to the axis of a given hist.
Note:
The min and max values should be bins, not user ranges! For more, see the binning
explanation in ``apply_func_to_find_bin(...)``.
Args:
hist: Histogram to which the axis range restriction should be ap... |
21,375 | def _get_support_sound_mode(self):
if self._receiver_type == AVR_X_2016.type:
return self._get_support_sound_mode_avr_2016()
else:
return self._get_support_sound_mode_avr() | Get if sound mode is supported from device.
Method executes the method for the current receiver type. |
21,376 | def delete_lambda_deprecated(awsclient, function_name, s3_event_sources=[],
time_event_sources=[], delete_logs=False):
unwire_deprecated(awsclient, function_name, s3_event_sources=s3_event_sources,
time_event_sources=time_event_sources,
... | Deprecated: please use delete_lambda!
:param awsclient:
:param function_name:
:param s3_event_sources:
:param time_event_sources:
:param delete_logs:
:return: exit_code |
21,377 | def gblocks(self,
new_path = None,
seq_type = or ):
if new_path is None: final = self.__class__(new_temp_path())
else: final = self.__class__(new_path)
orig_name_to_temp = {seq.description: + str(i) for i,seq in enumerat... | Apply the gblocks filtering algorithm to the alignment.
See http://molevol.cmima.csic.es/castresana/Gblocks/Gblocks_documentation.html
Need to rename all sequences, because it will complain with long names. |
21,378 | def next(self):
while True:
if not self._resp:
self._start()
if self._stop:
raise StopIteration
skip, data = self._process_data(next_(self._lines))
if not skip:
break
return data | Handles the iteration by pulling the next line out of the stream,
attempting to convert the response to JSON if necessary.
:returns: Data representing what was seen in the feed |
21,379 | def getobjectsize(self, window_name, object_name=None):
if not object_name:
handle, name, app = self._get_window_handle(window_name)
else:
handle = self._get_object_handle(window_name, object_name)
return self._getobjectsize(handle) | Get object size
@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type... |
21,380 | def revert(self, revision_id):
if self.model is None:
raise MissingModelError()
revision = self.revisions[revision_id]
with db.session.begin_nested():
before_record_revert.send(
current_app._get_current_object(),
record=self
... | Revert the record to a specific revision.
#. Send a signal :data:`invenio_records.signals.before_record_revert`
with the current record as parameter.
#. Revert the record to the revision id passed as parameter.
#. Send a signal :data:`invenio_records.signals.after_record_revert`
... |
21,381 | def potential_from_grid(self, grid):
potential_grid = quad_grid(self.potential_func, 0.0, 1.0, grid,
args=(self.axis_ratio, self.kappa_s, self.scale_radius),
epsrel=1.49e-5)[0]
return potential_grid | Calculate the potential at a given set of arc-second gridded coordinates.
Parameters
----------
grid : grids.RegularGrid
The grid of (y,x) arc-second coordinates the deflection angles are computed on. |
21,382 | def add(self, labels, value):
if type(value) not in (float, int):
raise TypeError("Summary only works with digits (int, float)")
with mutex:
try:
e = self.get_value(labels)
except KeyError:
e = quant... | Add adds a single observation to the summary. |
21,383 | def solution_to_array(solution, events, slots):
array = np.zeros((len(events), len(slots)), dtype=np.int8)
for item in solution:
array[item[0], item[1]] = 1
return array | Convert a schedule from solution to array form
Parameters
----------
solution : list or tuple
of tuples of event index and slot index for each scheduled item
events : list or tuple
of :py:class:`resources.Event` instances
slots : list or tuple
of :py:class:`resources.Slot` i... |
21,384 | def amplification_type(self, channels=None):
if channels is None:
channels = self._channels
channels = self._name_to_index(channels)
if hasattr(channels, ) \
and not isinstance(channels, six.string_types):
return [self... | Get the amplification type used for the specified channel(s).
Each channel uses one of two amplification types: linear or
logarithmic. This function returns, for each channel, a tuple of
two numbers, in which the first number indicates the number of
decades covered by the logarithmic am... |
21,385 | def get_stats_item(self, item):
if isinstance(self.stats, dict):
try:
return self._json_dumps({item: self.stats[item]})
except KeyError as e:
logger.error("Cannot get item {} ({})".format(item, e))
return None
elif isinstan... | Return the stats object for a specific item in JSON format.
Stats should be a list of dict (processlist, network...) |
21,386 | def print_table(self, stream=sys.stdout, filter_function=None):
print(self.to_table(filter_function=filter_function), file=stream) | A pretty ASCII printer for the periodic table, based on some filter_function.
Args:
stream: file-like object
filter_function:
A filtering function that take a Pseudo as input and returns a boolean.
For example, setting filter_function = lambda p: p.Z_val ... |
21,387 | def bfs(self, root = None, display = None):
if root == None:
root = self.root
if display == None:
display = self.attr[]
self.traverse(root, display, Queue()) | API: bfs(self, root = None, display = None)
Description:
Searches tree starting from node named root using breadth-first
strategy if root argument is provided. Starts search from root node
of the tree otherwise.
Pre:
Node indicated by root argument should ... |
21,388 | def _mb_model(self, beta, mini_batch):
Y = np.array(self.data[self.max_lag:])
sample = np.random.choice(len(Y), mini_batch, replace=False)
Y = Y[sample]
X = self.X[:, sample]
z = np.array([self.latent_variables.z_list[k].prior.transform(beta[k]) for k i... | Creates the structure of the model (model matrices etc) for mini batch model
Parameters
----------
beta : np.ndarray
Contains untransformed starting values for the latent variables
mini_batch : int
Mini batch size for the data sampling
Returns
-... |
21,389 | def iter_node(node, name=, unknown=None,
list=list, getattr=getattr, isinstance=isinstance,
enumerate=enumerate, missing=NonExistent):
fields = getattr(node, , None)
if fields is not None:
for name in fields:
value = getattr(node, name, missing... | Iterates over an object:
- If the object has a _fields attribute,
it gets attributes in the order of this
and returns name, value pairs.
- Otherwise, if the object is a list instance,
it returns name, value pairs for each item
in the list, where the name is passed int... |
21,390 | def name(self):
name = self._platform_impl.get_process_name()
if os.name == :
try:
cmdline = self.cmdline
except AccessDenied:
pass
else:
if cmdline:
... | The process name. |
21,391 | def create_api_handler(self):
try:
self.github = github3.login(username=config.data[],
password=config.data[])
except KeyError as e:
raise config.NotConfigured(e)
logger.info("ratelimit remaining: {}".format(self.github.ratelim... | Creates an api handler and sets it on self |
21,392 | def _find_free_location(self, free_locations, required_sectors=1, preferred=None):
if preferred and all(free_locations[preferred:preferred+required_sectors]):
return preferred
i = 2
while i < len(free_l... | Given a list of booleans, find a list of <required_sectors> consecutive True values.
If no such list is found, return length(free_locations).
Assumes first two values are always False. |
21,393 | def on_path(self, new):
self.name = basename(new)
self.graph = self.editor_input.load() | Handle the file path changing. |
21,394 | def rpc_call(self, request, method=None, **payload):
if not method or self.separator not in method:
raise AssertionError("Wrong method name: {0}".format(method))
resource_name, method = method.split(self.separator, 1)
if resource_name not in self.api.resources:
... | Call REST API with RPC force.
return object: a result |
21,395 | def merge_dicts(*dict_list):
all_dicts = []
for ag in dict_list:
if isinstance(ag, dict):
all_dicts.append(ag)
try:
qitem = { k: v for d in all_dicts for k, v in d.items() }
return qitem
except Exception:
return {} | Extract all of the dictionaries from this list, then merge them together |
21,396 | def copy_files(self):
files = [u, u]
this_dir = dirname(abspath(__file__))
for _file in files:
sh.cp(
.format(this_dir, _file),
.format(self.book.local_path)
)
if self.book.meta.rdf_path:
sh.cp(
... | Copy the LICENSE and CONTRIBUTING files to each folder repo
Generate covers if needed. Dump the metadata. |
21,397 | def decode_nibbles(value):
nibbles_with_flag = bytes_to_nibbles(value)
flag = nibbles_with_flag[0]
needs_terminator = flag in {HP_FLAG_2, HP_FLAG_2 + 1}
is_odd_length = flag in {HP_FLAG_0 + 1, HP_FLAG_2 + 1}
if is_odd_length:
raw_nibbles = nibbles_with_flag[1:]
else:
raw_n... | The inverse of the Hex Prefix function |
21,398 | def notify_created(room, event, user):
tpl = get_plugin_template_module(, chatroom=room, event=event, user=user)
_send(event, tpl) | Notifies about the creation of a chatroom.
:param room: the chatroom
:param event: the event
:param user: the user performing the action |
21,399 | def validate_deprecation_semver(version_string, version_description):
if version_string is None:
raise MissingSemanticVersionError(.format(version_description))
if not isinstance(version_string, six.string_types):
raise BadSemanticVersionError(.format(version_description))
try:
v = Versio... | Validates that version_string is a valid semver.
If so, returns that semver. Raises an error otherwise.
:param str version_string: A pantsbuild.pants version which affects some deprecated entity.
:param str version_description: A string used in exception messages to describe what the
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.