Source code for semantic_release.commit_parser.conventional.options_monorepo
from__future__importannotationsfrompathlibimportPathfromreimportcompileasregexp,errorasRegExpError# noqa: N812fromtypingimportTYPE_CHECKING,Any,Iterable,TuplefrompydanticimportField,field_validatorfrompydantic.dataclassesimportdataclass# typing_extensions is for Python 3.8, 3.9, 3.10 compatibilityfromtyping_extensionsimportAnnotatedfromsemantic_release.commit_parser.conventional.optionsimport(ConventionalCommitParserOptions,)ifTYPE_CHECKING:# pragma: no coverpass
[docs]@dataclassclassConventionalCommitMonorepoParserOptions(ConventionalCommitParserOptions):# TODO: add example into the docstring"""Options dataclass for ConventionalCommitMonorepoParser."""path_filters:Annotated[Tuple[str,...],Field(validate_default=True)]=(".",)""" A set of relative paths to filter commits by. Only commits with file changes that match these file paths or its subdirectories will be considered valid commits. Syntax is similar to .gitignore with file path globs and inverse file match globs via `!` prefix. Paths should be relative to the current working directory. """scope_prefix:str=""""" A prefix that will be striped from the scope when parsing commit messages. If set, it will cause unscoped commits to be ignored. Use this in tandem with the `path_filters` option to filter commits by directory and scope. This will be fed into a regular expression so you must escape any special characters that are meaningful in regular expressions (e.g. `.`, `*`, `?`, `+`, etc.) if you want to match them literally. """@classmethod@field_validator("path_filters",mode="before")defconvert_strs_to_paths(cls,value:Any)->tuple[Path,...]:values=valueifisinstance(value,Iterable)else[value]results:list[Path]=[]forvalinvalues:ifisinstance(val,(str,Path)):results.append(Path(val))continueraiseTypeError(f"Invalid type: {type(val)}, expected str or Path.")returntuple(results)@classmethod@field_validator("path_filters",mode="after")defresolve_path(cls,dir_paths:tuple[Path,...])->tuple[Path,...]:returntuple((Path(f"!{Path(str_path[1:]).expanduser().absolute().resolve()}")# maintains the negation prefix if it existsif(str_path:=str(path)).startswith("!")# otherwise, resolve the path normallyelsepath.expanduser().absolute().resolve())forpathindir_paths)@classmethod@field_validator("scope_prefix",mode="after")defvalidate_scope_prefix(cls,scope_prefix:str)->str:ifnotscope_prefix:return""# Allow the special case of a plain wildcard although it's not a valid regexifscope_prefix=="*":return".*"try:regexp(scope_prefix)exceptRegExpErroraserr:raiseValueError(f"Invalid regex {scope_prefix!r}")fromerrreturnscope_prefix