text stringlengths 0 828 |
|---|
dst_file.write(raw) |
dst_file.close()" |
1317,"def compile_dir(env, src_path, dst_path, pattern=r'^.*\.html$', encoding='utf-8', base_dir=None): |
""""""Compiles a directory of Jinja2 templates to python code. |
:param env: a Jinja2 Environment instance. |
:param src_path: path to the source directory. |
:param dst_path: path to the destination directory. |
:param encoding: template encoding. |
:param base_dir: the base path to be removed from the compiled template filename. |
"""""" |
from os import path, listdir, mkdir |
file_re = re.compile(pattern) |
if base_dir is None: |
base_dir = src_path |
for filename in listdir(src_path): |
src_name = path.join(src_path, filename) |
dst_name = path.join(dst_path, filename) |
if path.isdir(src_name): |
mkdir(dst_name) |
compile_dir(env, src_name, dst_name, encoding=encoding, base_dir=base_dir) |
elif path.isfile(src_name) and file_re.match(filename): |
compile_file(env, src_name, dst_name, encoding=encoding, base_dir=base_dir)" |
1318,"def _pre_dump(cls): |
""""""Output all recorded stats"""""" |
shutil.rmtree(cls.outdir, ignore_errors=True) |
os.makedirs(cls.outdir) |
super(PlotMetric, cls)._pre_dump()" |
1319,"def _histogram(self, which, mu, sigma, data): |
""""""plot a histogram. For internal use only"""""" |
weights = np.ones_like(data)/len(data) # make bar heights sum to 100% |
n, bins, patches = plt.hist(data, bins=25, weights=weights, facecolor='blue', alpha=0.5) |
plt.title(r'%s %s: $\mu=%.2f$, $\sigma=%.2f$' % (self.name, which.capitalize(), mu, sigma)) |
plt.xlabel('Items' if which == 'count' else 'Seconds') |
plt.ylabel('Frequency') |
plt.gca().yaxis.set_major_formatter(FuncFormatter(lambda y, position: ""{:.1f}%"".format(y*100)))" |
1320,"def _scatter(self): |
""""""plot a scatter plot of count vs. elapsed. For internal use only"""""" |
plt.scatter(self.count_arr, self.elapsed_arr) |
plt.title('{}: Count vs. Elapsed'.format(self.name)) |
plt.xlabel('Items') |
plt.ylabel('Seconds')" |
1321,"def bind(self, __fun, *args, **kwargs): |
"""""" |
Bind a worker function to the future. This worker function will be |
executed when the future is executed. |
"""""" |
with self._lock: |
if self._running or self._completed or self._cancelled: |
raise RuntimeError('Future object can not be reused') |
if self._worker: |
raise RuntimeError('Future object is already bound') |
self._worker = functools.partial(__fun, *args, **kwargs) |
return self" |
1322,"def add_done_callback(self, fun): |
"""""" |
Adds the callback *fun* to the future so that it be invoked when the |
future completed. The future completes either when it has been completed |
after being started with the :meth:`start` method (independent of whether |
an error occurs or not) or when either :meth:`set_result` or |
:meth:`set_exception` is called. |
If the future is already complete, *fun* will be invoked directly. |
The function *fun* must accept the future as its sole argument. |
"""""" |
with self._lock: |
if self._completed: |
fun() |
else: |
self._done_callbacks.append(fun)" |
1323,"def enqueue(self): |
"""""" |
Mark the future as being enqueued in some kind of executor for futures. |
Calling :meth:`start()` with the *as_thread* parameter as :const:`True` |
will raise a :class:`RuntimeError` after this method has been called. |
This method will also validate the state of the future. |
"""""" |
with self._lock: |
if self._enqueued: |
raise RuntimeError('Future object is already enqueued') |
if self._running: |
raise RuntimeError('Future object is already running') |
if self._completed: |
raise RuntimeError('Future object can not be restarted') |
if not self._worker: |
raise RuntimeError('Future object is not bound') |
self._enqueued = True" |
1324,"def start(self, as_thread=True): |
"""""" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.