def make(ctx, jobs="auto", touch=False, clean=False, binary=""): """ Touch all modified files and recompile the code Args: jobs: Use `jobs` threads for make -jNUM touch: Touch all changed files clean: Issue `make clean` before `make`. binary: Binary to recompile, default: all """ if touch: with cd(ABINIT_ROOTDIR): cmd = "./abisrc.py touch" cprint("Executing: %s" % cmd, "yellow") result = ctx.run(cmd, pty=True) if not result.ok: cprint("`%s` failed. Aborting now!" % cmd, "red") return 1 top = find_top_build_tree(".", with_abinit=False) jobs = max(1, number_of_cpus() // 2) if jobs == "auto" else int(jobs) with cd(top): if clean: ctx.run("cd src && make clean && cd ..", pty=True) ctx.run("cd shared && make clean && cd ..", pty=True) cmd = "make -j%d %s > >(tee -a make.log) 2> >(tee -a make.stderr >&2)" % ( jobs, binary) cprint("Executing: %s" % cmd, "yellow") results = ctx.run(cmd, pty=True)
def env(ctx): """Print sh code to set $PATH and $ABI_PSPDIR in order to work with build directory.""" print("\nExecute the following lines in the shell to set the env:\n") top = find_top_build_tree(".", with_abinit=True) binpath = os.path.join(top, "src", "98_main") print(f"export ABI_PSPDIR={ABINIT_ROOTDIR}/tests/Psps_for_tests") print(f"export PATH={binpath}:$PATH")
def _run(ctx, input_name, exec_name, run_make): """"Execute `exec_name input_name`""" if run_make: make(ctx) top = find_top_build_tree(".", with_abinit=True) binpath = os.path.join(top, "src", "98_main", exec_name) cprint(f"Using binpath: {binpath}", "green") cmd = f"{binpath} {input_name}" cprint(f"Executing {cmd}", color="green") ctx.run(cmd, pty=True)
def make_abinit(num_threads): """ Find the top-level directory of the build tree and issue `make -j num_threads`. Returns: Exit status of the subprocess. """ top = find_top_build_tree(".", with_abinit=False) cmd = "cd %s && make -j%d" % (top, num_threads) return os.system(cmd)
def make_abinit(num_threads, touch_patterns=None): """ Find the top-level directory of the build tree and issue `make -j num_threads`. Returns: Exit status of the subprocess. """ top = find_top_build_tree(".", with_abinit=False) if touch_patterns: abenv.touch_srcfiles( [s.strip() for s in touch_patterns.split(",") if s]) return os.system("cd %s && make -j%d" % (top, num_threads))
def links(ctx): """ Create symbolic links to Abinit executables in current working directory. """ top = find_top_build_tree(".", with_abinit=True) main98 = os.path.join(top, "src", "98_main") for dest in ALL_BINARIES: if os.path.islink(os.path.join(os.getcwd(), dest)): continue source = os.path.join(main98, dest) if os.path.isfile(source): os.symlink(source, dest) else: cprint("Cannot find `%s` in dir `%s" % (source, main98), "yellow")
def lldb(ctx, input_name, exec_name="abinit", run_make=False): """ Execute `lldb` debugger with the given `input_name`. """ if run_make: make(ctx) top = find_top_build_tree(".", with_abinit=True) binpath = os.path.join(top, "src", "98_main", exec_name) cprint(f"Using binpath: {binpath}", "green") cmd = f"lldb {binpath} --one-line 'settings set target.run-args {input_name}'" cprint(f"Executing lldb command: {cmd}", color="green") cprint("Type run to start lldb debugger", color="green") cprint("Then use `bt` to get the backtrace\n\n", color="green") ctx.run(cmd, pty=True)
def make(ctx, jobs="auto", clean=False): """ Touch all modified files and recompile the code with -jNUM. """ with cd(ABINIT_SRCDIR): cmd = "./abisrc.py touch" cprint("Executing: %s" % cmd, "yellow") result = ctx.run(cmd, pty=True) if not result.ok: cprint("`%s` failed. Aborting now!" % cmd, "red") return 1 top = find_top_build_tree(".", with_abinit=False) jobs = max(1, number_of_cpus() // 2) if jobs == "auto" else int(jobs) with cd(top): if clean: ctx.run("make clean", pty=True) #cmd = "make -j%d > make.log 2> make.stderr" % jobs cmd = "make -j%d > >(tee -a make.log) 2> >(tee -a make.stderr >&2)" % jobs cprint("Executing: %s" % cmd, "yellow") ctx.run(cmd, pty=True)
def runemall(ctx, make=True, jobs="auto", touch=False, clean=False, keywords=None): """Run all tests (sequential and parallel). Exit immediately if errors""" make(ctx, jobs=jobs, touch=touch, clean=clean) top = find_top_build_tree(".", with_abinit=True) jobs = max(1, number_of_cpus() // 2) if jobs == "auto" else int(jobs) kws = "" if keywords is None else "-k %s" % keywords with cd(os.path.join(top, "tests")): cmd = "./runtests.py -j%d %s" % (jobs, kws) cprint("Executing: %s" % cmd, "yellow") ctx.run(cmd, pty=True) # Now run the parallel tests. for n in [2, 4, 10]: j = jobs // n if j == 0: continue cmd = "./runtests.py paral mpiio -j%d -n%d %s" % (j, n, kws) cprint("Executing: %s" % cmd, "yellow") ctx.run(cmd, pty=True)
def watchdog(ctx, jobs="auto", sleep_time=5): """ Start watchdog service to watch F90 files and execute `make` when changes are detected. """ cprint( "Starting watchdog service to watch F90 files and execute `make` when changes are detected", color="green") cprint("Enter <CTRL + C> in the terminal to kill the service.", color="green") cprint(f"Start watching F90 files with sleep_time {sleep_time} s ....", color="green") top = find_top_build_tree(".", with_abinit=True) jobs = max(1, number_of_cpus() // 2) if jobs == "auto" else int(jobs) # http://thepythoncorner.com/dev/how-to-create-a-watchdog-in-python-to-look-for-filesystem-changes/ # https://stackoverflow.com/questions/19991033/generating-multiple-observers-with-python-watchdog import time from watchdog.observers import Observer from watchdog.events import PatternMatchingEventHandler event_handler = PatternMatchingEventHandler(patterns="*.F90", ignore_patterns="", ignore_directories=False, case_sensitive=True) def on_created(event): print(f"hey, {event.src_path} has been created!") def on_deleted(event): print(f"what the f**k! Someone deleted {event.src_path}!") def on_modified(event): print(f"hey buddy, {event.src_path} has been modified") cmd = "make -j%d > >(tee -a make.log) 2> >(tee -a make.stderr >&2)" % jobs cprint("Executing: %s" % cmd, color="yellow") with cd(top): try: result = ctx.run(cmd, pty=True) if result.ok: cprint("Make completed successfully", color="green") cprint("Watching for changes ...", color="green") except Exception: cprint(f"Make returned non-zero exit status", color="red") cprint( f"Keep on watching for changes hoping you get it right ...", color="red") def on_moved(event): print(f"ok ok ok, someone moved {event.src_path} to {event.dest_path}") event_handler.on_created = on_created event_handler.on_deleted = on_deleted event_handler.on_modified = on_modified event_handler.on_moved = on_moved observer = Observer() path = ABINIT_SRCDIR observer.schedule(event_handler, path, recursive=True) observer.start() try: while True: time.sleep(sleep_time) except KeyboardInterrupt: observer.stop() observer.join()
def clean(ctx): """Remove object files in src and shared. Do not object files in fallbacks""" top = find_top_build_tree(".", with_abinit=False) with cd(top): ctx.run("cd src && make clean && cd ..", pty=True) ctx.run("cd shared && make clean && cd ..", pty=True)