macaron.parsers package
Subpackages
Submodules
macaron.parsers.actionparser module
This module contains the parser for GitHub Actions Workflow files.
- macaron.parsers.actionparser.parse(workflow_path)
Parse the GitHub Actions workflow YAML file.
- Parameters:
workflow_path (str) – Path to the GitHub Actions.
- Returns:
The parsed workflow.
- Return type:
Workflow
- Raises:
ParseError – When parsing fails with errors.
- macaron.parsers.actionparser.get_run_step(step)
Get the parsed GitHub Action run step for inlined shell scripts.
If the run step cannot be validated this function returns None.
- Parameters:
step (Step) – The parsed step object.
- Returns:
The inlined run script or None if the run step cannot be validated.
- Return type:
str | None
- macaron.parsers.actionparser.get_step_input(step, key)
Get an input value from a GitHub Action step.
If the input value cannot be found or the step inputs cannot be validated this function returns None.
macaron.parsers.bashparser module
This module is a Python wrapper for the compiled bashparser binary.
The bashparser Go module is based on the github.com/mvdan/sh Go module and is distributed
together with Macaron as a compiled binary.
See Also https://github.com/mvdan/sh.
- macaron.parsers.bashparser.parse_file(file_path, macaron_path=None)
Parse a bash script file.
- Parameters:
- Returns:
The parsed bash script in JSON (dict) format.
- Return type:
- Raises:
ParseError – When parsing fails with errors.
- macaron.parsers.bashparser.parse(bash_content, macaron_path=None)
Parse a bash script’s content.
- Parameters:
- Returns:
The parsed bash script in JSON (dict) format.
- Return type:
- Raises:
ParseError – When parsing fails with errors.
- macaron.parsers.bashparser.parse_raw(bash_content, macaron_path=None)
Parse a bash script’s content.
- Parameters:
- Returns:
The parsed bash script AST in typed JSON (dict) format.
- Return type:
- Raises:
ParseError – When parsing fails with errors.
- macaron.parsers.bashparser.parse_raw_with_gha_mapping(bash_content, macaron_path=None)
Parse bash content and return raw AST plus GitHub expression mapping.
- Parameters:
- Returns:
A tuple of: - The parsed raw bash AST. - Mapping from parser placeholder variable names to original GitHub expression bodies.
- Return type:
- Raises:
ParseError – When parsing fails with errors or output cannot be decoded.
- macaron.parsers.bashparser.parse_expr(bash_expr_content, macaron_path=None)
Parse a bash script’s content.
- Parameters:
- Returns:
The parsed bash expr AST in typed JSON (dict) format.
- Return type:
- Raises:
ParseError – When parsing fails with errors.
macaron.parsers.bashparser_model module
Type definitions for Bash AST as produced (and json-serialised) by the “mvdan.cc/sh/v3/syntax” bash parser.
- class macaron.parsers.bashparser_model.UnAritOperators(value)
Bases:
Enum- Not = 34
- BitNegation = 35
- Inc = 36
- Dec = 37
- Plus = 68
- Minus = 70
- class macaron.parsers.bashparser_model.UnaryArithm
Bases:
TypedDict-
X:
Union[BinaryArithm,UnaryArithm,ParenArithm,Word]
-
X:
- macaron.parsers.bashparser_model.is_unary_arithm(expr)
- Return type:
TypeGuard[UnaryArithm]
- class macaron.parsers.bashparser_model.BinAritOperators(value)
Bases:
Enum- Add = 68
- Sub = 70
- Mul = 38
- Quo = 85
- Rem = 76
- Pow = 39
- Eql = 40
- Gtr = 54
- Lss = 56
- Neq = 41
- Leq = 42
- Geq = 43
- And = 9
- Or = 12
- Xor = 80
- Shr = 55
- Shl = 61
- AndArit = 10
- OrArit = 11
- Comma = 82
- TernQuest = 72
- TernColon = 87
- Assgn = 74
- AddAssgn = 44
- SubAssgn = 45
- MulAssgn = 46
- QuoAssgn = 47
- RemAssgn = 48
- AndAssgn = 49
- OrAssgn = 50
- XorAssgn = 51
- ShlAssgn = 52
- ShrAssgn = 53
- class macaron.parsers.bashparser_model.BinaryArithm
Bases:
TypedDict-
X:
Union[BinaryArithm,UnaryArithm,ParenArithm,Word]
-
Y:
Union[BinaryArithm,UnaryArithm,ParenArithm,Word]
-
X:
- macaron.parsers.bashparser_model.is_binary_arithm(expr)
- Return type:
TypeGuard[BinaryArithm]
- class macaron.parsers.bashparser_model.ParenArithm
Bases:
TypedDict-
X:
Union[BinaryArithm,UnaryArithm,ParenArithm,Word]
-
X:
- macaron.parsers.bashparser_model.is_paren_arithm(expr)
- Return type:
TypeGuard[ParenArithm]
- class macaron.parsers.bashparser_model.Slice
Bases:
TypedDict-
Offset:
Union[BinaryArithm,UnaryArithm,ParenArithm,Word]
-
Length:
Union[BinaryArithm,UnaryArithm,ParenArithm,Word]
-
Offset:
- class macaron.parsers.bashparser_model.ParNamesOperators(value)
Bases:
Enum- NamesPrefix = 38
- NamesPrefixWords = 84
- class macaron.parsers.bashparser_model.ParExpOperators(value)
Bases:
Enum- AlternateUnset = 68
- AlternateUnsetOrNull = 69
- DefaultUnset = 70
- DefaultUnsetOrNull = 71
- ErrorUnset = 72
- ErrorUnsetOrNull = 73
- AssignUnset = 74
- AssignUnsetOrNull = 75
- RemSmallSuffix = 76
- RemLargeSuffix = 77
- RemSmallPrefix = 78
- RemLargePrefix = 79
- UpperFirst = 80
- UpperAll = 81
- LowerFirst = 82
- LowerAll = 83
- OtherParamOps = 84
- class macaron.parsers.bashparser_model.ParamExp
Bases:
TypedDict-
Index:
NotRequired[Union[BinaryArithm,UnaryArithm,ParenArithm,Word]]
-
Index:
- class macaron.parsers.bashparser_model.ArithmExp
Bases:
TypedDict-
X:
Union[BinaryArithm,UnaryArithm,ParenArithm,Word]
-
X:
- class macaron.parsers.bashparser_model.GlobOperators(value)
Bases:
Enum- GlobZeroOrOne = 122
- GlobZeroOrMore = 123
- GlobOneOrMore = 124
- GlobOne = 125
- GlobExcept = 126
- class macaron.parsers.bashparser_model.RedirOperators(value)
Bases:
Enum- RdrOut = 54
- AppOut = 55
- RdrIn = 56
- RdrInOut = 57
- DplIn = 58
- DplOut = 59
- ClbOut = 60
- Hdoc = 61
- DashHdoc = 62
- WordHdoc = 63
- RdrAll = 64
- AppAll = 65
- class macaron.parsers.bashparser_model.ArrayElem
Bases:
TypedDict-
Index:
NotRequired[Union[BinaryArithm,UnaryArithm,ParenArithm,Word]]
-
Index:
- class macaron.parsers.bashparser_model.Assign
Bases:
TypedDict-
Index:
NotRequired[Union[BinaryArithm,UnaryArithm,ParenArithm,Word]]
-
Index:
- class macaron.parsers.bashparser_model.IfClause
Bases:
TypedDict-
Else:
NotRequired[IfClause|ElseClause]
-
Else:
- macaron.parsers.bashparser_model.is_else_clause(clause)
- Return type:
TypeGuard[ElseClause]
- macaron.parsers.bashparser_model.is_while_clause(cmd)
- Return type:
TypeGuard[WhileClause]
- class macaron.parsers.bashparser_model.CStyleLoop
Bases:
TypedDict-
Init:
NotRequired[Union[BinaryArithm,UnaryArithm,ParenArithm,Word]]
-
Cond:
NotRequired[Union[BinaryArithm,UnaryArithm,ParenArithm,Word]]
-
Post:
NotRequired[Union[BinaryArithm,UnaryArithm,ParenArithm,Word]]
-
Init:
- macaron.parsers.bashparser_model.is_cstyle_loop(loop)
- Return type:
TypeGuard[CStyleLoop]
- class macaron.parsers.bashparser_model.ForClause
Bases:
TypedDict-
Loop:
Union[WordIter,CStyleLoop]
-
Loop:
- class macaron.parsers.bashparser_model.CaseOperators(value)
Bases:
Enum- Break = 30
- Fallthrough = 31
- Resume = 32
- ResumeKorn = 33
- macaron.parsers.bashparser_model.is_case_clause(cmd)
- Return type:
TypeGuard[CaseClause]
- class macaron.parsers.bashparser_model.BinCmdOperators(value)
Bases:
Enum- AndStmt = 10
- OrStmt = 11
- Pipe = 12
- PipeAll = 13
- class macaron.parsers.bashparser_model.ArithmCmd
Bases:
TypedDict-
X:
Union[BinaryArithm,UnaryArithm,ParenArithm,Word]
-
X:
- class macaron.parsers.bashparser_model.BinTestOperators(value)
Bases:
Enum- TsReMatch = 112
- TsNewer = 113
- TsOlder = 114
- TsDevIno = 115
- TsEql = 116
- TsNeq = 117
- TsLeq = 118
- TsGeq = 119
- TsLss = 120
- TsGtr = 121
- AndTest = 10
- OrTest = 11
- TsMatchShort = 74
- TsMatch = 40
- TsNoMatch = 41
- TsBefore = 56
- TsAfter = 54
- class macaron.parsers.bashparser_model.BinaryTest
Bases:
TypedDict-
X:
Union[BinaryTest,UnaryTest,ParenTest,Word]
-
Y:
Union[BinaryTest,UnaryTest,ParenTest,Word]
-
X:
- macaron.parsers.bashparser_model.is_binary_test(test_expr)
- Return type:
TypeGuard[BinaryTest]
- class macaron.parsers.bashparser_model.UnTestOperators(value)
Bases:
Enum- TsExists = 88
- TsRegFile = 89
- TsDirect = 90
- TsCharSp = 91
- TsBlckSp = 92
- TsNmPipe = 93
- TsSocket = 94
- TsSmbLink = 95
- TsSticky = 96
- TsGIDSet = 97
- TsUIDSet = 98
- TsGrpOwn = 99
- TsUsrOwn = 100
- TsModif = 101
- TsRead = 102
- TsWrite = 103
- TsExec = 104
- TsNoEmpty = 105
- TsFdTerm = 106
- TsEmpStr = 107
- TsNempStr = 108
- TsOptSet = 109
- TsVarSet = 110
- TsRefVar = 111
- TsNot = 34
- class macaron.parsers.bashparser_model.UnaryTest
Bases:
TypedDict-
X:
Union[BinaryTest,UnaryTest,ParenTest,Word]
-
X:
- class macaron.parsers.bashparser_model.ParenTest
Bases:
TypedDict-
X:
Union[BinaryTest,UnaryTest,ParenTest,Word]
-
X:
- class macaron.parsers.bashparser_model.TestClause
Bases:
TypedDict-
X:
Union[BinaryTest,UnaryTest,ParenTest,Word]
-
X:
- macaron.parsers.bashparser_model.is_test_clause(cmd)
- Return type:
TypeGuard[TestClause]
- macaron.parsers.bashparser_model.is_decl_clause(cmd)
- Return type:
TypeGuard[DeclClause]
- class macaron.parsers.bashparser_model.LetClause
Bases:
TypedDict-
Exprs:
list[Union[BinaryArithm,UnaryArithm,ParenArithm,Word]]
-
Exprs:
- macaron.parsers.bashparser_model.is_time_clause(cmd)
- Return type:
TypeGuard[TimeClause]
- macaron.parsers.bashparser_model.is_coproc_clause(cmd)
- Return type:
TypeGuard[CoprocClause]
- class macaron.parsers.bashparser_model.Stmt
Bases:
TypedDict-
Cmd:
Union[CallExpr,IfClause,WhileClause,ForClause,CaseClause,Block,Subshell,BinaryCmd,FuncDecl,ArithmCmd,TestClause,DeclClause,LetClause,TimeClause,CoprocClause,TestDecl]
-
Cmd:
macaron.parsers.github_workflow_model module
- class macaron.parsers.github_workflow_model.On
Bases:
TypedDict-
pull_request:
NotRequired[Ref1]
-
pull_request_target:
NotRequired[Ref1]
-
push:
NotRequired[Ref1]
-
workflow_call:
NotRequired[WorkflowCall]
-
workflow_dispatch:
NotRequired[WorkflowDispatch]
-
schedule:
NotRequired[list[ScheduleItem]]
-
pull_request:
- class macaron.parsers.github_workflow_model.Container
Bases:
TypedDict-
credentials:
NotRequired[Credentials]
-
credentials:
- class macaron.parsers.github_workflow_model.ReusableWorkflowCallJob
Bases:
dict-
strategy:
NotRequired[Strategy]
-
strategy:
- class macaron.parsers.github_workflow_model.Identified(id, obj)
Bases:
Generic[T]- __init__(id, obj)
- macaron.parsers.github_workflow_model.is_normal_job(job)
- Return type:
TypeGuard[NormalJob]
- macaron.parsers.github_workflow_model.is_reusable_workflow_call_job(job)
- Return type:
TypeGuard[ReusableWorkflowCallJob]
- macaron.parsers.github_workflow_model.is_run_step(step)
- Return type:
TypeGuard[Step5]
- macaron.parsers.github_workflow_model.is_action_step(step)
- Return type:
TypeGuard[Step4]
macaron.parsers.pomparser module
This module contains the parser for POM files.
- macaron.parsers.pomparser.parse_pom_string(pom_string)
Parse the passed POM string using defusedxml.
- Parameters:
pom_string (str) – The contents of a POM file as a string.
- Returns:
The parsed element representing the POM’s XML hierarchy.
- Return type:
Element | None
- macaron.parsers.pomparser.extract_gav_from_pom(pom_file)
Extract Maven coordinates (groupId, artifactId, version) from a pom.xml.
The function reads and parses the POM and attempts to extract the <groupId>, <artifactId>, and <version> values from the root <project> element. If an individual coordinate cannot be found, that field is returned as
None. If the POM cannot be parsed at all, all three values are returned asNone.If <groupId> is not present directly under <project>, the function falls back to <project>/<parent>/<groupId>.
- Parameters:
pom_file (pathlib.Path) – Path to the pom.xml file to parse.
- Return type:
- Returns:
group_id (str | None) – The Maven groupId if found; otherwise
None.artifact_id (str | None) – The Maven artifactId if found; otherwise
None.version (str | None) – The Maven version if found; otherwise
None.
Notes
This function does not resolve property-substituted values (e.g.,
${project.version}).XML namespaces are handled by matching tag suffixes (e.g.,
...}groupId).
- macaron.parsers.pomparser.detect_parent_pom(pom_path, repo_root)
Detect a parent POM file for a given pom.xml if it exists in the repo.
This inspects the <parent> section of the POM and resolves the parent POM file path using Maven semantics:
If <project>/<parent>/<relativePath> is present and non-empty, that path (relative to the directory containing pom.xml) is used.
Otherwise Maven defaults to
../pom.xml.
See https://maven.apache.org/ref/3.0/maven-model/maven.html#class_parent.
If the resolved parent POM exists on disk and is within repo_root, this returns its path relative to repo_root. Otherwise returns
None.
- macaron.parsers.pomparser.pom_has_modules(pom_path)
Check whether a POM contains a non-empty
<modules>section.This function parses the POM and returns
Trueif it finds at least one<module>entry under<modules>(i.e., the POM is an aggregator/reactor POM).- Parameters:
pom_path (Path) – Path to the
pom.xmlto inspect.- Returns:
Trueif the POM has a<modules><module>...entry; otherwiseFalse.- Return type:
- macaron.parsers.pomparser.extract_included_pom_modules(pom_path)
Extract module entries from a Maven
pom.xml.
- macaron.parsers.pomparser.find_matching_maven_module_build_configs(repo_root, artifact_id)
Find module
pom.xmlfiles likely associated with the artifact id.
- macaron.parsers.pomparser.find_nearest_modules_pom(pom_path, repo_root, *, max_depth=50)
Find the nearest POM (self or Maven parent chain) that defines modules.
Starting from
pom_path, this function checks whether the current POM is an aggregator (i.e., contains a non-empty<modules>section). If not, it resolves the Maven parent POM and repeats recursively until:a POM with modules is found (returned), or
there is no parent POM resolvable within
repo_root(returnsNone), ora cycle is detected (returns
None), ormax_depthis exceeded (returnsNone).
- Parameters:
pom_path (Path) – Path to the starting (child)
pom.xml.repo_root (str or pathlib.Path) – Repository root path used to validate parent POMs are inside the repo and to produce a repo-relative return value.
max_depth (int, optional) – Maximum number of parent hops to attempt before aborting. Default is 50.
- Returns:
Repo-relative path to the nearest POM that contains a non-empty
<modules>section. If none is found, returnsNone.- Return type:
str | None