def get_project(*, is_managed_host: bool = False, skip_snapcraft_yaml: bool = False, **kwargs): # We need to do this here until we can get_snapcraft_yaml as part of Project. if is_managed_host: os.chdir(os.path.expanduser(os.path.join("~", "project"))) if skip_snapcraft_yaml: snapcraft_yaml_file_path = None else: snapcraft_yaml_file_path = get_snapcraft_yaml() ctx = click.get_current_context() for key, value in ctx.parent.params.items(): if not kwargs.get(key): kwargs[key] = value project = Project( debug=kwargs.pop("debug"), use_geoip=kwargs.pop("enable_geoip"), parallel_builds=not kwargs.pop("no_parallel_builds"), target_deb_arch=kwargs.pop("target_arch"), snapcraft_yaml_file_path=snapcraft_yaml_file_path, is_managed_host=is_managed_host, ) return project
def get_project(*, is_managed_host: bool = False, **kwargs): # We need to do this here until we can get_snapcraft_yaml as part of Project. if is_managed_host: try: os.chdir(os.path.expanduser(os.path.join("~", "project"))) except FileNotFoundError: # No project found (fresh environment). raise errors.ProjectNotFoundError() snapcraft_yaml_file_path = get_snapcraft_yaml() # This method may be called from a click.Command with no parent. ctx = click.get_current_context() if ctx.parent is not None: for key, value in ctx.parent.params.items(): if not kwargs.get(key): kwargs[key] = value project = Project( debug=kwargs.pop("debug", False), target_deb_arch=kwargs.pop("target_arch", None), snapcraft_yaml_file_path=snapcraft_yaml_file_path, is_managed_host=is_managed_host, ) # TODO: this should be automatic on get_project(). # This is not the complete meta parsed by the project loader. project._snap_meta = Snap.from_dict(project.info.get_raw_snapcraft()) return project
def _get_origin_data(origin_dir): origin_data = {} yaml_file = project.get_snapcraft_yaml(base_dir=origin_dir) try: with open(yaml_file) as fp: origin_data = yaml.safe_load(fp) except ScannerError as e: raise errors.InvalidWikiEntryError(e) from e return origin_data
def get_project(*, skip_snapcraft_yaml: bool = False, **kwargs): if skip_snapcraft_yaml: snapcraft_yaml_file_path = None else: snapcraft_yaml_file_path = get_snapcraft_yaml() ctx = click.get_current_context() for key, value in ctx.parent.params.items(): if not kwargs.get(key): kwargs[key] = value project = Project( debug=kwargs.pop("debug"), use_geoip=kwargs.pop("enable_geoip"), parallel_builds=not kwargs.pop("no_parallel_builds"), target_deb_arch=kwargs.pop("target_arch"), snapcraft_yaml_file_path=snapcraft_yaml_file_path, ) return project
def get_project(*, skip_snapcraft_yaml: bool = False, **kwargs): if skip_snapcraft_yaml: snapcraft_yaml_file_path = None else: snapcraft_yaml_file_path = get_snapcraft_yaml() ctx = click.get_current_context() for key, value in ctx.parent.params.items(): if not kwargs.get(key): kwargs[key] = value project = Project( debug=kwargs.pop("debug"), use_geoip=kwargs.pop("enable_geoip"), parallel_builds=not kwargs.pop("no_parallel_builds"), target_deb_arch=kwargs.pop("target_arch"), snapcraft_yaml_file_path=snapcraft_yaml_file_path, ) return project
def _needs_legacy() -> bool: if not os.path.isdir(common.get_legacy_snapcraft_dir()): return False try: # Early bootstrapping does not allow us to use the existing utilities we # have to manage this check. if os.getenv("SNAPCRAFT_BUILD_ENVIRONMENT") == "managed-host": base_dir = os.path.expanduser(os.path.join("~", "project")) else: base_dir = None snapcraft_yaml_path = project.get_snapcraft_yaml(base_dir=base_dir) with open(snapcraft_yaml_path, "r") as f: data = yaml_utils.load(f) return data.get("base") is None except Exception: # If there are issues loading/parsing the YAML, just pass off to the current version # where the error should be properly handled return False
def get_project(*, is_managed_host: bool = False, **kwargs): # We need to do this here until we can get_snapcraft_yaml as part of Project. if is_managed_host: os.chdir(os.path.expanduser(os.path.join("~", "project"))) snapcraft_yaml_file_path = get_snapcraft_yaml() # This method may be called from a click.Command with no parent. ctx = click.get_current_context() if ctx.parent is not None: for key, value in ctx.parent.params.items(): if not kwargs.get(key): kwargs[key] = value project = Project( debug=kwargs.pop("debug", False), target_deb_arch=kwargs.pop("target_arch", None), snapcraft_yaml_file_path=snapcraft_yaml_file_path, is_managed_host=is_managed_host, ) return project
def test_duplicates(duplicate_stub_snapcraft_yaml_file): with pytest.raises(errors.DuplicateSnapcraftYamlError): get_snapcraft_yaml()
def test_config_raises_on_missing_snapcraft_yaml(tmp_work_path): """Test that an error is raised if snap/snapcraft.yaml is missing""" with pytest.raises(errors.MissingSnapcraftYamlError): get_snapcraft_yaml()
def test_get_snapcraft_yaml(stub_snapcraft_yaml_file): assert get_snapcraft_yaml() == stub_snapcraft_yaml_file
def test_get(self): if os.path.dirname(self.file_path): os.makedirs(os.path.dirname(self.file_path)) open(self.file_path, "w").close() self.assertThat(get_snapcraft_yaml(), Equals(self.file_path))
def test_get(self): if os.path.dirname(self.file_path): os.makedirs(os.path.dirname(self.file_path)) open(self.file_path, "w").close() self.assertThat(get_snapcraft_yaml(), Equals(self.file_path))