def _namespace_to_specs(namespace): """Return dictionary of specifications from namespace.""" from neurodocker.generators.common import _installation_implementations instructions = [('base', namespace.base)] try: for arg in namespace.ordered_args: # TODO: replace try-except with stricter logic. if arg[0] == 'install': instructions.append(arg) continue try: ii = (arg[0], {k: v for k, v in arg[1]}) except ValueError: ii = arg instructions.append(ii) except AttributeError: pass # Convert string options that should be booleans to booleans. for instruction, options in instructions: if instruction in _installation_implementations.keys(): _string_vals_to_bool(options) _string_vals_to_list(options) return { 'pkg_manager': namespace.pkg_manager, 'instructions': instructions, }
def _validate_software_options(self): """Raise ValueError if a key is present that does not belong in a function's signature. """ for pkg, opts in self.specs['instructions']: if pkg in _installation_implementations.keys(): func = _installation_implementations[pkg] params = list(inspect.signature(func).parameters) bad_opts = [opt for opt in opts if opt not in params] if bad_opts: bad_opts = ', '.join(bad_opts) raise ValueError("Invalid option(s) found in instructions " " key '{}': {}. Valid options are {}" "".format(pkg, bad_opts, params))
def _namespace_to_specs(namespace): """Return dictionary of specifications from namespace.""" from neurodocker.generators.common import _installation_implementations # instructions = [("base", namespace.base)] instructions = [] try: for arg in namespace.ordered_args: # TODO: replace try-except with stricter logic. if arg[0] == "install": instructions.append(arg) continue try: ii = (arg[0], {k: v for k, v in arg[1]}) except ValueError: ii = arg instructions.append(ii) except AttributeError: pass # Convert string options that should be booleans to booleans. for instruction, options in instructions: if instruction in _installation_implementations.keys(): _string_vals_to_bool(options) _string_vals_to_list(options) specs = { "pkg_manager": namespace.pkg_manager, "instructions": instructions } # Add nd_freeze nd_freeze_idx = _get_index_of_tuple_in_instructions( "nd_freeze", specs["instructions"]) if nd_freeze_idx: nd_freeze = specs["instructions"].pop(nd_freeze_idx) specs["instructions"].insert(1, nd_freeze) return specs
def _add_generate_common_arguments(parser): p = parser p.add_argument("-b", "--base", help="Base Docker image. E.g., debian:stretch") p.add_argument("-p", "--pkg-manager", choices={'apt', 'yum'}, help="Linux package manager.") p.add_argument( '--add-to-entrypoint', action=OrderedArgs, help=("Add a command to the file /neurodocker/startup.sh, which is the" " container's default entrypoint.")) p.add_argument( '--copy', action=OrderedArgs, nargs="+", help="Copy files into container. Use format <src>... <dest>") p.add_argument( '--install', action=OrderedArgs, nargs="+", help=("Install system packages with apt-get or yum, depending on the" " package manager specified.")) p.add_argument( '--entrypoint', action=OrderedArgs, help="Set the container's entrypoint (Docker) / append to runscript" " (Singularity)") p.add_argument( '-e', '--env', action=OrderedArgs, nargs="+", type=_list_of_kv, help="Set environment variable(s). Use the format KEY=VALUE") p.add_argument('-r', '--run', action=OrderedArgs, help="Run a command when building container") p.add_argument('--run-bash', action=OrderedArgs, help="Run a command in bash") p.add_argument('-u', '--user', action=OrderedArgs, help="Switch current user (creates user if necessary)") p.add_argument('-w', '--workdir', action=OrderedArgs, help="Set working directory") # To generate from file. p.add_argument( 'file', nargs='?', help="Generate file from JSON. Overrides other `generate` arguments") p.add_argument('--json', action="store_true", help="Print Neurodocker JSON spec") # Other arguments (no order). p.add_argument( '-o', '--output', dest="output", help="If specified, save Dockerfile to file with this name.") p.add_argument('--no-print', dest='no_print', action="store_true", help="Do not print the generated file") _ndeb_servers = ", ".join( _installation_implementations['neurodebian']._servers.keys()) # Software package options. pkgs_help = { "all": "Install software packages. Each argument takes a list of" " key=value pairs. Where applicable, the default installation" " behavior is to install by downloading and uncompressing" " binaries. Some programs can be built from source.", "afni": "Install AFNI. Valid keys are version (required), method," " install_path, install_r, install_r_pkgs, install_python2," " and install_python3. Only the latest version and version" " 17.2.02 are supported at this time.", "ants": "Install ANTs. Valid keys are version (required), method" " install_path, cmake_opts, and make_opts. Version can be a " " git commit hash if building from source.", "convert3d": "Install Convert3D. Valid keys are version (required)," " method, and install_path.", "dcm2niix": "Install dcm2niix. Valid keys are version, method," " install_path, cmake_opts, and make_opts", "freesurfer": "Install FreeSurfer. Valid keys are version (required)," " method, install_path, and exclude_paths. A FreeSurfer" " license is required to run the software and is not" " provided by Neurodocker.", "fsl": "Install FSL. Valid keys are version (required), method," " install_path, and exclude_paths.", "matlabmcr": "Install Matlab Compiler Runtime. Valid keys are version," " method, and install_path", "miniconda": "Install Miniconda. Valid keys are install_path," " env_name, conda_install, pip_install, conda_opts," " pip_opts, activate (default false), and version" " (defaults to latest). The options conda_install and" " pip_install accept strings of packages: conda_install=" '"python=3.6 numpy traits".', "mrtrix3": "Install MRtrix3. Valid keys are version (required)," " method, and install_path", "ndfreeze": "Use the NeuroDebian command `nd_freeze` to freeze the apt" " sources to a certain date. This will only have an effect" " on Debian and NeuroDebian APT sources.", "neurodebian": "Add NeuroDebian repository. Valid keys are " "os_codename (e.g., zesty), server (e.g., usa-nh), and" " full (if true, use non-free packages). Valid download" " servers are {}.".format(_ndeb_servers), "spm12": "Install SPM12 and its dependency, Matlab Compiler Runtime." " Valid keys are version and install_path.", "minc": "Install MINC. Valid keys is version (required), method, and" " install_path. Only version 1.9.15 is supported at this" " time.", "petpvc": "Install PETPVC. Valid keys are version (required), method," " and install_path.", "vnc": "Install a VNC server. Valid keys are passwd (required)," " start_at_runtime, and geometry." } pkgs = p.add_argument_group(title="software package arguments", description=pkgs_help['all']) for pkg in _installation_implementations.keys(): if pkg == '_header': continue flag = "--{}".format(pkg) # MRtrix3 does not need any arguments by default. nargs = "*" if pkg == "mrtrix3" else "+" pkgs.add_argument(flag, dest=pkg, nargs=nargs, action=OrderedArgs, metavar="", type=_list_of_kv, help=pkgs_help[pkg])