Ejemplo n.º 1
0
Archivo: create.py Proyecto: LLNL/spack
def create(parser, args):
    # Gather information about the package to be created
    name = get_name(args)
    url = get_url(args)
    versions, guesser = get_versions(args, name)
    build_system = get_build_system(args, guesser)

    # Create the package template object
    package_class = templates[build_system]
    package = package_class(name, url, versions)
    tty.msg("Created template for {0} package".format(package.name))

    # Create a directory for the new package
    repo = get_repository(args, name)
    pkg_path = repo.filename_for_package_name(package.name)
    if os.path.exists(pkg_path) and not args.force:
        tty.die('{0} already exists.'.format(pkg_path),
                '  Try running `spack create --force` to overwrite it.')
    else:
        mkdirp(os.path.dirname(pkg_path))

    # Write the new package file
    package.write(pkg_path)
    tty.msg("Created package file: {0}".format(pkg_path))

    # Open up the new package file in your $EDITOR
    editor(pkg_path)
Ejemplo n.º 2
0
Archivo: edit.py Proyecto: LLNL/spack
def edit_package(name, repo_path, namespace):
    """Opens the requested package file in your favorite $EDITOR.

    Args:
        name (str): The name of the package
        repo_path (str): The path to the repository containing this package
        namespace (str): A valid namespace registered with Spack
    """
    # Find the location of the package
    if repo_path:
        repo = spack.repo.Repo(repo_path)
    elif namespace:
        repo = spack.repo.path.get_repo(namespace)
    else:
        repo = spack.repo.path
    path = repo.filename_for_package_name(name)

    spec = Spec(name)
    if os.path.exists(path):
        if not os.path.isfile(path):
            tty.die("Something is wrong. '{0}' is not a file!".format(path))
        if not os.access(path, os.R_OK | os.W_OK):
            tty.die("Insufficient permissions on '%s'!" % path)
    else:
        tty.die("No package for '{0}' was found.".format(spec.name),
                "  Use `spack create` to create a new package")

    editor(path)
Ejemplo n.º 3
0
Archivo: create.py Proyecto: eic/spack
def create(parser, args):
    # Gather information about the package to be created
    name = get_name(args)
    url = get_url(args)
    versions, guesser = get_versions(args, name)
    build_system = get_build_system(args, guesser)

    # Create the package template object
    constr_args = {'name': name, 'versions': versions}
    package_class = templates[build_system]
    if package_class != BundlePackageTemplate:
        constr_args['url'] = url
    package = package_class(**constr_args)
    tty.msg("Created template for {0} package".format(package.name))

    # Create a directory for the new package
    repo = get_repository(args, name)
    pkg_path = repo.filename_for_package_name(package.name)
    if os.path.exists(pkg_path) and not args.force:
        tty.die('{0} already exists.'.format(pkg_path),
                '  Try running `spack create --force` to overwrite it.')
    else:
        mkdirp(os.path.dirname(pkg_path))

    # Write the new package file
    package.write(pkg_path)
    tty.msg("Created package file: {0}".format(pkg_path))

    # Optionally open up the new package file in your $EDITOR
    if not args.skip_editor:
        editor(pkg_path)
Ejemplo n.º 4
0
def create(parser, args):
    # Gather information about the package to be created
    name = get_name(args)
    url = get_url(args)
    versions, guesser = get_versions(args, name)
    build_system = get_build_system(args, guesser)

    # Create the package template object
    package_class = templates[build_system]
    package = package_class(name, url, versions)
    tty.msg("Created template for {0} package".format(package.name))

    # Create a directory for the new package
    repo = get_repository(args, name)
    pkg_path = repo.filename_for_package_name(package.name)
    if os.path.exists(pkg_path) and not args.force:
        tty.die('{0} already exists.'.format(pkg_path),
                '  Try running `spack create --force` to overwrite it.')
    else:
        mkdirp(os.path.dirname(pkg_path))

    # Write the new package file
    package.write(pkg_path)
    tty.msg("Created package file: {0}".format(pkg_path))

    # Open up the new package file in your $EDITOR
    editor(pkg_path)
