def get_from_dict( cls, raw_dict: dict, config_file_path: str = None, repo_name: str = None, spec_file_path: str = None, ) -> "PackageConfig": # required to avoid cyclical imports from packit.schema import PackageConfigSchema if config_file_path and not raw_dict.get("config_file_path", None): raw_dict.update(config_file_path=config_file_path) if "jobs" not in raw_dict: # we want default jobs to go through the proper parsing process raw_dict["jobs"] = get_default_jobs() package_config = PackageConfigSchema().load_config(raw_dict) if not getattr(package_config, "specfile_path", None): if spec_file_path: package_config.specfile_path = spec_file_path else: raise PackitConfigException("Spec file was not found!") if not getattr(package_config, "upstream_package_name", None) and repo_name: package_config.upstream_package_name = repo_name if not getattr(package_config, "downstream_package_name", None) and repo_name: package_config.downstream_package_name = repo_name logger.debug(package_config) return package_config
def __eq__(self, other: object): if not isinstance(other, self.__class__): return NotImplemented # required to avoid cyclical imports from packit.schema import PackageConfigSchema s = PackageConfigSchema() # Compare the serialized objects. serialized_self = s.dump(self) serialized_other = s.dump(other) logger.debug(f"our configuration:\n{serialized_self}") logger.debug(f"the other configuration:\n{serialized_other}") return serialized_self == serialized_other
def get_from_dict( cls, raw_dict: dict, config_file_path: str = None, repo_name: str = None, spec_file_path: str = None, ) -> "PackageConfig": # required to avoid cyclical imports from packit.schema import PackageConfigSchema if config_file_path and not raw_dict.get("config_file_path", None): raw_dict.update(config_file_path=config_file_path) # we need to process defaults first so they get propagated to JobConfigs if "jobs" not in raw_dict: # we want default jobs to go through the proper parsing process raw_dict["jobs"] = get_default_jobs() if not raw_dict.get("specfile_path", None): if spec_file_path: raw_dict["specfile_path"] = spec_file_path else: raise PackitConfigException("Spec file was not found!") if not raw_dict.get("upstream_package_name", None) and repo_name: raw_dict["upstream_package_name"] = repo_name if not raw_dict.get("downstream_package_name", None) and repo_name: raw_dict["downstream_package_name"] = repo_name return PackageConfigSchema().load(raw_dict)
def __repr__(self): # required to avoid cyclical imports from packit.schema import PackageConfigSchema s = PackageConfigSchema() # For __repr__() return a JSON-encoded string, by using dumps(). # Mind the 's'! return f"PackageConfig: {s.dumps(self)}"
def get_from_dict( cls, raw_dict: dict, config_file_path: str = None, repo_name: str = None, spec_file_path: str = None, ) -> "PackageConfig": # required to avoid cyclical imports from packit.schema import PackageConfigSchema if config_file_path and not raw_dict.get("config_file_path", None): raw_dict.update(config_file_path=config_file_path) package_config = PackageConfigSchema(strict=True).load(raw_dict).data if not getattr(package_config, "specfile_path", None): if spec_file_path: package_config.specfile_path = spec_file_path else: raise PackitConfigException("Spec file was not found!") if not getattr(package_config, "upstream_package_name", None) and repo_name: package_config.upstream_package_name = repo_name if not getattr(package_config, "downstream_package_name", None) and repo_name: package_config.downstream_package_name = repo_name if "jobs" not in raw_dict: package_config.jobs = default_jobs return package_config
def get_from_dict( cls, raw_dict: dict, config_file_path: Optional[str] = None, repo_name: Optional[str] = None, spec_file_path: Optional[str] = None, ) -> "PackageConfig": # required to avoid cyclical imports from packit.schema import PackageConfigSchema if config_file_path and not raw_dict.get("config_file_path", None): raw_dict.update(config_file_path=config_file_path) # we need to process defaults first so they get propagated to JobConfigs if "jobs" not in raw_dict: # we want default jobs to go through the proper parsing process raw_dict["jobs"] = get_default_jobs() if not raw_dict.get("upstream_package_name", None) and repo_name: raw_dict["upstream_package_name"] = repo_name if not raw_dict.get("downstream_package_name", None) and repo_name: raw_dict["downstream_package_name"] = repo_name if not raw_dict.get("specfile_path", None): if spec_file_path: raw_dict["specfile_path"] = spec_file_path else: # we default to downstream_package_name # https://packit.dev/docs/configuration/#specfile_path downstream_package_name = raw_dict.get("downstream_package_name", None) if downstream_package_name: raw_dict["specfile_path"] = f"{downstream_package_name}.spec" # else: we could try upstream_package_name but this seems # like an extreme corner case package_config = PackageConfigSchema().load(raw_dict) if not package_config.specfile_path and not all( job.type == JobType.tests and job.skip_build for job in package_config.jobs ): raise PackitConfigException("Spec file was not found!") return package_config
def dump_package_config(package_config: PackageConfig): return PackageConfigSchema().dump_config( package_config) if package_config else None
def load_package_config(package_config: PackageConfig): return PackageConfigSchema().load_config( package_config) if package_config else None
def test_serialize_and_deserialize(package_config): schema = PackageConfigSchema() serialized = schema.dump_config(package_config) new_package_config = schema.load_config(serialized) assert package_config == new_package_config