def test_move_transaction_commit(tmpdir): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Just some fake content.') with fs.replace_directory_transaction(str(tmpdir.join('lib'))) as backup: assert os.path.isdir(backup) fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Other content.') assert not os.path.lexists(backup) with open(str(tmpdir.join('lib', 'libfoo.so')), 'r') as f: assert 'Other content.' == f.read()
def test_move_transaction_commit(tmpdir): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Just some fake content.') old_md5 = fs.hash_directory(str(tmpdir)) with fs.replace_directory_transaction(str(tmpdir.join('lib'))): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Other content.') new_md5 = fs.hash_directory(str(tmpdir)) assert old_md5 != fs.hash_directory(str(tmpdir)) assert new_md5 == fs.hash_directory(str(tmpdir))
def test_move_transaction_rollback(tmpdir): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Just some fake content.') h = fs.hash_directory(str(tmpdir)) try: with fs.replace_directory_transaction(str(tmpdir.join('lib'))): assert h != fs.hash_directory(str(tmpdir)) fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Other content.') raise RuntimeError('') except RuntimeError: pass assert h == fs.hash_directory(str(tmpdir))
def test_move_transaction_rollback(tmpdir): fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('Initial content.') try: with fs.replace_directory_transaction(str( tmpdir.join('lib'))) as backup: assert os.path.isdir(backup) fake_library = tmpdir.mkdir('lib').join('libfoo.so') fake_library.write('New content.') raise RuntimeError('') except RuntimeError: pass assert not os.path.lexists(backup) with open(str(tmpdir.join('lib', 'libfoo.so')), 'r') as f: assert 'Initial content.' == f.read()
def install(parser, args, **kwargs): if not args.package and not args.specfiles: # if there are no args but an active environment or spack.yaml file # then install the packages from it. env = ev.get_env(args, 'install', required=False) if env: if not args.only_concrete: env.concretize() env.write() tty.msg("Installing environment %s" % env.name) env.install_all(args) return else: tty.die("install requires a package argument or a spack.yaml file") if args.jobs is not None: if args.jobs <= 0: tty.die("The -j option must be a positive integer!") if args.no_checksum: spack.config.set('config:checksum', False, scope='command_line') # Parse cli arguments and construct a dictionary # that will be passed to Package.do_install API update_kwargs_from_args(args, kwargs) kwargs.update({ 'install_dependencies': ('dependencies' in args.things_to_install), 'install_package': ('package' in args.things_to_install) }) if args.run_tests: tty.warn("Deprecated option: --run-tests: use --test=all instead") # 1. Abstract specs from cli reporter = spack.report.collect_info(args.log_format, ' '.join(args.package), args.cdash_upload_url) if args.log_file: reporter.filename = args.log_file abstract_specs = spack.cmd.parse_specs(args.package) tests = False if args.test == 'all' or args.run_tests: tests = True elif args.test == 'root': tests = [spec.name for spec in abstract_specs] kwargs['tests'] = tests try: specs = spack.cmd.parse_specs( args.package, concretize=True, tests=tests) except SpackError as e: reporter.concretization_report(e.message) raise # 2. Concrete specs from yaml files for file in args.specfiles: with open(file, 'r') as f: s = spack.spec.Spec.from_yaml(f) if s.concretized().dag_hash() != s.dag_hash(): msg = 'skipped invalid file "{0}". ' msg += 'The file does not contain a concrete spec.' tty.warn(msg.format(file)) continue specs.append(s.concretized()) if len(specs) == 0: tty.die('The `spack install` command requires a spec to install.') if not args.log_file and not reporter.filename: reporter.filename = default_log_file(specs[0]) reporter.specs = specs with reporter: if args.overwrite: # If we asked to overwrite an existing spec we must ensure that: # 1. We have only one spec # 2. The spec is already installed assert len(specs) == 1, \ "only one spec is allowed when overwriting an installation" spec = specs[0] t = spack.store.db.query(spec) assert len(t) == 1, "to overwrite a spec you must install it first" # Give the user a last chance to think about overwriting an already # existing installation if not args.yes_to_all: tty.msg('The following package will be reinstalled:\n') display_args = { 'long': True, 'show_flags': True, 'variants': True } spack.cmd.display_specs(t, **display_args) answer = tty.get_yes_or_no( 'Do you want to proceed?', default=False ) if not answer: tty.die('Reinstallation aborted.') with fs.replace_directory_transaction(specs[0].prefix): install_spec(args, kwargs, abstract_specs[0], specs[0]) else: for abstract, concrete in zip(abstract_specs, specs): install_spec(args, kwargs, abstract, concrete)
def install(parser, args, **kwargs): if not args.package and not args.specfiles: # if there are no args but an active environment or spack.yaml file # then install the packages from it. env = ev.get_env(args, 'install') if env: if not args.only_concrete: env.concretize() env.write() tty.msg("Installing environment %s" % env.name) env.install_all(workers=args.nprocs, args=args) return else: tty.die("install requires a package argument or a spack.yaml file") if args.jobs is not None: if args.jobs <= 0: tty.die("The -j option must be a positive integer!") if args.no_checksum: spack.config.set('config:checksum', False, scope='command_line') # Parse cli arguments and construct a dictionary # that will be passed to Package.do_install API update_kwargs_from_args(args, kwargs) kwargs.update({ 'install_dependencies': ('dependencies' in args.things_to_install), 'install_package': ('package' in args.things_to_install) }) if args.run_tests: tty.warn("Deprecated option: --run-tests: use --test=all instead") # 1. Abstract specs from cli reporter = spack.report.collect_info(args.log_format, args) if args.log_file: reporter.filename = args.log_file abstract_specs = spack.cmd.parse_specs(args.package) tests = False if args.test == 'all' or args.run_tests: tests = True elif args.test == 'root': tests = [spec.name for spec in abstract_specs] kwargs['tests'] = tests try: specs = spack.cmd.parse_specs(args.package, concretize=True, tests=tests) except SpackError as e: reporter.concretization_report(e.message) raise # 2. Concrete specs from yaml files for file in args.specfiles: with open(file, 'r') as f: s = spack.spec.Spec.from_yaml(f) if s.concretized().dag_hash() != s.dag_hash(): msg = 'skipped invalid file "{0}". ' msg += 'The file does not contain a concrete spec.' tty.warn(msg.format(file)) continue abstract_specs.append(s) specs.append(s.concretized()) if len(specs) == 0: tty.die('The `spack install` command requires a spec to install.') if not args.log_file and not reporter.filename: reporter.filename = default_log_file(specs[0]) reporter.specs = specs with reporter: if args.overwrite: installed = list( filter(lambda x: x, map(spack.store.db.query_one, specs))) if not args.yes_to_all: display_args = { 'long': True, 'show_flags': True, 'variants': True } if installed: tty.msg('The following package specs will be ' 'reinstalled:\n') spack.cmd.display_specs(installed, **display_args) not_installed = list( filter(lambda x: x not in installed, specs)) if not_installed: tty.msg('The following package specs are not installed and' ' the --overwrite flag was given. The package spec' ' will be newly installed:\n') spack.cmd.display_specs(not_installed, **display_args) # We have some specs, so one of the above must have been true answer = tty.get_yes_or_no('Do you want to proceed?', default=False) if not answer: tty.die('Reinstallation aborted.') for abstract, concrete in zip(abstract_specs, specs): if concrete in installed: with fs.replace_directory_transaction(concrete.prefix): install_spec(args, kwargs, abstract, concrete) else: install_spec(args, kwargs, abstract, concrete) else: for abstract, concrete in zip(abstract_specs, specs): install_spec(args, kwargs, abstract, concrete)
def install(parser, args, **kwargs): if not args.package and not args.specfiles: tty.die("install requires at least one package argument or yaml file") if args.jobs is not None: if args.jobs <= 0: tty.die("The -j option must be a positive integer!") if args.no_checksum: spack.do_checksum = False # TODO: remove this global. if args.strip_binaries: spack.hooks.strip_binaries.enabled = True # Parse cli arguments and construct a dictionary # that will be passed to Package.do_install API kwargs.update({ 'keep_prefix': args.keep_prefix, 'keep_stage': args.keep_stage, 'restage': not args.dont_restage, 'install_source': args.install_source, 'install_deps': 'dependencies' in args.things_to_install, 'make_jobs': args.jobs, 'verbose': args.verbose, 'fake': args.fake, 'dirty': args.dirty, 'use_cache': args.use_cache }) if args.run_tests: tty.warn("Deprecated option: --run-tests: use --test=all instead") # 1. Abstract specs from cli specs = spack.cmd.parse_specs(args.package) if args.test == 'all' or args.run_tests: spack.package_testing.test_all() elif args.test == 'root': for spec in specs: spack.package_testing.test(spec.name) specs = spack.cmd.parse_specs(args.package, concretize=True) # 2. Concrete specs from yaml files for file in args.specfiles: with open(file, 'r') as f: s = spack.spec.Spec.from_yaml(f) if s.concretized().dag_hash() != s.dag_hash(): msg = 'skipped invalid file "{0}". ' msg += 'The file does not contain a concrete spec.' tty.warn(msg.format(file)) continue specs.append(s.concretized()) if len(specs) == 0: tty.die('The `spack install` command requires a spec to install.') if args.overwrite: # If we asked to overwrite an existing spec we must ensure that: # 1. We have only one spec # 2. The spec is already installed assert len(specs) == 1, \ "only one spec is allowed when overwriting an installation" spec = specs[0] t = spack.store.db.query(spec) assert len(t) == 1, "to overwrite a spec you must install it first" # Give the user a last chance to think about overwriting an already # existing installation if not args.yes_to_all: tty.msg('The following package will be reinstalled:\n') display_args = {'long': True, 'show_flags': True, 'variants': True} spack.cmd.display_specs(t, **display_args) answer = tty.get_yes_or_no('Do you want to proceed?', default=False) if not answer: tty.die('Reinstallation aborted.') with fs.replace_directory_transaction(specs[0].prefix): install_spec(args, kwargs, specs[0]) else: filename = args.log_file or default_log_file(specs[0]) with spack.report.collect_info(specs, args.log_format, filename): for spec in specs: install_spec(args, kwargs, spec)
def install(parser, args, **kwargs): if args.help_cdash: parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, epilog=textwrap.dedent('''\ environment variables: SPACK_CDASH_AUTH_TOKEN authentication token to present to CDash ''')) add_cdash_args(parser, True) parser.print_help() return if not args.spec and not args.specfiles: # if there are no args but an active environment or spack.yaml file # then install the packages from it. env = ev.get_env(args, 'install') if env: if not args.only_concrete: with env.write_transaction(): concretized_specs = env.concretize() ev.display_specs(concretized_specs) # save view regeneration for later, so that we only do it # once, as it can be slow. env.write(regenerate_views=False) tty.msg("Installing environment %s" % env.name) env.install_all(args) with env.write_transaction(): # It is not strictly required to synchronize view regeneration # but doing so can prevent redundant work in the filesystem. env.regenerate_views() return else: tty.die("install requires a package argument or a spack.yaml file") if args.no_checksum: spack.config.set('config:checksum', False, scope='command_line') # Parse cli arguments and construct a dictionary # that will be passed to Package.do_install API update_kwargs_from_args(args, kwargs) if args.run_tests: tty.warn("Deprecated option: --run-tests: use --test=all instead") # 1. Abstract specs from cli reporter = spack.report.collect_info(args.log_format, args) if args.log_file: reporter.filename = args.log_file abstract_specs = spack.cmd.parse_specs(args.spec) tests = False if args.test == 'all' or args.run_tests: tests = True elif args.test == 'root': tests = [spec.name for spec in abstract_specs] kwargs['tests'] = tests try: specs = spack.cmd.parse_specs(args.spec, concretize=True, tests=tests) except SpackError as e: tty.debug(e) reporter.concretization_report(e.message) raise # 2. Concrete specs from yaml files for file in args.specfiles: with open(file, 'r') as f: s = spack.spec.Spec.from_yaml(f) if s.concretized().dag_hash() != s.dag_hash(): msg = 'skipped invalid file "{0}". ' msg += 'The file does not contain a concrete spec.' tty.warn(msg.format(file)) continue abstract_specs.append(s) specs.append(s.concretized()) if len(specs) == 0: tty.die('The `spack install` command requires a spec to install.') if not args.log_file and not reporter.filename: reporter.filename = default_log_file(specs[0]) reporter.specs = specs with reporter: if args.overwrite: installed = list( filter(lambda x: x, map(spack.store.db.query_one, specs))) if not args.yes_to_all: display_args = { 'long': True, 'show_flags': True, 'variants': True } if installed: tty.msg('The following package specs will be ' 'reinstalled:\n') spack.cmd.display_specs(installed, **display_args) not_installed = list( filter(lambda x: x not in installed, specs)) if not_installed: tty.msg('The following package specs are not installed and' ' the --overwrite flag was given. The package spec' ' will be newly installed:\n') spack.cmd.display_specs(not_installed, **display_args) # We have some specs, so one of the above must have been true answer = tty.get_yes_or_no('Do you want to proceed?', default=False) if not answer: tty.die('Reinstallation aborted.') for abstract, concrete in zip(abstract_specs, specs): if concrete in installed: with fs.replace_directory_transaction(concrete.prefix): install_spec(args, kwargs, abstract, concrete) else: install_spec(args, kwargs, abstract, concrete) else: for abstract, concrete in zip(abstract_specs, specs): install_spec(args, kwargs, abstract, concrete)
def dev_build(self, args): if not args.spec: tty.die("spack dev-build requires a package spec argument.") specs = spack.cmd.parse_specs(args.spec) if len(specs) > 1: tty.die("spack dev-build only takes one spec.") spec = specs[0] if not spack.repo.path.exists(spec.name): tty.die("No package for '{0}' was found.".format(spec.name), " Use `spack create` to create a new package") tests = False if args.test == 'all': tests = True elif args.test == 'root': tests = [spec.name] if not spec.versions.concrete: tty.die("spack dev-build spec must have a single, concrete version. " "Did you forget a package version number?") spec.concretize() package = spack.repo.get(spec) source_path = args.source_path if source_path is None: source_path = os.getcwd() source_path = os.path.abspath(source_path) # Forces the build to run out of the current directory. package.stage = DIYStage(source_path) # disable checksumming if requested if args.no_checksum or args.yes_to_all: spack.config.set('config:checksum', False, scope='command_line') kwargs = dict( make_jobs=args.jobs, keep_prefix=args.keep_prefix, install_deps=not args.ignore_deps, verbose=not args.quiet, keep_stage=True, # don't remove source dir for DIY. tests=tests, dirty=args.dirty, stop_at=args.until) display_args = {'long': True, 'show_flags': True, 'variants': True} if package.installed: if args.overwrite: if not args.yes_to_all: tty.msg('The following package will be reinstalled:\n') t = spack.store.db.query(spec) spack.cmd.display_specs(t, **display_args) answer = tty.get_yes_or_no('Do you want to proceed?', default=False) if not answer: tty.die('Reinstallation aborted.') with fs.replace_directory_transaction(spec.prefix): package.do_install(**kwargs) else: tty.error("Already installed in %s" % package.prefix) tty.msg( "Uninstall or try adding a version suffix for this DIY build.") sys.exit(1) # Give the user a last chance to think about overwriting an already # existing installation else: if args.overwrite: tty.msg("The following spec will be freshly installed, " "ignoring the --overwrite flag:") spack.cmd.display_specs([spec], **display_args) package.do_install(**kwargs)
def install(parser, args, **kwargs): if not args.package and not args.specfiles: # if there are no args but an active environment or spack.yaml file # then install the packages from it. env = ev.get_env(args, 'install', required=False) if env: if not args.only_concrete: env.concretize() env.write() tty.msg("Installing environment %s" % env.name) env.install_all(args) return else: tty.die("install requires a package argument or a spack.yaml file") if args.jobs is not None: if args.jobs <= 0: tty.die("The -j option must be a positive integer!") if args.no_checksum: spack.config.set('config:checksum', False, scope='command_line') # Parse cli arguments and construct a dictionary # that will be passed to Package.do_install API update_kwargs_from_args(args, kwargs) kwargs.update({ 'install_dependencies': ('dependencies' in args.things_to_install), 'install_package': ('package' in args.things_to_install) }) if args.run_tests: tty.warn("Deprecated option: --run-tests: use --test=all instead") # 1. Abstract specs from cli reporter = spack.report.collect_info(args.log_format, ' '.join(args.package), args.cdash_upload_url) if args.log_file: reporter.filename = args.log_file abstract_specs = spack.cmd.parse_specs(args.package) tests = False if args.test == 'all' or args.run_tests: tests = True elif args.test == 'root': tests = [spec.name for spec in abstract_specs] kwargs['tests'] = tests try: specs = spack.cmd.parse_specs(args.package, concretize=True, tests=tests) except SpackError as e: reporter.concretization_report(e.message) raise # 2. Concrete specs from yaml files for file in args.specfiles: with open(file, 'r') as f: s = spack.spec.Spec.from_yaml(f) if s.concretized().dag_hash() != s.dag_hash(): msg = 'skipped invalid file "{0}". ' msg += 'The file does not contain a concrete spec.' tty.warn(msg.format(file)) continue specs.append(s.concretized()) if len(specs) == 0: tty.die('The `spack install` command requires a spec to install.') if not args.log_file and not reporter.filename: reporter.filename = default_log_file(specs[0]) reporter.specs = specs with reporter: if args.overwrite: # If we asked to overwrite an existing spec we must ensure that: # 1. We have only one spec # 2. The spec is already installed assert len(specs) == 1, \ "only one spec is allowed when overwriting an installation" spec = specs[0] t = spack.store.db.query(spec) assert len(t) == 1, "to overwrite a spec you must install it first" # Give the user a last chance to think about overwriting an already # existing installation if not args.yes_to_all: tty.msg('The following package will be reinstalled:\n') display_args = { 'long': True, 'show_flags': True, 'variants': True } spack.cmd.display_specs(t, **display_args) answer = tty.get_yes_or_no('Do you want to proceed?', default=False) if not answer: tty.die('Reinstallation aborted.') with fs.replace_directory_transaction(specs[0].prefix): install_spec(args, kwargs, abstract_specs[0], specs[0]) else: for abstract, concrete in zip(abstract_specs, specs): install_spec(args, kwargs, abstract, concrete)