diff --git a/doc/contrib/coding-style.rst b/doc/contrib/coding-style.rst index 7558f061e4..e740ced0b3 100644 --- a/doc/contrib/coding-style.rst +++ b/doc/contrib/coding-style.rst @@ -14,8 +14,8 @@ run the following commands to apply it: # Install the formatter if not present pip install black - # Automatically apply style. If unsure what this does read on. - black . scripts/build-catalogue.in + # Automatically apply style to a certain file. If unsure what this does read on. + black . scripts/arbor/build-catalogue.in The formatter can also be run with ``--check`` to list offending files and ``--diff`` to preview changes. Most editors can `integrate with black diff --git a/scripts/arbor-build-catalogue b/scripts/arbor-build-catalogue index 1bf7b0e38b..2bf1383ff5 100755 --- a/scripts/arbor-build-catalogue +++ b/scripts/arbor-build-catalogue @@ -12,23 +12,47 @@ import re config = A.config() -prefix = Path(config['prefix']) +prefix = Path(config["prefix"]) +CXX = Path(config["CXX"]) if not prefix.exists(): try: # Example <>/lib/python3.10/site-packages/arbor altern = Path(A.__path__[0]).parent.parent.parent.parent - print(f"Warning: prefix '{prefix}' does not exist, falling back to '{altern}'.", file=sys.stderr) + print( + f"Warning: prefix '{prefix}' does not exist, falling back to '{altern}'.", + file=sys.stderr, + ) prefix = altern except: - print(f"Error: Neither prefix '{prefix}' nor fallback '{altern}' exist; giving up.", file=sys.stderr) + print( + f"Error: Neither prefix '{prefix}' nor fallback '{altern}' exist. Please specify the prefix where you keep your Python libraries with --prefix.", + file=sys.stderr, + ) exit(-1) +if not CXX.exists(): + try: + # Example <>/lib/python3.10/site-packages/arbor + altern = "c++" + print( + f"Warning: prefix '{CXX}' does not exist, falling back to '{altern}'.", + file=sys.stderr, + ) + CXX = altern + except: + print( + f"Error: Neither prefix '{CXX}' nor fallback '{altern}' exist. Please provide a path to a C++ compiler with --cxx", + file=sys.stderr, + ) + exit(-1) + def parse_arguments(): parser = argparse.ArgumentParser( description="Generate dynamic catalogue and build it into a shared object.", usage="%(prog)s catalogue_name mod_source_dir", add_help=False, - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + formatter_class=argparse.ArgumentDefaultsHelpFormatter, + ) parser.add_argument("name", metavar="name", type=str, help="Catalogue name.") @@ -54,9 +78,7 @@ enabled) must be present in the target directory.""", parser.add_argument("-q", "--quiet", action="store_true", help="Less output.") - parser.add_argument("--cpu", - default=True, - help="Enable CPU support.") + parser.add_argument("--cpu", default=True, help="Enable CPU support.") parser.add_argument( "--debug", @@ -65,7 +87,7 @@ enabled) must be present in the target directory.""", const=True, default=None, help="Don't clean up the generated temp cpp code." - +" Can be a target path for the generated code.", + + " Can be a target path for the generated code.", ) parser.add_argument( @@ -79,8 +101,8 @@ enabled) must be present in the target directory.""", parser.add_argument( "--cxx", metavar="cxx", - default=config["CXX"], - help='Use this C++ compiler.', + default=CXX, + help="Use this C++ compiler.", ) parser.add_argument( @@ -126,6 +148,12 @@ mod_dir = pwd / Path(args["modpfx"]) mods = [f[:-4] for f in os.listdir(mod_dir) if f.endswith(".mod")] quiet = args["quiet"] verbose = args["verbose"] and not quiet +if verbose: + print("=" * 80) + print(f"{os.path.basename(__file__)} called with the following arguments:") + for k, v in args.items(): + print(k, v) + print("=" * 80) debug = args["debug"] raw = args["raw"] gpu = args["gpu"] @@ -191,7 +219,7 @@ set(arbor_DIR {pakdir}) find_package(arbor REQUIRED) {gpu_support} set(CMAKE_BUILD_TYPE release) -set(CMAKE_CXX_COMPILER ${{ARB_CXX}}) +set(CMAKE_CXX_COMPILER {args["cxx"]}) set(CMAKE_CXX_FLAGS ${{ARB_CXX_FLAGS}}) include(BuildModules.cmake)