def f1(*args1, **kwargs1): """ This function serves to test manually how ips_after_exception behaves :param args1: :param kwargs1: :return: """ ipd.activate_ips_on_exception() x = kwargs1.get("x", 0) print("x=", x) if x > 3: 1/0 else: f2(x)
def handle(self, *args, **options): from ipydex import IPS, activate_ips_on_exception activate_ips_on_exception() buf = StringIO() call_command("dumpdata", stdout=buf) buf.seek(0) data = json.loads(buf.read()) blacklist_re = re.compile("|".join(model_blacklist)) if options.get('backup'): opfname = time.strftime("%Y-%m-%d__%H-%M-%S_backup_all.json") backup_path = settings.BACKUP_PATH if not os.path.exists(backup_path): os.makedirs(backup_path) outputpath = os.path.join(backup_path, opfname) else: outputpath = time.strftime("%Y-%m-%d__%H-%M-%S_all.json") keep_data = [] bad_data = [] for d in data: model = d.get("model") if model is None: continue if blacklist_re.match(model): # just for debugging bad_data.append(model) continue else: keep_data.append(d) # dependency only needed here # todo: properly handle optional dependencies (Milestone 1.0) # noinspection PyPackageRequirements import demjson res = demjson.encode(keep_data, encoding="utf-8", compactly=False) # remove trailing spaces and ensure final linebreak: lb = b"\n" # byte-linebreak res2 = lb.join([line.rstrip() for line in res.split(lb)] + [lb]) # write bytes because we have specified utf8-encoding with open(outputpath, "wb") as jfile: jfile.write(res2) self.stdout.write(f"file written: {outputpath}") self.stdout.write(self.style.SUCCESS('Done'))
import time import os import shutil from ipydex import IPS from splinter import Browser import glob from ipydex import IPS, activate_ips_on_exception activate_ips_on_exception() url = "https://bramp.github.io/js-sequence-diagrams/" download_path = f"{os.environ['HOME']}/Downloads" # splinter: d = dict() d['loggingPrefs'] = {'browser': 'ALL'} options_for_browser = dict(driver_name='chrome', headless=False, desired_capabilities=d) class JS_Diagram_Converter(object): def __init__(self): self.browser = None def _init(self):
#============================================================= # from sympy.physics.vector import init_vprinting, vlatex # init_vprinting(use_latex='mathjax', pretty_print=False) # import ipydex import numpy as np from scipy.optimize import minimize import cfg from sys_model import system_model_generator from myfuncs import sympy_states_to_func from myfuncs import jac_func import ipydex ipydex.activate_ips_on_exception() def interpolation_constrains(z): '''return collocation constrains ''' # k :number of knotes , and n :system dimension k = cfg.pendata.trajectory.k n = cfg.pendata.trajectory.n max_time = cfg.pendata.trajectory.max_time hk = max_time / (k - 1) fxu = cfg.pendata.trajectory.fxu x = z[0:(2 * k - 1) * n].reshape(2 * k - 1, n) x_knot = x[::2] xc = x[1::2]
import unittest from ipydex import displaytools as dt from ipydex import IPS, activate_ips_on_exception activate_ips_on_exception() def bool_sum(x): if x: return 1 else: return 0 # noinspection PyPep8Naming,PyUnresolvedReferences,PyUnusedLocal class Tests(unittest.TestCase): def setUp(self): pass def test_classify_comment(self): c1 = "" r1 = dt.classify_comment(c1) self.assertTrue(r1.empty_comment) # all other flags should be false self.assertEqual(bool_sum(r1.value_list()), 1) c1 = "# nothing special here" r1 = dt.classify_comment(c1) # all flags should be false