Ejemplo n.º 5
0
def augment(parser, args):
    name = args.package
    target_repo = spack.repo.path.get_repo(args.namespace)
    target_path = target_repo.filename_for_package_name(name)

    repos = spack.repo.path.repos
    namespaces = [r.namespace for r in repos]
    target_index = namespaces.index(args.namespace)
    for repo in repos[target_index:]:
        if repo.namespace == args.namespace:
            continue
        source_path = repo.filename_for_package_name(name)
        if os.path.exists(source_path):
            break
    else:
        tty.die("No package for '{0}' was found.".format(name),
                "  Use `spack create` to create a new package")
    spec = Spec(".".join([repo.namespace, name]))

    if not os.path.exists(target_path):
        mkdirp(os.path.dirname(target_path))
        with open(target_path, "w") as pkg_file:
            pkg_file.write(
                PACKAGE_TEMPLATE.format(module=spec.package.fullname.replace(
                    '-', '_'),
                                        namespace=repo.namespace.capitalize(),
                                        cls=mod_to_class(name)))
    if args.split:
        editor("-o", source_path, target_path)
    else:
        editor(target_path)
Ejemplo n.º 6
0
def edit_package(name, repo_path, namespace):
    """Opens the requested package file in your favorite $EDITOR.

    Args:
        name (str): The name of the package
        repo_path (str): The path to the repository containing this package
        namespace (str): A valid namespace registered with Spack
    """
    # Find the location of the package
    if repo_path:
        repo = spack.repo.Repo(repo_path)
    elif namespace:
        repo = spack.repo.path.get_repo(namespace)
    else:
        repo = spack.repo.path
    path = repo.filename_for_package_name(name)

    spec = Spec(name)
    if os.path.exists(path):
        if not os.path.isfile(path):
            tty.die("Something is wrong. '{0}' is not a file!".format(path))
        if not os.access(path, os.R_OK):
            tty.die("Insufficient permissions on '%s'!" % path)
    else:
        tty.die("No package for '{0}' was found.".format(spec.name),
                "  Use `spack create` to create a new package")

    editor(path)
Ejemplo n.º 7
0
def set_up_license(pkg):
    """Prompt the user, letting them know that a license is required.

    For packages that rely on license files, a global license file is
    created and opened for editing.

    For packages that rely on environment variables to point to a
    license, a warning message is printed.

    For all other packages, documentation on how to set up a license
    is printed."""

    # If the license can be stored in a file, create one
    if pkg.license_files:
        license_path = pkg.global_license_file
        if not os.path.exists(license_path):
            # Create a new license file
            write_license_file(pkg, license_path)
            # Open up file in user's favorite $EDITOR for editing
            editor_exe = None
            if 'VISUAL' in os.environ:
                editor_exe = Executable(os.environ['VISUAL'])
                # gvim runs in the background by default so we force it to run
                # in the foreground to make sure the license file is updated
                # before we try to install
                if 'gvim' in os.environ['VISUAL']:
                    editor_exe.add_default_arg('-f')
            elif 'EDITOR' in os.environ:
                editor_exe = Executable(os.environ['EDITOR'])
            else:
                editor_exe = which('vim', 'vi', 'emacs', 'nano')
            if editor_exe is None:
                raise EnvironmentError(
                    'No text editor found! Please set the VISUAL and/or EDITOR'
                    ' environment variable(s) to your preferred text editor.')

            def editor_wrapper(exe, args):
                editor_exe(license_path)

            editor(license_path, _exec_func=editor_wrapper)
        else:
            # Use already existing license file
            tty.msg("Found already existing license %s" % license_path)

    # If not a file, what about an environment variable?
    elif pkg.license_vars:
        tty.warn("A license is required to use %s. Please set %s to the "
                 "full pathname to the license file, or port@host if you"
                 " store your license keys on a dedicated license server" %
                 (pkg.name, ' or '.join(pkg.license_vars)))

    # If not a file or variable, suggest a website for further info
    elif pkg.license_url:
        tty.warn("A license is required to use %s. See %s for details" %
                 (pkg.name, pkg.license_url))

    # If all else fails, you're on your own
    else:
        tty.warn("A license is required to use %s" % pkg.name)
Ejemplo n.º 8
0
def test_editor_visual(good_exe):
    os.environ['VISUAL'] = good_exe

    def assert_exec(exe, args):
        assert exe == good_exe
        assert args == [good_exe, '/path/to/file']

    ed.editor('/path/to/file', _exec_func=assert_exec)
Ejemplo n.º 9
0
def test_editor_no_visual(good_exe):
    if 'VISUAL' in os.environ:
        del os.environ['VISUAL']
    os.environ['EDITOR'] = good_exe

    def assert_exec(exe, args):
        assert exe == good_exe
        assert args == [good_exe, '/path/to/file']

    ed.editor('/path/to/file', _exec_func=assert_exec)
Ejemplo n.º 10
0
def test_editor_visual_bad(good_exe, bad_exe):
    os.environ['VISUAL'] = bad_exe
    os.environ['EDITOR'] = good_exe

    def assert_exec(exe, args):
        if exe == bad_exe:
            raise OSError()

        assert exe == good_exe
        assert args == [good_exe, '/path/to/file']

    ed.editor('/path/to/file', _exec_func=assert_exec)
