def execute( step: steps.Step, project_config: "project_loader._config.Config", part_names: Sequence[str] = None, ): """Execute until step in the lifecycle for part_names or all parts. Lifecycle execution will happen for each step iterating over all the available parts, if part_names is specified, only those parts will run. If one of the parts to execute has an after keyword, execution is forced until the stage step for such part. If part_names was provided and after is not in this set, an exception will be raised. :param str step: A valid step in the lifecycle: pull, build, prime or snap. :param project_config: Fully loaded project (old logic moving either to Project or the PluginHandler). :param list part_names: A list of parts to execute the lifecycle on. :raises RuntimeError: If a prerequesite of the part needs to be staged and such part is not in the list of parts to iterate over. :returns: A dict with the snap name, version, type and architectures. """ installed_packages = _install_build_packages( project_config.get_build_packages()) installed_snaps = _install_build_snaps( project_config.get_build_snaps(), project_config.project._get_content_snaps()) try: global_state = states.GlobalState.load( filepath=project_config.project._get_global_state_file_path()) except FileNotFoundError: global_state = states.GlobalState() global_state.append_build_packages(installed_packages) global_state.append_build_snaps(installed_snaps) # Let's not call out to the Snap Store if we do not need to. if global_state.get_required_grade() is None: global_state.set_required_grade( _get_required_grade( base=project_config.project.info.base, arch=project_config.project.deb_arch, )) global_state.save( filepath=project_config.project._get_global_state_file_path()) executor = _Executor(project_config) executor.run(step, part_names) if not executor.steps_were_run: logger.warning( "The requested action has already been taken. Consider\n" "specifying parts, or clean the steps you want to run again.") return { "name": project_config.data["name"], "version": project_config.data.get("version"), "arch": project_config.data["architectures"], "type": project_config.data.get("type", ""), }
def test_grade_not_queried_for_if_already_set(self): # Set the grade global_state = states.GlobalState() global_state.set_required_grade("devel") global_state.save(filepath=self.global_state_filepath) lifecycle.execute(steps.PULL, self.project_config) self.fake_storeapi_get_info.mock.assert_not_called()
def execute( step: steps.Step, project_config: "snapcraft.internal.project_loader._config.Config", part_names: Sequence[str] = None, ): """Execute until step in the lifecycle for part_names or all parts. Lifecycle execution will happen for each step iterating over all the available parts, if part_names is specified, only those parts will run. If one of the parts to execute has an after keyword, execution is forced until the stage step for such part. If part_names was provided and after is not in this set, an exception will be raised. :param str step: A valid step in the lifecycle: pull, build, prime or snap. :param project_config: Fully loaded project (old logic moving either to Project or the PluginHandler). :param list part_names: A list of parts to execute the lifecycle on. :raises RuntimeError: If a prerequesite of the part needs to be staged and such part is not in the list of parts to iterate over. :returns: A dict with the snap name, version, type and architectures. """ installed_packages = repo.Repo.install_build_packages( project_config.build_tools) if installed_packages is None: raise ValueError( "The repo backend is not returning the list of installed packages") installed_snaps = repo.snaps.install_snaps(project_config.build_snaps) os.makedirs(constants.SNAPCRAFT_INTERNAL_DIR, exist_ok=True) state_path = os.path.join(constants.SNAPCRAFT_INTERNAL_DIR, "state") with open(state_path, "w") as state_file: state_file.write( yaml.dump(states.GlobalState(installed_packages, installed_snaps))) if _should_get_core(project_config.data.get("confinement")): _setup_core(project_config.project.deb_arch, project_config.data.get("base", "core")) executor = _Executor(project_config) executor.run(step, part_names) if not executor.steps_were_run: logger.warn( "The requested action has already been taken. Consider\n" "specifying parts, or clean the steps you want to run again.") return { "name": project_config.data["name"], "version": project_config.data.get("version"), "arch": project_config.data["architectures"], "type": project_config.data.get("type", ""), }
def execute(step: steps.Step, project_options, part_names=None): """Execute until step in the lifecycle for part_names or all parts. Lifecycle execution will happen for each step iterating over all the available parts, if part_names is specified, only those parts will run. If one of the parts to execute has an after keyword, execution is forced until the stage step for such part. If part_names was provided and after is not in this set, an exception will be raised. :param str step: A valid step in the lifecycle: pull, build, prime or snap. :param project_options: Runtime options for the project. :param list part_names: A list of parts to execute the lifecycle on. :raises RuntimeError: If a prerequesite of the part needs to be staged and such part is not in the list of parts to iterate over. :returns: A dict with the snap name, version, type and architectures. """ config = project_loader.load_config(project_options) installed_packages = repo.Repo.install_build_packages( config.build_tools) if installed_packages is None: raise ValueError( 'The repo backend is not returning the list of installed packages') installed_snaps = repo.snaps.install_snaps(config.build_snaps) os.makedirs(constants.SNAPCRAFT_INTERNAL_DIR, exist_ok=True) state_path = os.path.join(constants.SNAPCRAFT_INTERNAL_DIR, 'state') with open(state_path, 'w') as state_file: state_file.write(yaml.dump( states.GlobalState(installed_packages, installed_snaps))) if _should_get_core(config.data.get('confinement')): _setup_core(project_options.deb_arch, config.data.get('base', 'core')) executor = _Executor(config, project_options) executor.run(step, part_names) if not executor.steps_were_run: logger.warn( 'The requested action has already been taken. Consider\n' 'specifying parts, or clean the steps you want to run again.') return {'name': config.data['name'], 'version': config.data.get('version'), 'arch': config.data['architectures'], 'type': config.data.get('type', '')}
def test_stable_but_devel_required(self): global_state_path = "global_state" self.useFixture( fixtures.MockPatch( "snapcraft.project.Project._get_global_state_file_path", return_value=global_state_path, ) ) global_state = states.GlobalState() global_state.set_required_grade("devel") global_state.save(filepath=global_state_path) self.config_data["grade"] = "stable" self.assertRaises(meta_errors.GradeDevelRequiredError, self.generate_meta_yaml)
def test_stable_required(self): global_state_path = "global_state" self.useFixture( fixtures.MockPatch( "snapcraft.project.Project._get_global_state_file_path", return_value=global_state_path, ) ) global_state = states.GlobalState() global_state.set_required_grade("stable") global_state.save(filepath=global_state_path) self.config_data["grade"] = "stable" self.assertThat(self.generate_meta_yaml()["grade"], Equals("stable"))
def execute(step, project_options, part_names=None): """Execute until step in the lifecycle for part_names or all parts. Lifecycle execution will happen for each step iterating over all the available parts, if part_names is specified, only those parts will run. If one of the parts to execute has an after keyword, execution is forced until the stage step for such part. If part_names was provided and after is not in this set, an exception will be raised. :param str step: A valid step in the lifecycle: pull, build, prime or snap. :param project_options: Runtime options for the project. :param list part_names: A list of parts to execute the lifecycle on. :raises RuntimeError: If a prerequesite of the part needs to be staged and such part is not in the list of parts to iterate over. :returns: A dict with the snap name, version, type and architectures. """ config = snapcraft.internal.load_config(project_options) installed_packages = repo.Repo.install_build_packages(config.build_tools) if installed_packages is None: raise ValueError( 'The repo backend is not returning the list of installed packages') installed_snaps = repo.snaps.install_snaps(config.build_snaps) os.makedirs(constants.SNAPCRAFT_INTERNAL_DIR, exist_ok=True) state_path = os.path.join(constants.SNAPCRAFT_INTERNAL_DIR, 'state') with open(state_path, 'w') as state_file: state_file.write( yaml.dump(states.GlobalState(installed_packages, installed_snaps))) if (os.environ.get('SNAPCRAFT_SETUP_CORE') and config.data['confinement'] == 'classic'): _setup_core(project_options.deb_arch) _Executor(config, project_options).run(step, part_names) return { 'name': config.data['name'], 'version': config.data['version'], 'arch': config.data['architectures'], 'type': config.data.get('type', '') }
def execute( step: steps.Step, project_config: "project_loader._config.Config", part_names: Sequence[str] = None, ): """Execute until step in the lifecycle for part_names or all parts. Lifecycle execution will happen for each step iterating over all the available parts, if part_names is specified, only those parts will run. If one of the parts to execute has an after keyword, execution is forced until the stage step for such part. If part_names was provided and after is not in this set, an exception will be raised. :param str step: A valid step in the lifecycle: pull, build, prime or snap. :param project_config: Fully loaded project (old logic moving either to Project or the PluginHandler). :param list part_names: A list of parts to execute the lifecycle on. :raises RuntimeError: If a prerequesite of the part needs to be staged and such part is not in the list of parts to iterate over. :returns: A dict with the snap name, version, type and architectures. """ installed_packages = repo.Repo.install_build_packages( project_config.build_tools) if installed_packages is None: raise ValueError( "The repo backend is not returning the list of installed packages") content_snaps = project_config.project._get_content_snaps() required_snaps = project_config.build_snaps | content_snaps if common.is_process_container(): installed_snaps = [] # type: List[str] logger.warning(( "The following snaps are required but not installed as snapcraft " "is running inside docker or podman container: {}.\n" "Please ensure the environment is properly setup before continuing.\n" "Ignore this message if the appropriate measures have already been taken" .format(", ".join(required_snaps)))) else: installed_snaps = repo.snaps.install_snaps(required_snaps) try: global_state = states.GlobalState.load( filepath=project_config.project._get_global_state_file_path()) except FileNotFoundError: global_state = states.GlobalState() global_state.append_build_packages(installed_packages) global_state.append_build_snaps(installed_snaps) # Let's not call out to the Snap Store if we do not need to. if global_state.get_required_grade() is None: global_state.set_required_grade( _get_required_grade( base=project_config.project.info.base, arch=project_config.project.deb_arch, )) global_state.save( filepath=project_config.project._get_global_state_file_path()) executor = _Executor(project_config) executor.run(step, part_names) if not executor.steps_were_run: logger.warn( "The requested action has already been taken. Consider\n" "specifying parts, or clean the steps you want to run again.") return { "name": project_config.data["name"], "version": project_config.data.get("version"), "arch": project_config.data["architectures"], "type": project_config.data.get("type", ""), }