MCPcopy Create free account
hub / github.com/FastLED/FastLED / _matches_rust_tool

Function _matches_rust_tool

ci/hooks/rust_tool_guard.py:104–133  ·  view source on GitHub ↗

Return the matched Rust tool name, or None. Matches two locations: 1. First token (after env-var prefix) is one of RUST_TOOLS. 2. Mid-chain occurrence: ` ` somewhere in the command (catches `cd /x && cargo build`, `(cd y; rustc …)`, etc.).

(command: str)

Source from the content-addressed store, hash-verified

102
103
104def _matches_rust_tool(command: str) -> str | None:
105 """Return the matched Rust tool name, or None.
106
107 Matches two locations:
108 1. First token (after env-var prefix) is one of RUST_TOOLS.
109 2. Mid-chain occurrence: ` <tool> ` somewhere in the command
110 (catches `cd /x && cargo build`, `(cd y; rustc …)`, etc.).
111 """
112 rest, _ = strip_env_prefix(command.lstrip())
113 # If already running under soldr, treat as compliant.
114 if re.match(r"soldr(\s|$)", rest):
115 return None
116 for tool in RUST_TOOLS:
117 # Position 1: first token.
118 if re.match(rf"{re.escape(tool)}(\s|$)", rest):
119 return tool
120 # Position 2: mid-chain. Match the tool when preceded by a
121 # shell separator (`&&`, `||`, `;`, `(`, `|`, whitespace) so we
122 # don't match substrings like `mycargo` or `--rustflags=…`.
123 # Python's `re` doesn't support variable-width lookbehind, so
124 # do the `soldr` exclusion as a second pass: walk every
125 # occurrence and check the immediately-preceding non-space
126 # token.
127 for m in re.finditer(rf"(?:^|[;&|()\s]){re.escape(tool)}(?:\s|$)", rest):
128 before = rest[: m.start()].rstrip()
129 last_token = before.rsplit(None, 1)[-1] if before else ""
130 if last_token == "soldr":
131 continue
132 return tool
133 return None
134
135
136def main() -> int:

Callers 1

mainFunction · 0.85

Calls 2

strip_env_prefixFunction · 0.85
startMethod · 0.45

Tested by

no test coverage detected