Ejemplo n.º 11
0
def test_editor_both_bad(nosuch_exe, vim_exe):
    os.environ['VISUAL'] = nosuch_exe
    os.environ['EDITOR'] = nosuch_exe

    os.environ['PATH'] = '%s:%s' % (os.path.dirname(vim_exe),
                                    os.environ['PATH'])

    def assert_exec(exe, args):
        assert exe == vim_exe
        assert args == [vim_exe, '/path/to/file']

    ed.editor('/path/to/file', _exec_func=assert_exec)
Ejemplo n.º 12
0
def test_editor_no_visual_with_args(good_exe):
    if 'VISUAL' in os.environ:
        del os.environ['VISUAL']

    # editor has extra args in the var (e.g., emacs -nw)
    os.environ['EDITOR'] = good_exe + ' -nw --foo'

    def assert_exec(exe, args):
        assert exe == good_exe
        assert args == [good_exe, '-nw', '--foo', '/path/to/file']

    ed.editor('/path/to/file', _exec_func=assert_exec)
Ejemplo n.º 13
0
def config_edit(args):
    if not args.scope:
        if args.section == 'compilers':
            args.scope = spack.config.default_modify_scope()
        else:
            args.scope = 'user'
    if not args.section:
        args.section = None

    config = spack.config.config
    config_file = config.get_config_filename(args.scope, args.section)
    editor(config_file)
Ejemplo n.º 14
0
def config_edit(args):
    if not args.scope:
        if args.section == 'compilers':
            args.scope = spack.config.default_modify_scope()
        else:
            args.scope = 'user'
    if not args.section:
        args.section = None

    config = spack.config.config
    config_file = config.get_config_filename(args.scope, args.section)
    editor(config_file)
Ejemplo n.º 15
0
def test_no_editor():
    if 'VISUAL' in os.environ:
        del os.environ['VISUAL']
    if 'EDITOR' in os.environ:
        del os.environ['EDITOR']
    os.environ['PATH'] = ''

    def assert_exec(exe, args):
        assert False

    with pytest.raises(EnvironmentError, match=r'No text editor found.*'):
        ed.editor('/path/to/file', _exec_func=assert_exec)
Ejemplo n.º 16
0
def config_edit(args):
    """Edit the configuration file for a specific scope and config section.

    With no arguments and an active environment, edit the spack.yaml for
    the active environment.
    """
    scope, section = _get_scope_and_section(args)
    if not scope and not section:
        tty.die('`spack config edit` requires a section argument '
                'or an active environment.')

    config_file = spack.config.config.get_config_filename(scope, section)
    if args.print_file:
        print(config_file)
    else:
        editor(config_file)
Ejemplo n.º 17
0
Archivo: config.py Proyecto: LLNL/spack
def config_edit(args):
    """Edit the configuration file for a specific scope and config section.

    With no arguments and an active environment, edit the spack.yaml for
    the active environment.

    """
    scope, section = _get_scope_and_section(args)
    if not scope and not section:
        tty.die('`spack config edit` requires a section argument '
                'or an active environment.')

    config_file = spack.config.config.get_config_filename(scope, section)
    if args.print_file:
        print(config_file)
    else:
        editor(config_file)
Ejemplo n.º 18
0
def set_up_license(pkg):
    """Prompt the user, letting them know that a license is required.

    For packages that rely on license files, a global license file is
    created and opened for editing.

    For packages that rely on environment variables to point to a
    license, a warning message is printed.

    For all other packages, documentation on how to set up a license
    is printed."""

    # If the license can be stored in a file, create one
    if pkg.license_files:
        license_path = pkg.global_license_file
        if not os.path.exists(license_path):
            # Create a new license file
            write_license_file(pkg, license_path)
            # Open up file in user's favorite $EDITOR for editing
            editor(license_path)
            tty.msg("Added global license file %s" % license_path)
        else:
            # Use already existing license file
            tty.msg("Found already existing license %s" % license_path)

    # If not a file, what about an environment variable?
    elif pkg.license_vars:
        tty.warn("A license is required to use %s. Please set %s to the "
                 "full pathname to the license file, or port@host if you"
                 " store your license keys on a dedicated license server" %
                 (pkg.name, ' or '.join(pkg.license_vars)))

    # If not a file or variable, suggest a website for further info
    elif pkg.license_url:
        tty.warn("A license is required to use %s. See %s for details" %
                 (pkg.name, pkg.license_url))

    # If all else fails, you're on your own
    else:
        tty.warn("A license is required to use %s" % pkg.name)
