code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
lenvec_plus = op.join(out_dir, 'genomic_lenvec.plus') lenvec_minus = op.join(out_dir, 'genomic_lenvec.minus') compute_genomic_cmd = ("compute_genomic_lenvectors " "{bam_in} {lenvec_plus} " "{lenvec_minus} " "{min_len} " ...
def create_features(bam_in, loci_file, reference, out_dir)
Use feature extraction module from CoRaL
2.906762
2.914707
0.997274
logger.info("reading sequeces") data = load_data(args.json) logger.info("create profile") data = make_profile(data, os.path.join(args.out, "profiles"), args) logger.info("create database") make_database(data, "seqcluster.db", args.out) logger.info("Done. Download https://github.com/lp...
def report(args)
Create report in html format
6.963284
7.073503
0.984418
previous = peaks[0] new_peaks = [previous] for pos in peaks: if pos > previous + 10: new_peaks.add(pos) previous = pos return new_peaks
def _summarize_peaks(peaks)
merge peaks position if closer than 10
3.71229
3.258483
1.139269
previous = min(y) peaks = [] intervals = range(x, y, win) for pos in intervals: if y[pos] > previous * 10: previous = y[pos] peaks.add(pos) peaks = _summarize_peaks(peaks)
def find_mature(x, y, win=10)
Window apprach to find hills in the expression profile
5.57384
5.564854
1.001615
keep = Counter() with open_fastq(in_file) as handle: for line in handle: if line.startswith("@"): if line.find("UMI") > -1: logger.info("Find UMI tags in read names, collapsing by UMI.") return collapse_umi(in_file) ...
def collapse(in_file)
collapse identical sequences and keep Q
4.078318
4.006186
1.018005
keep = defaultdict(dict) with open_fastq(in_file) as handle: for line in handle: if line.startswith("@"): m = re.search('UMI_([ATGC]*)', line.strip()) umis = m.group(0) seq = handle.next().strip() handle.next() ...
def collapse_umi(in_file)
collapse reads using UMI tags
3.343557
3.325593
1.005402
_, ext = os.path.splitext(in_file) if ext == ".gz": return gzip.open(in_file, 'rb') if ext in [".fastq", ".fq", ".fasta", ".fa"]: return open(in_file, 'r') return ValueError("File needs to be fastq|fasta|fq|fa [.gz]")
def open_fastq(in_file)
open a fastq file, using gzip if it is gzipped from bcbio package
3.087684
3.081132
1.002126
try: umi_fn = args.fastq if _is_umi(args.fastq): umis = collapse(args.fastq) umi_fn = os.path.join(args.out, splitext_plus(os.path.basename(args.fastq))[0] + "_umi_trimmed.fastq") write_output(umi_fn, umis, args.minimum) seqs = collapse(umi_fn) ...
def collapse_fastq(args)
collapse fasq files after adapter trimming
2.749694
2.729586
1.007367
current = 0 num_children = len(doctree.children) while current < num_children: child = doctree.children[current] child.replace_self( child.traverse(no_autoslides_filter) ) if len(doctree.children) == num_children: # nothing removed, increment c...
def filter_doctree_for_slides(doctree)
Given a doctree, remove all non-slide related elements from it.
4.806735
4.400705
1.092265
parent_title_node = node.parent.next_node(nodes.title) nextslide_info = getattr( parent_title_node, 'nextslide_info', (parent_title_node.deepcopy().children, 1), ) nextslide_info = ( nextslide_info[0], nextslide_info[1] + 1, ...
def _make_title_node(self, node, increment=True)
Generate a new title node for ``node``. ``node`` is a ``nextslide`` node. The title will use the node's parent's title, or the title specified as an argument.
3.482329
3.227608
1.078919
if 'theme' in self.attributes: builder.apply_theme( self.attributes['theme'], builder.theme_options, )
def apply(self, builder)
Apply the Slide Configuration to a Builder.
6.983453
6.180555
1.129907
# set up the default conf result = { 'theme': builder.config.slide_theme, 'autoslides': builder.config.autoslides, 'slide_classes': [], } # now look for a slideconf node in the doctree and update the conf if doctree: conf...
def get_conf(cls, builder, doctree=None)
Return a dictionary of slide configuration for this doctree.
4.233522
3.690017
1.147291
COPY_LISTS = ('script_files', 'css_files',) for attr in COPY_LISTS: if attr in context: context[attr] = context[attr][:] return context
def __fix_context(context)
Return a new context dict based on original context. The new context will be a copy of the original, and some mutable members (such as script and css files) will also be copied to prevent polluting shared context.
6.210461
4.143929
1.498689
# Print welcome message msg = bold('Welcome to the Hieroglyph %s quickstart utility.') % ( version(), ) print(msg) msg = print(msg) # set a few defaults that we don't usually care about for Hieroglyph d.update({ 'version': datetime.date.today().strftime('%Y.%m.%d'...
def ask_user(d)
Wrap sphinx.quickstart.ask_user, and add additional questions.
5.227936
4.780658
1.09356
return { 'title': self.title, 'level': self.level, 'content': self.content, 'classes': self.classes, 'slide_classes': self._filter_classes(exclude='content-'), 'content_classes': self._filter_classes(include='content-'), ...
def get_slide_context(self)
Return the context dict for rendering this slide.
4.670915
4.053182
1.152407
if self.builder.config.slide_numbers: self.body.append( '\n<div class="slide-no">%s</div>\n' % (slide_no,), )
def _add_slide_number(self, slide_no)
Add the slide number to the output if enabled.
4.756207
4.015939
1.184332
if self.builder.config.slide_footer: self.body.append( '\n<div class="slide-footer">%s</div>\n' % ( self.builder.config.slide_footer, ), )
def _add_slide_footer(self, slide_no)
Add the slide footer to the output if enabled.
3.73829
3.142128
1.189732
# avoid import cycles :/ from hieroglyph import writer # only reconfigure Sphinx if we're generating HTML if app.builder.name not in HTML_BUILDERS: return if app.config.slide_link_html_to_slides: # add the slide theme dir as a Loader app.builder.templates.loaders.app...
def inspect_config(app)
Inspect the Sphinx configuration and update for slide-linking. If links from HTML to slides are enabled, make sure the sidebar configuration includes the template and add the necessary theme directory as a loader so the sidebar template can be located. If the sidebar configuration already includes ``s...
4.019293
3.590475
1.119432
return builder.get_relative_uri( pagename or builder.current_docname, os.path.join( builder.app.config.slide_relative_path, pagename or builder.current_docname, ))
def slide_path(builder, pagename=None)
Calculate the relative path to the Slides for pagename.
4.267953
3.66732
1.16378
return builder.get_relative_uri( pagename or builder.current_docname, os.path.join( builder.app.config.slide_html_relative_path, pagename or builder.current_docname, ))
def html_path(builder, pagename=None)
Calculate the relative path to the Slides for pagename.
5.022016
3.816942
1.315717
# we can only show the slidelink if we can resolve the filename context['show_slidelink'] = ( app.config.slide_link_html_to_slides and hasattr(app.builder, 'get_outfilename') ) if context['show_slidelink']: context['slide_path'] = slide_path(app.builder, pagename)
def add_link(app, pagename, templatename, context, doctree)
Add the slides link to the HTML context.
5.701555
5.29402
1.07698
# push the existing values onto the Stack self._theme_stack.append( (self.theme, self.theme_options) ) theme_factory = HTMLThemeFactory(self.app) theme_factory.load_additional_themes(self.get_builtin_theme_dirs() + self.config.slide_theme_path) sel...
def apply_theme(self, themename, themeoptions)
Apply a new theme to the document. This will store the existing theme configuration and apply a new one.
5.029773
5.326957
0.944211
super(AbstractSlideBuilder, self).post_process_images(doctree) # figure out where this doctree is in relation to the srcdir relative_base = ( ['..'] * doctree.attributes.get('source')[len(self.srcdir) + 1:].count('/') ) for node in doctree.trav...
def post_process_images(self, doctree)
Pick the best candidate for all image URIs.
4.803202
4.749878
1.011226
metadata = {} metadata_lines = section.split('\n') for line in metadata_lines: colon_index = line.find(':') if colon_index != -1: key = line[:colon_index].strip() val = line[colon_index + 1:].strip() metadata[key] = val return metadata
def parse_metadata(section)
Given the first part of a slide, returns metadata associated with it.
2.013933
1.823405
1.104491
if metadata.get('build_lists') and metadata['build_lists'] == 'true': html = html.replace('<ul>', '<ul class="build">') html = html.replace('<ol>', '<ol class="build">') return html
def postprocess_html(html, metadata)
Returns processed HTML to fit into the slide template format.
3.72619
3.427694
1.087084
if sys.version_info[0] <= 2: checker = get_checker(linter, checker_method.im_class) else: try: checker = get_checker(linter, checker_method.__self__.__class__) except AttributeError: checker = get_checker(linter, get_class(checker_method.__module__, checker_...
def augment_visit(linter, checker_method, augmentation)
Augmenting a visit enables additional errors to be raised (although that case is better served using a new checker) or to suppress all warnings in certain circumstances. Augmenting functions should accept a 'chain' function, which runs the checker method and possibly any other augmentations, and secondly a...
2.690246
2.593904
1.037142
# At some point, pylint started preferring message symbols to message IDs. However this is not done # consistently or uniformly - occasionally there are some message IDs with no matching symbols. # We try to work around this here by suppressing both the ID and the symbol, if we can find it. # This ...
def suppress_message(linter, checker_method, message_id_or_symbol, test_func)
This wrapper allows the suppression of a message if the supplied test function returns True. It is useful to prevent one particular message from being raised in one particular case, while leaving the rest of the messages intact.
5.82231
5.909722
0.985209
q = '''SELECT threat_type,platform_type,threat_entry_type, expires_at < current_timestamp AS has_expired FROM full_hash WHERE value IN ({}) ''' output = [] with self.get_cursor() as dbc: placeholders = ','.join(['?'] * len(hash_values)) db...
def lookup_full_hashes(self, hash_values)
Query DB to see if hash is blacklisted
3.786151
3.64051
1.040006
q = '''SELECT value, MAX(negative_expires_at < current_timestamp) AS negative_cache_expired FROM hash_prefix WHERE cue IN ({}) GROUP BY 1 ''' output = [] with self.get_cursor() as dbc: dbc.execute(q.format(','.join(['?'] * len(cues))), [sqlite3.Binary...
def lookup_hash_prefix(self, cues)
Lookup hash prefixes by cue (first 4 bytes of hash) Returns a tuple of (value, negative_cache_expired).
4.378923
3.475551
1.259922
log.info('Storing full hash %s to list %s with cache duration %s', to_hex(hash_value), str(threat_list), cache_duration) qi = '''INSERT OR IGNORE INTO full_hash (value, threat_type, platform_type, threat_entry_type, malware_threat_type, downloaded_at) ...
def store_full_hash(self, threat_list, hash_value, cache_duration, malware_threat_type)
Store full hash found for the given hash prefix
2.960198
2.971781
0.996102
q = '''DELETE FROM full_hash WHERE expires_at < datetime(current_timestamp, '-{} SECONDS') ''' log.info('Cleaning up full_hash entries expired more than {} seconds ago.'.format(keep_expired_for)) with self.get_cursor() as dbc: dbc.execute(q.format(int(keep_expired_fo...
def cleanup_full_hashes(self, keep_expired_for=(60 * 60 * 12))
Remove long expired full_hash entries.
3.731576
3.261279
1.144206
q = '''SELECT threat_type,platform_type,threat_entry_type FROM threat_list''' output = [] with self.get_cursor() as dbc: dbc.execute(q) for h in dbc.fetchall(): threat_type, platform_type, threat_entry_type = h threat_list = Threat...
def get_threat_lists(self)
Get a list of known threat lists.
3.038681
2.877722
1.055933
q = '''SELECT threat_type,platform_type,threat_entry_type,client_state FROM threat_list''' output = {} with self.get_cursor() as dbc: dbc.execute(q) for h in dbc.fetchall(): threat_type, platform_type, threat_entry_type, client_state = h ...
def get_client_state(self)
Get a dict of known threat lists including clientState values.
3.618584
2.87606
1.258174
q = '''INSERT OR IGNORE INTO threat_list (threat_type, platform_type, threat_entry_type, timestamp) VALUES (?, ?, ?, current_timestamp) ''' params = [threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type...
def add_threat_list(self, threat_list)
Add threat list entry if it does not exist.
3.166385
2.952126
1.072578
log.info('Deleting cached threat list "{}"'.format(repr(threat_list))) q = '''DELETE FROM threat_list WHERE threat_type=? AND platform_type=? AND threat_entry_type=? ''' params = [threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_ty...
def delete_threat_list(self, threat_list)
Delete threat list entry.
3.765919
3.670587
1.025972
q = '''SELECT value FROM hash_prefix WHERE threat_type=? AND platform_type=? AND threat_entry_type=? ORDER BY value ''' params = [threat_list.threat_type, threat_list.platform_type, threat_list.threat_entry_type] with self.get_cursor() as dbc: ...
def hash_prefix_list_checksum(self, threat_list)
Returns SHA256 checksum for alphabetically-sorted concatenated list of hash prefixes
3.272141
3.041309
1.075899
batch_size = 40 q = '''DELETE FROM hash_prefix WHERE threat_type=? AND platform_type=? AND threat_entry_type=? AND value IN ({}) ''' prefixes_to_remove = self.get_hash_prefix_values_to_remove(threat_list, indices) with self.get_cursor() as dbc: ...
def remove_hash_prefix_indices(self, threat_list, indices)
Remove records matching idices from a lexicographically-sorted local threat list.
2.947951
2.90148
1.016016
q = '''SELECT distinct value from hash_prefix''' output = [] with self.get_cursor() as dbc: dbc.execute(q) output = [bytes(r[0]) for r in dbc.fetchall()] return output
def dump_hash_prefix_values(self)
Export all hash prefix values. Returns a list of known hash prefix values
4.924798
4.693357
1.049312
used = False try: # Process all enqueued events, then exit. while True: try: # Get an event request from the queue. method, args, kwargs, response_queue = tk.tk._event_queue.get_nowait() except queue.Empty: # No more e...
def _check_events(tk)
Checks events in the queue on a given Tk instance
3.72766
3.617288
1.030513
try: self.storage.cleanup_full_hashes() self.storage.commit() self._sync_threat_lists() self.storage.commit() self._sync_hash_prefix_cache() except Exception: self.storage.rollback() raise
def update_hash_prefix_cache(self)
Update locally cached threat lists.
5.640396
4.143888
1.361136
client_state = self.storage.get_client_state() self.api_client.fair_use_delay() fh_response = self.api_client.get_full_hashes(hash_prefixes, client_state) # update negative cache for each hash prefix # store full hash (insert or update) with positive cache bumped up ...
def _sync_full_hashes(self, hash_prefixes)
Download full hashes matching hash_prefixes. Also update cache expiration timestamps.
4.345929
4.172034
1.041681
if type(url) is not str: url = url.encode('utf8') if not url.strip(): raise ValueError("Empty input string.") url_hashes = URL(url).hashes try: list_names = self._lookup_hashes(url_hashes) self.storage.commit() except Excep...
def lookup_url(self, url)
Look up specified URL in Safe Browsing threat lists.
4.547139
4.188996
1.085496
full_hashes = list(full_hashes) cues = [fh[0:4] for fh in full_hashes] result = [] matching_prefixes = {} matching_full_hashes = set() is_potential_threat = False # First lookup hash prefixes which match full URL hash for (hash_prefix, negative_ca...
def _lookup_hashes(self, full_hashes)
Lookup URL hash in blacklists Returns names of lists it was found in.
4.398732
4.324175
1.017242
response = self.service.threatLists().list().execute() self.set_wait_duration(response.get('minimumWaitDuration')) return response['threatLists']
def get_threats_lists(self)
Retrieve all available threat lists
7.87182
6.618197
1.189421
request_body = { "client": { "clientId": self.client_id, "clientVersion": self.client_version, }, "listUpdateRequests": [], } for (threat_type, platform_type, threat_entry_type), current_state in client_state.items(): ...
def get_threats_update(self, client_state)
Fetch hash prefixes update for given threat list. client_state is a dict which looks like {(threatType, platformType, threatEntryType): clientState}
3.676455
2.879906
1.276588
request_body = { "client": { "clientId": self.client_id, "clientVersion": self.client_version, }, "clientStates": [], "threatInfo": { "threatTypes": [], "platformTypes": [], "...
def get_full_hashes(self, prefixes, client_state)
Find full hashes matching hash prefixes. client_state is a dict which looks like {(threatType, platformType, threatEntryType): clientState}
2.245175
1.965551
1.142263
for url_variant in self.url_permutations(self.canonical): url_hash = self.digest(url_variant) yield url_hash
def hashes(self)
Hashes of all possible permutations of the URL in canonical form
9.700336
5.429233
1.786686
def full_unescape(u): uu = urllib.unquote(u) if uu == u: return uu else: return full_unescape(uu) def full_unescape_to_bytes(u): uu = urlparse.unquote_to_bytes(u) if uu == u: return uu ...
def canonical(self)
Convert URL to its canonical form.
2.136068
2.091283
1.021415
def url_host_permutations(host): if re.match(r'\d+\.\d+\.\d+\.\d+', host): yield host return parts = host.split('.') l = min(len(parts), 5) if l > 4: yield host for i in range(l - 1): ...
def url_permutations(url)
Try all permutations of hostname and path which can be applied to blacklisted URLs
2.51395
2.462822
1.02076
def normalize(v): # strip trailing .0 or .00 or .0.0 or ... v = re.sub(r'(\.0+)*$', '', v) result = [] for part in v.split('.'): # just digits m = re.match(r'^(\d+)$', part) if m: result.append(int(m.group(1))) ...
def _compare_versions(v1, v2)
Compare two version strings and return -1, 0 or 1 depending on the equality of the subset of matching version numbers. The implementation is inspired by the top answer at http://stackoverflow.com/a/1714190/997768.
1.831004
1.800459
1.016966
m = re.search(r'([<>=]?=?)?\s*([0-9.a-zA-Z]+)', spec) return m.group(2), m.group(1)
def _split_version_specifier(spec)
Splits version specifiers in the form ">= 0.1.2" into ('0.1.2', '>=')
3.881971
3.284639
1.181856
pkg_config_exe = os.environ.get('PKG_CONFIG', None) or 'pkg-config' cmd = '{0} --exists {1}'.format(pkg_config_exe, package).split() return call(cmd) == 0
def exists(package)
Return True if package information is available. If ``pkg-config`` not on path, raises ``EnvironmentError``.
3.117239
3.255038
0.957666
_raise_if_not_exists(package) return _query(package, *_build_options('--libs', static=static))
def libs(package, static=False)
Return the LDFLAGS string returned by pkg-config. The static specifier will also include libraries for static linking (i.e., includes any private libraries).
11.890494
14.841365
0.801173
_raise_if_not_exists(package) result = _query(package, '--print-variables') names = (x.strip() for x in result.split('\n') if x != '') return dict(((x, _query(package, '--variable={0}'.format(x)).strip()) for x in names))
def variables(package)
Return a dictionary of all the variables defined in the .pc pkg-config file of 'package'.
4.441587
3.971601
1.118337
if not exists(package): return False number, comparator = _split_version_specifier(version) modversion = _query(package, '--modversion') try: result = _compare_versions(modversion, number) except ValueError: msg = "{0} is not a correct version specifier".format(version...
def installed(package, version)
Check if the package meets the required version. The version specifier consists of an optional comparator (one of =, ==, >, <, >=, <=) and an arbitrarily long version number separated by dots. The should be as you would expect, e.g. for an installed version '0.1.2' of package 'foo': >>> installed(...
3.094699
2.87994
1.074571
for package in packages.split(): _raise_if_not_exists(package) out = _query(packages, *_build_options('--cflags --libs', static=static)) out = out.replace('\\"', '') result = collections.defaultdict(list) for token in re.split(r'(?<!\\) ', out): key = _PARSE_MAP.get(token[:2])...
def parse(packages, static=False)
Parse the output from pkg-config about the passed package or packages. Builds a dictionary containing the 'libraries', the 'library_dirs', the 'include_dirs', and the 'define_macros' that are presented by pkg-config. *package* is a string with space-delimited package names. The static specifier will a...
4.884425
4.60499
1.060681
'''Send the data over UDP while taking the sample_rate in account The sample rate should be a number between `0` and `1` which indicates the probability that a message will be sent. The sample_rate is also communicated to `statsd` so it knows what multiplier to use. :keyword da...
def send(self, data, sample_rate=None)
Send the data over UDP while taking the sample_rate in account The sample rate should be a number between `0` and `1` which indicates the probability that a message will be sent. The sample_rate is also communicated to `statsd` so it knows what multiplier to use. :keyword data: The dat...
3.853312
2.193792
1.756462
'''Start the timer and store the start time, this can only be executed once per instance It returns the timer instance so it can be chained when instantiating the timer instance like this: ``timer = Timer('application_name').start()``''' assert self._start is None, ( ...
def start(self)
Start the timer and store the start time, this can only be executed once per instance It returns the timer instance so it can be chained when instantiating the timer instance like this: ``timer = Timer('application_name').start()``
9.095167
2.612973
3.480773
'''Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword delta: The time delta (time.time() - time.time()) to report :type delta: float ''' ms = delta ...
def send(self, subname, delta)
Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword delta: The time delta (time.time() - time.time()) to report :type delta: float
4.81349
2.886324
1.667689
'''Send the time that has passed since our last measurement :keyword subname: The subname to report the data to (appended to the client name) :type subname: str ''' t = time.time() response = self.send(subname, t - self._last) self._last = t r...
def intermediate(self, subname)
Send the time that has passed since our last measurement :keyword subname: The subname to report the data to (appended to the client name) :type subname: str
6.963409
2.57597
2.703218
'''Stop the timer and send the total since `start()` was run :keyword subname: The subname to report the data to (appended to the client name) :type subname: str ''' assert self._stop is None, ( 'Unable to stop, the timer is already stopped') self...
def stop(self, subname='total')
Stop the timer and send the total since `start()` was run :keyword subname: The subname to report the data to (appended to the client name) :type subname: str
6.185112
2.622652
2.358342
'''Decorate a function to time the execution The method can be called with or without a name. If no name is given the function defaults to the name of the function. :keyword function_or_name: The name to post to or the function to wrap >>> from statsd import Timer >>> ...
def decorate(self, function_or_name)
Decorate a function to time the execution The method can be called with or without a name. If no name is given the function defaults to the name of the function. :keyword function_or_name: The name to post to or the function to wrap >>> from statsd import Timer >>> timer = Tim...
3.257326
1.467835
2.219136
'''Returns a context manager to time execution of a block of code. :keyword subname: The subname to report data to :type subname: str :keyword class_: The :class:`~statsd.client.Client` subclass to use (e.g. :class:`~statsd.timer.Timer` or :class:`~statsd.counter...
def time(self, subname=None, class_=None)
Returns a context manager to time execution of a block of code. :keyword subname: The subname to report data to :type subname: str :keyword class_: The :class:`~statsd.client.Client` subclass to use (e.g. :class:`~statsd.timer.Timer` or :class:`~statsd.counter.Counter`) ...
3.584112
1.495703
2.396273
'''Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword value: The raw value to send ''' if timestamp is None: ts = int(dt.datetime.now().strftime...
def send(self, subname, value, timestamp=None)
Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword value: The raw value to send
4.652858
3.079849
1.510742
'''Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword value: The gauge value to send ''' name = self._get_name(self.name, subname) self.logger.info(...
def _send(self, subname, value)
Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword value: The gauge value to send
5.875161
2.992109
1.963552
'''Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword value: The gauge value to send ''' assert isinstance(value, compat.NUM_TYPES) return self._sen...
def send(self, subname, value)
Send the data to statsd via self.connection :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword value: The gauge value to send
7.175501
2.795959
2.566382
'''Increment the gauge with `delta` :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword delta: The delta to add to the gauge :type delta: int >>> gauge = Gauge('application_name') >>> gauge.in...
def increment(self, subname=None, delta=1)
Increment the gauge with `delta` :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword delta: The delta to add to the gauge :type delta: int >>> gauge = Gauge('application_name') >>> gauge.increment('ga...
3.967499
1.773543
2.237047
'''Decrement the gauge with `delta` :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword delta: The delta to remove from the gauge :type delta: int >>> gauge = Gauge('application_name') >>> gau...
def decrement(self, subname=None, delta=1)
Decrement the gauge with `delta` :keyword subname: The subname to report the data to (appended to the client name) :type subname: str :keyword delta: The delta to remove from the gauge :type delta: int >>> gauge = Gauge('application_name') >>> gauge.decremen...
4.273195
1.768414
2.416399
''' Set the data ignoring the sign, ie set("test", -1) will set "test" exactly to -1 (not decrement it by 1) See https://github.com/etsy/statsd/blob/master/docs/metric_types.md "Adding a sign to the gauge value will change the value, rather than setting it. ...
def set(self, subname, value)
Set the data ignoring the sign, ie set("test", -1) will set "test" exactly to -1 (not decrement it by 1) See https://github.com/etsy/statsd/blob/master/docs/metric_types.md "Adding a sign to the gauge value will change the value, rather than setting it. gaugor:-10|g ...
9.087666
1.49172
6.092073
'''Get a (sub-)client with a separate namespace This way you can create a global/app based client with subclients per class/function :keyword name: The name to use, if the name for this client was `spam` and the `name` argument is `eggs` than the resulting name will be ...
def get_client(self, name=None, class_=None)
Get a (sub-)client with a separate namespace This way you can create a global/app based client with subclients per class/function :keyword name: The name to use, if the name for this client was `spam` and the `name` argument is `eggs` than the resulting name will be `spa...
5.577327
1.965579
2.837499
'''Shortcut for getting an :class:`~statsd.average.Average` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str ''' return self.get_client(name=name, class_=statsd.Average)
def get_average(self, name=None)
Shortcut for getting an :class:`~statsd.average.Average` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str
6.50479
2.714754
2.396089
'''Shortcut for getting a :class:`~statsd.counter.Counter` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str ''' return self.get_client(name=name, class_=statsd.Counter)
def get_counter(self, name=None)
Shortcut for getting a :class:`~statsd.counter.Counter` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str
5.658897
2.647239
2.13766
'''Shortcut for getting a :class:`~statsd.gauge.Gauge` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str ''' return self.get_client(name=name, class_=statsd.Gauge)
def get_gauge(self, name=None)
Shortcut for getting a :class:`~statsd.gauge.Gauge` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str
5.896401
2.694381
2.188407
'''Shortcut for getting a :class:`~statsd.raw.Raw` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str ''' return self.get_client(name=name, class_=statsd.Raw)
def get_raw(self, name=None)
Shortcut for getting a :class:`~statsd.raw.Raw` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str
6.684026
2.744023
2.435849
'''Shortcut for getting a :class:`~statsd.timer.Timer` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str ''' return self.get_client(name=name, class_=statsd.Timer)
def get_timer(self, name=None)
Shortcut for getting a :class:`~statsd.timer.Timer` instance :keyword name: See :func:`~statsd.client.Client.get_client` :type name: str
5.863096
2.688876
2.1805
r if v_str is None: cls._git_version = None return v_str = v_str.strip() try: version = cls._git_version = tuple( int(x) for x in v_str.split()[2].split('.')[:3]) except Exception: raise ValueError("Could not parse ...
def init_git_version(cls, v_str)
r"""Parse git version string and store the resulting tuple on self. :returns: the parsed version tuple Only the first 3 digits are kept. This is good enough for the few version dependent cases we need, and coarse enough to avoid more complicated parsing. Some real-life examples::...
3.715954
4.485227
0.828487
out = self.log_call(['git', 'ls-remote', remote, ref], cwd=self.cwd, callwith=subprocess.check_output).strip() for sha, fullref in (l.split() for l in out.splitlines()): if fullref == 'refs/heads/' + ref: return...
def query_remote_ref(self, remote, ref)
Query remote repo about given ref. :return: ``('tag', sha)`` if ref is a tag in remote ``('branch', sha)`` if ref is branch (aka "head") in remote ``(None, ref)`` if ref does not exist in remote. This happens notably if ref if a commit sha (they can't be querie...
4.175377
3.793506
1.100664
logger.log(log_level, "%s> call %r", self.cwd, cmd) ret = callwith(cmd, **kw) if callwith == subprocess.check_output: ret = console_to_str(ret) return ret
def log_call(self, cmd, callwith=subprocess.check_call, log_level=logging.DEBUG, **kw)
Wrap a subprocess call with logging :param meth: the calling method to use.
4.414177
5.433329
0.812426
logger.info('Start aggregation of %s', self.cwd) target_dir = self.cwd is_new = not os.path.exists(target_dir) if is_new: self.init_repository(target_dir) self._switch_to_branch(self.target['branch']) for r in self.remotes: self._set_rem...
def aggregate(self)
Aggregate all merges into the target branch If the target_dir doesn't exist, create an empty git repo otherwise clean it, add all remotes , and merge all merges.
4.504878
3.79771
1.186209
logger.info('Checking repo status') status = self.log_call( ['git', 'status', '--porcelain'], callwith=subprocess.check_output, cwd=self.cwd, ) if status: raise DirtyException(status)
def _check_status(self)
Check repo status and except if dirty.
6.80686
5.02035
1.355854
cmd = tuple() for option in FETCH_DEFAULTS: value = merge.get(option, self.defaults.get(option)) if value: cmd += ("--%s" % option, str(value)) return cmd
def _fetch_options(self, merge)
Get the fetch options from the given merge dict.
4.764218
3.973476
1.199005
remotes = self._get_remotes() exising_url = remotes.get(name) if exising_url == url: logger.info('Remote already exists %s <%s>', name, url) return if not exising_url: logger.info('Adding remote %s <%s>', name, url) self.log_call([...
def _set_remote(self, name, url)
Add remote to the repository. It's equivalent to the command git remote add <name> <url> If the remote already exists with an other url, it's removed and added aggain
2.272594
2.229442
1.019356
REPO_RE = re.compile( '^(https://github.com/|git@github.com:)' '(?P<owner>.*?)/(?P<repo>.*?)(.git)?$') PULL_RE = re.compile( '^(refs/)?pull/(?P<pr>[0-9]+)/head$') remotes = {r['name']: r['url'] for r in self.remotes} all_prs = {} for m...
def collect_prs_info(self)
Collect all pending merge PRs info. :returns: mapping of PRs by state
2.309986
2.335198
0.989204
all_prs = self.collect_prs_info() for pr_info in all_prs.get('closed', []): logger.info( '{url} in state {state} ({merged})'.format(**pr_info) )
def show_closed_prs(self)
Log only closed PRs.
5.477186
5.35555
1.022712
for __, prs in self.collect_prs_info().items(): for pr_info in prs: logger.info( '{url} in state {state} ({merged})'.format(**pr_info) )
def show_all_prs(self)
Log all PRs grouped by state.
6.871643
6.009881
1.143391
repo_list = [] for directory, repo_data in config.items(): if not os.path.isabs(directory): directory = os.path.abspath(directory) repo_dict = { 'cwd': directory, 'defaults': repo_data.get('defaults', dict()), 'force': force, } ...
def get_repos(config, force=False)
Return a :py:obj:`list` list of repos from config file. :param config: the repos config in :py:class:`dict` format. :param bool force: Force aggregate dirty repos or not. :type config: dict :rtype: list
2.095239
2.096848
0.999232
if not os.path.exists(config): raise ConfigException('Unable to find configuration file: %s' % config) file_extension = os.path.splitext(config)[1][1:] conf = kaptan.Kaptan(handler=kaptan.HANDLER_EXT.get(file_extension)) if expand_env: with open(config, 'r') as file_handler: ...
def load_config(config, expand_env=False, force=False)
Return repos from a directory and fnmatch. Not recursive. :param config: paths to config file :type config: str :param expand_env: True to expand environment varialbes in the config. :type expand_env: bool :param bool force: True to aggregate even if repo is dirty. :returns: expanded config dic...
4.096
3.921625
1.044465
if not log: log = logging.getLogger() if not log.handlers: channel = logging.StreamHandler() if level == logging.DEBUG: channel.setFormatter(DebugLogFormatter()) else: channel.setFormatter(LogFormatter()) log.setLevel(level) log.addHa...
def setup_logger(log=None, level=logging.INFO)
Setup logging for CLI use. :param log: instance of logger :type log: :py:class:`Logger`
2.450916
2.635969
0.929797
main_parser = argparse.ArgumentParser( formatter_class=argparse.RawTextHelpFormatter) main_parser.add_argument( '-c', '--config', dest='config', type=str, nargs='?', help='Pull the latest repositories from config(s)' ).completer = argcomplete.completers...
def get_parser()
Return :py:class:`argparse.ArgumentParser` instance for CLI.
3.838035
3.770102
1.018019
parser = get_parser() argcomplete.autocomplete(parser, always_complete_options=False) args = parser.parse_args() setup_logger( level=args.log_level ) try: if args.config and \ args.command in \ ('aggregate', 'show-closed-prs', 'show-all-p...
def main()
Main CLI application.
4.605954
4.456965
1.033428
repos = load_config(args.config, args.expand_env) dirmatch = args.dirmatch for repo_dict in repos: r = Repo(**repo_dict) logger.debug('%s' % r) if not match_dir(r.cwd, dirmatch): logger.info("Skip %s", r.cwd) continue r.aggregate() if args...
def load_aggregate(args)
Load YAML and JSON configs and begin creating / updating , aggregating and pushing the repos (deprecated in favor or run())
5.196364
4.646417
1.11836
try: logger.debug('%s' % repo) dirmatch = args.dirmatch if not match_dir(repo.cwd, dirmatch): logger.info("Skip %s", repo.cwd) return if args.command == 'aggregate': repo.aggregate() if args.do_push: repo.push() ...
def aggregate_repo(repo, args, sem, err_queue)
Aggregate one repo according to the args. Args: repo (Repo): The repository to aggregate. args (argparse.Namespace): CLI arguments.
3.212941
3.277561
0.980284
repos = load_config(args.config, args.expand_env, args.force) jobs = max(args.jobs, 1) threads = [] sem = threading.Semaphore(jobs) err_queue = Queue() for repo_dict in repos: if not err_queue.empty(): break sem.acquire() r = Repo(**repo_dict) ...
def run(args)
Load YAML and JSON configs and run the command specified in args.command
3.002118
3.018315
0.994634
if state.reporter.get_errors(): state.do_test(incorrect_msg) return state
def has_no_error( state, incorrect_msg="Your code generated an error. Fix it and try again!" )
Check whether the submission did not generate a runtime error. Simply use ``Ex().has_no_error()`` in your SCT whenever you want to check for errors. By default, after the entire SCT finished executing, ``sqlwhat`` will check for errors before marking the exercise as correct. You can disable this behavior ...
10.734056
16.467579
0.65183
# first check if there is no error has_no_error(state) if not state.solution_result: raise NameError( "You are using has_result() to verify that the student query generated an error, but the solution query did not return a result either!" ) if not state.student_result...
def has_result(state, incorrect_msg="Your query did not return a result.")
Checks if the student's query returned a result. Args: incorrect_msg: If specified, this overrides the automatically generated feedback message in case the student's query did not return a result.
8.834644
8.610726
1.026005
# check that query returned something has_result(state) # assumes that columns cannot be jagged in size n_stu = len(next(iter(state.student_result.values()))) n_sol = len(next(iter(state.solution_result.values()))) if n_stu != n_sol: _msg = state.build_message( incorr...
def has_nrows( state, incorrect_msg="Your query returned a table with {{n_stu}} row{{'s' if n_stu > 1 else ''}} while it should return a table with {{n_sol}} row{{'s' if n_sol > 1 else ''}}.", )
Test whether the student and solution query results have equal numbers of rows. Args: incorrect_msg: If specified, this overrides the automatically generated feedback message in case the number of rows in the student and solution query don't match.
4.464823
4.724498
0.945036
# check that query returned something has_result(state) n_stu = len(state.student_result) n_sol = len(state.solution_result) if n_stu != n_sol: _msg = state.build_message( incorrect_msg, fmt_kwargs={"n_stu": n_stu, "n_sol": n_sol} ) state.do_test(_msg) ...
def has_ncols( state, incorrect_msg="Your query returned a table with {{n_stu}} column{{'s' if n_stu > 1 else ''}} while it should return a table with {{n_sol}} column{{'s' if n_sol > 1 else ''}}.", )
Test whether the student and solution query results have equal numbers of columns. Args: incorrect_msg: If specified, this overrides the automatically generated feedback message in case the number of columns in the student and solution query don't match. :Example: Consi...
3.626486
4.307378
0.841924
if missing_msg is None: missing_msg = "The system wants to verify row {{index + 1}} of your query result, but couldn't find it. Have another look." if expand_msg is None: expand_msg = "Have another look at row {{index + 1}} in your query result. " msg_kwargs = {"index": index} # c...
def check_row(state, index, missing_msg=None, expand_msg=None)
Zoom in on a particular row in the query result, by index. After zooming in on a row, which is represented as a single-row query result, you can use ``has_equal_value()`` to verify whether all columns in the zoomed in solution query result have a match in the student query result. Args: index:...
4.103746
3.983594
1.030162
if missing_msg is None: missing_msg = "We expected to find a column named `{{name}}` in the result of your query, but couldn't." if expand_msg is None: expand_msg = "Have another look at your query result. " msg_kwargs = {"name": name} # check that query returned something has...
def check_column(state, name, missing_msg=None, expand_msg=None)
Zoom in on a particular column in the query result, by name. After zooming in on a column, which is represented as a single-column query result, you can use ``has_equal_value()`` to verify whether the column in the solution query result matches the column in student query result. Args: name: n...
4.904038
4.908629
0.999065
if too_many_cols_msg is None: too_many_cols_msg = ( "Your query result contains the column {{col}} but shouldn't." ) if expand_msg is None: expand_msg = "Have another look at your query result. " child_stu_result = {} child_sol_result = {} for col in state...
def check_all_columns(state, allow_extra=True, too_many_cols_msg=None, expand_msg=None)
Zoom in on the columns that are specified by the solution Behind the scenes, this is using ``check_column()`` for every column that is in the solution query result. Afterwards, it's selecting only these columns from the student query result and stores them in a child state that is returned, so you can ...
3.527079
3.23195
1.091316