diff options
-rw-r--r-- | lib/spack/spack/cmd/create.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/test/cmd/create.py | 57 | ||||
-rwxr-xr-x | share/spack/spack-completion.bash | 2 |
3 files changed, 64 insertions, 3 deletions
diff --git a/lib/spack/spack/cmd/create.py b/lib/spack/spack/cmd/create.py index e41a51ce76..792a437f29 100644 --- a/lib/spack/spack/cmd/create.py +++ b/lib/spack/spack/cmd/create.py @@ -393,6 +393,9 @@ def setup_parser(subparser): subparser.add_argument( '-f', '--force', action='store_true', help="overwrite any existing package file with the same name") + subparser.add_argument( + '--skip-editor', action='store_true', + help="skip the edit session for the package (e.g., automation)") class BuildSystemGuesser: @@ -671,5 +674,6 @@ def create(parser, args): 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) + # Optionally open up the new package file in your $EDITOR + if not args.skip_editor: + editor(pkg_path) diff --git a/lib/spack/spack/test/cmd/create.py b/lib/spack/spack/test/cmd/create.py new file mode 100644 index 0000000000..d3da1cce2f --- /dev/null +++ b/lib/spack/spack/test/cmd/create.py @@ -0,0 +1,57 @@ +# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import argparse +import os +import pytest + +import spack.cmd.create +import spack.util.editor + +from spack.main import SpackCommand + + +create = SpackCommand('create') + + +@pytest.fixture("module") +def cmd_create_repo(tmpdir_factory): + repo_namespace = 'cmd_create_repo' + repodir = tmpdir_factory.mktemp(repo_namespace) + repodir.ensure(spack.repo.packages_dir_name, dir=True) + yaml = repodir.join('repo.yaml') + yaml.write(""" +repo: + namespace: cmd_create_repo +""") + + repo = spack.repo.RepoPath(str(repodir)) + with spack.repo.swap(repo): + yield repo, repodir + + +@pytest.fixture(scope='module') +def parser(): + """Returns the parser for the module""" + prs = argparse.ArgumentParser() + spack.cmd.create.setup_parser(prs) + return prs + + +def test_create_template(parser, cmd_create_repo): + """Test template creation.""" + repo, repodir = cmd_create_repo + + name = 'test-package' + args = parser.parse_args(['--skip-editor', name]) + spack.cmd.create.create(parser, args) + + filename = repo.filename_for_package_name(name) + assert os.path.exists(filename) + + with open(filename, 'r') as package_file: + content = ' '.join(package_file.readlines()) + for entry in [r'TestPackage(Package)', r'def install(self']: + assert content.find(entry) > -1 diff --git a/share/spack/spack-completion.bash b/share/spack/spack-completion.bash index a1795647a6..890f6de026 100755 --- a/share/spack/spack-completion.bash +++ b/share/spack/spack-completion.bash @@ -352,7 +352,7 @@ function _spack_create { if $list_options then compgen -W "-h --help --keep-stage -n --name -t --template -r --repo - -N --namespace -f --force" -- "$cur" + -N --namespace -f --force --skip-editor" -- "$cur" fi } |