def test_2_writepy(self): """Tests the writing of the python module that interacts with the fortran shared library via ctypes. """ for modname in self.originals: msg.info("Writing python wrapper module {}.py".format(modname)) self.writers[modname].write_py() msg.okay("Finished writing {}.py".format(modname))
def save(self): """Saves the state of the wizard to binary in the code root as .fpytests """ from os import path from fortpy import msg fullpath = path.join(self.coderoot, ".fpytests") with open(fullpath, 'wb') as f: pickle.dump(self, f, pickle.HIGHEST_PROTOCOL) msg.okay("Saved wizard data to {}".format(fullpath))
def test_0_writef90(self): """Tests the writing of the wrapper F90 module as well as the compilation of the *.a library for the dependency modules required by symmetry_module.f90 """ for modname, module in self.parser.modules.items(): msg.info("Writing wrapper module for {}".format(modname)) fwriter = f90.WrapperModule(module, "celib", self.fdir, link="/Users/trunks/codes/celib/trunk/celib.a") self.writers[modname] = fwriter fwriter.write_f90() msg.okay("Finished writing {}_c.f90".format(modname))
def generate(parser, coderoot, stagedir, compiler=None, debug=False, profile=False, strict=False, docompile=True): """Generates the f90 module file for all members referenced in the parser's modules list. """ import fortpy from fortpy.utility import get_fortpy_templates_dir from fortpy.testing.elements import AutoClasser members = _find_members(parser, coderoot) folder = "filename" classers = [AutoClasser(m, folder, m.name, [], coderoot, True) for m in members] from os import path templates = get_fortpy_templates_dir() statpath = path.join(templates, "fpy_auxiliary.f90") with open(statpath) as f: static = f.read() from fortpy.printing.formatting import present_params xnames, modcode, routines, modules = _generate_single(classers) from fortpy.code import order_module_dependencies modules = order_module_dependencies(modules, parser) from os import mkdir, path if docompile: auxdir = path.join(stagedir, "fortpy.aux") if not path.isdir(auxdir): mkdir(auxdir) else: auxdir = coderoot if docompile and not _should_recompile(auxdir, parser, modules, compiler): msg.okay("The current version of fpy_auxiliary.f90 is up-to-date.") from fortpy.testing.compilers import replace target = replace(auxdir + ".[c]", compiler) return (0, True, target) static = static.replace("__auxsave__", present_params(xnames, 21)) static = static.replace("__aux_uses__", '\n'.join(modcode)) static = static.replace("__version__", fortpy.__version__) static = static.replace("__fxauxsave__", '\n'.join(routines)) xnames, modcode, routines, dmods = _generate_single(classers, False) static = static.replace("__auxread__", present_params(xnames, 21)) static = static.replace("__fxauxread__", '\n'.join(routines)) fortpath = path.join(auxdir, "fpy_auxiliary.f90") with open(fortpath, 'w') as f: f.write(static) if docompile: _prepare_dir(parser, modules, auxdir) return _compile(auxdir, compiler, debug, profile)
def test_0_writef90(self): """Tests the writing of the wrapper F90 module as well as the compilation of the *.a library for the dependency modules required by symmetry_module.f90 """ for modname, module in self.parser.modules.items(): msg.info("Writing wrapper module for {}".format(modname)) fwriter = f90.WrapperModule( module, "celib", self.fdir, link="/Users/trunks/codes/celib/trunk/celib.a") self.writers[modname] = fwriter fwriter.write_f90() msg.okay("Finished writing {}_c.f90".format(modname))
def _prompt_general(header, skeys, sources=None, args=None): msg.okay(header) for i, k in enumerate(skeys): msg.std("{}. {}".format(i, k)) msg.blank(1,0) choice = input("Selection: ") if re.match("[\d]+", choice.strip()): value = int(choice) if sources is None: return value else: if value in sources: sources[value](*args) else: msg.warn("choice '{}' not in list of possibilities.".format(choice)) else: msg.warn("invalid (non-numeric) choice: '{}'".format(choice))
def _complete_general(prompt="$ ", options=None, completer=None, leader=None, regex=None, cast=None, current=None): """Prompts the user for input from the specified options. """ import readline readline.parse_and_bind("tab: complete") if completer is not None: readline.set_completer(SimpleCompleter(None, completer).complete) elif options is not None: readline.set_completer(SimpleCompleter(options).complete) if leader is not None: msg.okay(leader) if current is not None: msg.gen("The current value is set as '{}'.".format(current)) choice = input(prompt) if choice.strip() == '?': return choice.strip() if choice.strip() == '': return None if regex is not None: import re if not re.match(regex, choice): msg.warn("'{}' is not a valid choice.".format(choice)) return None if cast is not None: try: result = cast(choice.strip()) except ValueError: return None else: result = choice return result
parser.add_argument("-check", nargs="+", help="Specify the best-practice checks to run.", choices=["pointers", "all"], required=True) parser.add_argument("-verbose", help="Sets the level of verbosity for comparison output.", type=int, default=0) parser.add_argument("-pypath", help="Specify a path to add to sys.path before running the tests.") parser.add_argument("-recursive", help=("Also analyze the libraries that the specified 'source' " "directory depends on."), action="store_true") #Parse the args from the commandline that ran the script, call initialize args = vars(parser.parse_args()) #We added this argument for debugging installations. That way we can make changes #without doing a pip install each time; just put the path to the repo root in 'pypath' if args["pypath"]: import sys sys.path.insert(0, args["pypath"]) import fortpy parser = parse() from fortpy.msg import okay if "all" in args["check"]: for ckey in checks: okay("Running {} checks".format(ckey)) checks[ckey](parser) else: for ckey in args["check"]: if ckey in checks: info("Running {} checks".format(ckey)) checks[ckey](parser)
"-pypath", help="Specify a path to add to sys.path before running the tests.") parser.add_argument( "-recursive", help=("Also analyze the libraries that the specified 'source' " "directory depends on."), action="store_true") #Parse the args from the commandline that ran the script, call initialize args = vars(parser.parse_args()) #We added this argument for debugging installations. That way we can make changes #without doing a pip install each time; just put the path to the repo root in 'pypath' if args["pypath"]: import sys sys.path.insert(0, args["pypath"]) import fortpy parser = parse() from fortpy.msg import okay if "all" in args["check"]: for ckey in checks: okay("Running {} checks".format(ckey)) checks[ckey](parser) else: for ckey in args["check"]: if ckey in checks: info("Running {} checks".format(ckey)) checks[ckey](parser)