text stringlengths 0 93.6k |
|---|
Returns self to facilitate chaining method calls |
""" |
# self.tasks.append({'task': task, 'inputs': inputs, 'outputs': outputs}) |
self.tasks.append(Task(fn, inputs, outputs)) |
return self |
def add_hook_point(self, name): |
""" |
Adds a point in the workflow where hook functions can be added. |
Implemented as a special type of task that takes full workspace as its |
input and returns a modified workspace |
""" |
self.tasks.append(Hook(name)) |
return self |
def add_hook(self, name, function): |
""" |
Adds a function to be called for hook of a given name. |
The function gets entire workspace as input and |
does not return anything. |
Example: |
def hook_fcn(workspace): |
pass |
""" |
if not callable(function): |
return ValueError('Hook function should be callable') |
if name not in self.hooks: |
self.hooks[name] = [] |
self.hooks[name].append(function) |
return self |
def __call__(self, workspace={}): |
""" |
Executes all the queued tasks in order and returns |
new workspace with results |
""" |
result = workspace |
for i, task in enumerate(self.tasks): |
# Check if task is a hook point |
if isinstance(task, Hook): |
result = run_hook(task, result, self.hooks) |
continue |
try: |
result = run_task(task, result) |
except Exception: |
print('Validation failed on task number %d' % i) |
raise |
return result |
def __repr__(self): |
return '<%s with %d tasks>' \ |
% (self.__class__.__name__, len(self.tasks)) |
# <FILESEP> |
#!/usr/bin/python |
import re |
from decimal import Decimal |
from itertools import chain |
import pywikibot |
from pywikibot import Coordinate, WbMonolingualText, WbQuantity, WbTime |
from pywikibot.exceptions import ( |
APIError, |
NoWikibaseEntityError, |
OtherPageSaveError, |
WikiBaseError, |
) |
from pywikibot.page import Property |
from wikidata import WikidataEntityBot |
class QuickStatementsBot(WikidataEntityBot): |
decimal_pattern = r'[+-]?(?:[1-9]\d*|0)(?:\.\d+)?' |
def __init__(self, generator, **kwargs): |
self.available_options.update({ |
'always': True, |
'noresolve': False, |
}) |
super().__init__(**kwargs) |
self.generator = generator |
self.globeR = re.compile(r'@({0})/({0})'.format(self.decimal_pattern)) |
self.quantity_errR = re.compile( |
r'({0})(?:~({0}))?(?:U([1-9]\d*))?' |
.format(self.decimal_pattern)) |
self.quantity_boundsR = re.compile( |
r'({0})(?:\[({0}),({0})\])(?:U([1-9]\d*))?' |
.format(self.decimal_pattern)) |
self.commentR = re.compile(r' */\*(.*?)\*/$') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.