text
stringlengths
1
93.6k
pty=True,
)
@fabric.task
def regen_all_api(ctx):
regen_apidoc(ctx, "src/puresnmp", "doc/api")
regen_apidoc(ctx, "src/puresnmp_plugins", "doc/plugins_api", True)
@fabric.task
def doc(ctx):
regen_all_api(ctx)
opts = {
"builddir": "_build",
"sphinx": abspath("env/bin/sphinx-build"),
"apidoc": abspath("env/bin/sphinx-apidoc"),
}
cmd = "{sphinx} -b html -d {builddir}/doctrees . {builddir}/html"
with ctx.cd("doc"):
ctx.run(cmd.format(**opts), replace_env=False, pty=True)
@fabric.task
def develop(ctx):
"""
Set up a development environment
"""
ctx.run("[ -d env ] || python3 -m venv env", replace_env=False)
ctx.run("./env/bin/pip install -U pip", replace_env=False)
ctx.run("./env/bin/pip install -e .[dev,test]", replace_env=False)
# <FILESEP>
import collections
import functools
import os
import pickle
import sys
from datetime import datetime as dt
import numpy as np
_verbose = False
def log(msg):
print("{} {}".format(dt.now().strftime("%Y-%m-%d %H:%M:%S.%f"), msg))
sys.stdout.flush()
def vlog(msg):
if _verbose:
print("{} {}".format(dt.now().strftime("%Y-%m-%d %H:%M:%S"), msg))
sys.stdout.flush()
def flog(msg, outfile):
msg = "{} {}".format(dt.now().strftime("%Y-%m-%d %H:%M:%S"), msg)
print(msg)
sys.stdout.flush()
try:
with open(outfile, "a") as f:
f.write(msg + "\n")
except Exception as e:
log(e)
class memoized(object):
"""Decorator. Caches a function's return value each time it is called.
If called later with the same arguments, the cached value is returned
(not reevaluated).
"""
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
if not isinstance(args, collections.Hashable):
# uncacheable. a list, for instance.
# better to not cache than blow up.
return self.func(*args)
if args in self.cache:
return self.cache[args]
else:
value = self.func(*args)
self.cache[args] = value
return value
def __repr__(self):
"""Return the function's docstring."""
return self.func.__doc__
def __get__(self, obj, objtype):
"""Support instance methods."""
return functools.partial(self.__call__, obj)