Ejemplo n.º 19
0
def set_up_license(pkg):
    """Prompt the user, letting them know that a license is required.

    For packages that rely on license files, a global license file is
    created and opened for editing.

    For packages that rely on environment variables to point to a
    license, a warning message is printed.

    For all other packages, documentation on how to set up a license
    is printed."""

    # If the license can be stored in a file, create one
    if pkg.license_files:
        license_path = pkg.global_license_file
        if not os.path.exists(license_path):
            # Create a new license file
            write_license_file(pkg, license_path)
            # Open up file in user's favorite $EDITOR for editing
            editor(license_path)
            tty.msg("Added global license file %s" % license_path)
        else:
            # Use already existing license file
            tty.msg("Found already existing license %s" % license_path)

    # If not a file, what about an environment variable?
    elif pkg.license_vars:
        tty.warn("A license is required to use %s. Please set %s to the "
                 "full pathname to the license file, or port@host if you"
                 " store your license keys on a dedicated license server" %
                 (pkg.name, ' or '.join(pkg.license_vars)))

    # If not a file or variable, suggest a website for further info
    elif pkg.license_url:
        tty.warn("A license is required to use %s. See %s for details" %
                 (pkg.name, pkg.license_url))

    # If all else fails, you're on your own
    else:
        tty.warn("A license is required to use %s" % pkg.name)
Ejemplo n.º 20
0
Archivo: edit.py Proyecto: mcuma/spack
def edit(parser, args):
    name = args.package

    # By default, edit package files
    path = spack.paths.packages_path

    # If `--command`, `--test`, or `--module` is chosen, edit those instead
    if args.path:
        path = args.path
        if name:
            # convert command names to python module name
            if path == spack.paths.command_path:
                name = spack.cmd.python_name(name)

            path = os.path.join(path, name)
            if not os.path.exists(path):
                files = glob.glob(path + '*')
                exclude_list = ['.pyc', '~']  # exclude binaries and backups
                files = list(
                    filter(lambda x: all(s not in x for s in exclude_list),
                           files))
                if len(files) > 1:
                    m = 'Multiple files exist with the name {0}.'.format(name)
                    m += ' Please specify a suffix. Files are:\n\n'
                    for f in files:
                        m += '        ' + os.path.basename(f) + '\n'
                    tty.die(m)
                if not files:
                    tty.die("No file for '{0}' was found in {1}".format(
                        name, path))
                path = files[0]  # already confirmed only one entry in files

        editor(path)
    elif name:
        edit_package(name, args.repo, args.namespace)
    else:
        # By default open the directory where packages live
        editor(path)
Ejemplo n.º 21
0
def config_edit(args):
    """Edit the configuration file for a specific scope and config section.

    With no arguments and an active environment, edit the spack.yaml for
    the active environment.
    """
    spack_env = os.environ.get(ev.spack_env_var)
    if spack_env and not args.scope:
        # Don't use the scope object for envs, as `config edit` can be called
        # for a malformed environment. Use SPACK_ENV to find spack.yaml.
        config_file = ev.manifest_file(spack_env)
    else:
        # If we aren't editing a spack.yaml file, get config path from scope.
        scope, section = _get_scope_and_section(args)
        if not scope and not section:
            tty.die('`spack config edit` requires a section argument '
                    'or an active environment.')
        config_file = spack.config.config.get_config_filename(scope, section)

    if args.print_file:
        print(config_file)
    else:
        editor(config_file)
Ejemplo n.º 22
0
Archivo: edit.py Proyecto: LLNL/spack
def edit(parser, args):
    name = args.name

    # By default, edit package files
    path = spack.paths.packages_path

    # If `--command`, `--test`, or `--module` is chosen, edit those instead
    if args.path:
        path = args.path
        if name:
            # convert command names to python module name
            if path == spack.paths.command_path:
                name = spack.cmd.python_name(name)

            path = os.path.join(path, name)
            if not os.path.exists(path):
                files = glob.glob(path + '*')
                blacklist = ['.pyc', '~']  # blacklist binaries and backups
                files = list(filter(
                    lambda x: all(s not in x for s in blacklist), files))
                if len(files) > 1:
                    m = 'Multiple files exist with the name {0}.'.format(name)
                    m += ' Please specify a suffix. Files are:\n\n'
                    for f in files:
                        m += '        ' + os.path.basename(f) + '\n'
                    tty.die(m)
                if not files:
                    tty.die("No file for '{0}' was found in {1}".format(name,
                                                                        path))
                path = files[0]  # already confirmed only one entry in files

        editor(path)
    elif name:
        edit_package(name, args.repo, args.namespace)
    else:
        # By default open the directory where packages live
        editor(path)