Source code for codegrade.models.ignored_files_exception

"""The module that defines the ``IgnoredFilesException`` model.

SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""

from __future__ import annotations

import typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa
from httpx import Response

from .. import parsers
from ..utils import to_dict
from .cg_ignore_version import CGIgnoreVersion
from .extract_file_tree_directory import ExtractFileTreeDirectory
from .file_deletion import FileDeletion
from .file_rule import FileRule
from .invalid_upload_exception import InvalidUploadException
from .missing_file import MissingFile


[docs] @dataclass(kw_only=True) class IgnoredFilesException(InvalidUploadException): """The exception used when invalid files were present in a submission.""" #: A unique code identifying the kind of error that occurred. code: t.Literal["IGNORED_FILES_IN_ARCHIVE"] #: The files that were removed from the submission. removed_files: t.Sequence[FileDeletion] #: The name and matching rule or reason for every file that was rejected by #: the ignore filter. invalid_files: t.Sequence[t.Sequence[t.Union[FileRule, str]]] #: The file tree of the submission before invalid files were removed. original_tree: ExtractFileTreeDirectory #: Deprecated: the version number of the ignore filter that was used, use #: `filter_name` instead. filter_version: int #: The name of the ignore filter version that was used. filter_name: CGIgnoreVersion #: The files that were required but missing from the submission. missing_files: t.Sequence[MissingFile] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: InvalidUploadException.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "code", rqa.StringEnum("IGNORED_FILES_IN_ARCHIVE"), doc="A unique code identifying the kind of error that occurred.", ), rqa.RequiredArgument( "removed_files", rqa.List(parsers.ParserFor.make(FileDeletion)), doc="The files that were removed from the submission.", ), rqa.RequiredArgument( "invalid_files", rqa.List( rqa.List( parsers.make_union( parsers.ParserFor.make(FileRule), rqa.SimpleValue.str, ) ) ), doc="The name and matching rule or reason for every file that was rejected by the ignore filter.", ), rqa.RequiredArgument( "original_tree", parsers.ParserFor.make(ExtractFileTreeDirectory), doc="The file tree of the submission before invalid files were removed.", ), rqa.RequiredArgument( "filter_version", rqa.SimpleValue.int, doc="Deprecated: the version number of the ignore filter that was used, use `filter_name` instead.", ), rqa.RequiredArgument( "filter_name", rqa.EnumValue(CGIgnoreVersion), doc="The name of the ignore filter version that was used.", ), rqa.RequiredArgument( "missing_files", rqa.List(parsers.ParserFor.make(MissingFile)), doc="The files that were required but missing from the submission.", ), ) ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "code": to_dict(self.code), "removed_files": to_dict(self.removed_files), "invalid_files": to_dict(self.invalid_files), "original_tree": to_dict(self.original_tree), "filter_version": to_dict(self.filter_version), "filter_name": to_dict(self.filter_name), "missing_files": to_dict(self.missing_files), "message": to_dict(self.message), "description": to_dict(self.description), "request_id": to_dict(self.request_id), } return res @classmethod def from_dict( cls: t.Type[IgnoredFilesException], d: t.Dict[str, t.Any], response: t.Optional[Response] = None, ) -> IgnoredFilesException: parsed = cls.data_parser.try_parse(d) res = cls( code=parsed.code, removed_files=parsed.removed_files, invalid_files=parsed.invalid_files, original_tree=parsed.original_tree, filter_version=parsed.filter_version, filter_name=parsed.filter_name, missing_files=parsed.missing_files, message=parsed.message, description=parsed.description, request_id=parsed.request_id, response=response, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): from .base_error import BaseError from .validation_exception import ValidationException