Repository navigation
Fix: Parse project names instead of grepping - #178
Merged
Merged
Conversation
The pyproject.toml and setup.py name lookups used PCRE patterns that only matched one double-quoted spelling. Valid files using single quotes or other spacing yielded no name, so the action failed with a misleading "no project name found" error. Neither pattern was scoped: a name in [[tool.uv.index]] before [project] was returned as the project name, and package_name="helper" in setup.py matched as name. Replace both file-grep-regex-action steps with inline steps that keep the extracted_string output, so the fall-through conditions and the capture step are unchanged: - pyproject.toml is parsed with tomllib and reads [project].name, falling back to [tool.poetry].name so Poetry 1.x projects, which the old unscoped pattern matched, keep working. Only a non-empty string counts, in both parsers, so a non-string [project] name falls through to Poetry whatever the parser mode. - setup.py is parsed with ast and reads the string-literal name keyword of a setup() call. Imports, star imports, definitions, assignments and other binding statements (for targets, with/except as, :=, match captures, del) bind names in source order; only names an assignment really rebinds count, not the base of an attribute or subscript target. Names are resolved in evaluation order (a call or binding takes effect where it ends, so setup = setup(...) calls first, a for loop binds before its body, and each with item binds before the next runs), and setup counts only when bound to one from a packaging module (setuptools, distutils.core, numpy.distutils.core or skbuild), under any alias or module path. Rebinding a name also drops the dotted paths recorded beneath it, so after import helper as distutils, distutils.core.setup() does not count. A local def setup, a setup from another module, a star import from elsewhere, helper.setup() or an unbound setup() does not count. A def or class header (decorators, defaults, bases) runs where it is defined, so a setup() there counts at that position. Annotations do not count: they are deferred under from __future__ import annotations, lazy from Python 3.14, and never evaluated for local variables. Control flow is followed: if, loop, try and match branches each start from the same state and merge where they meet, so a binding on a path that may not run (an untaken if, a loop body, an except handler) leaves a name ambiguous rather than replacing it. A call counts only when every path that binds the name binds it to a packaging setup, ignoring paths where it is unbound, so try/except ImportError fallbacks keep working. A call in a loop must hold on every pass. A block stops at return, raise, break or continue, so code after one never supplies the name, and del leaves a name unbound rather than rebinding it. A call on a path that may not run (an if branch, an except handler, a match case, a loop or comprehension body, a later and/or operand, a branch of a conditional expression) is only a candidate: a call that certainly runs wins, so a dead branch cannot supply the name ahead of the real call. In the function-body fallback, a function the file calls ranks above one it never does. Module-level calls win; function and class bodies, which may never run, count only when module level calls no bare setup() (e.g. setup() inside a main() the file calls). Each body is then scanned as its own scope, starting from the bindings it inherits (the module's final ones, an enclosing function's, but not a class body's for its methods) with its own parameters bound locally, so a name bound in one function never leaks into another. As in Python, every name a function binds anywhere in its body (except names declared global or nonlocal), including a simple x: T with no value, is local from the start, so calling it before it is bound reaches nothing. Comprehensions are scopes too: a call in one sees its loop targets and any earlier := in it, while the targets never leak out; a := inside a lambda stays in the lambda. A non-literal such as name=NAME, or a file with no such call, yields no name instead of a wrong one. tomllib needs Python 3.11+, and runners such as ubuntu-22.04 ship 3.10, so when python3 is missing, too old, or cannot parse the file, an awk match scoped to the same tables (or to a whole-word name= in setup.py) stands in. Both steps apply the setup.cfg step's PEP 508 charset check to the whole string. The parsers check before printing, because command substitution drops NUL bytes: "foo\u0000bar" in TOML, or "foo\x00bar" in setup.py, would otherwise reach the shell check as "foobar" and pass. The awk fallback skips files holding a raw NUL byte, which neither format allows, since mawk and gawk pass it through to the same effect. The setup.cfg step gains the same raw NUL guard, which it lacked, and now also matches the whole string and logs a rejected value with %q, so all three sources are checked alike. Rejected values are logged with repr() or %q, so they cannot start a workflow command. Add a test job per parser mode: tomllib on the runner, a real Python 3.10 without tomllib, and an image with no python3, both images pinned by digest; a guard step fails the job if the image does not provide its mode. Each job runs every fixture in turn and a final step checks all four outputs of each, or that the action failed without a name, reporting every failure. Fixtures cover each case from the issue, Poetry-only and [project]-over-Poetry files, aliased setup imports, module-qualified and unrelated setup() calls, shadowed setup imports in either order, setup() in function bodies, a local def setup, a star import from elsewhere, an unbound setup(), a rebound packaging module root, imports in an unrelated function and a class body, attribute assignments, a shadowing parameter, a for loop rebinding setup, a comprehension variable, a comprehension target shadowing setup, a match capture rebinding setup, a setup() call in a default value, a default that runs before its def rebinds setup, a walrus in a comprehension condition, a non-string [project] name with a Poetry name, a setup() call in a deferred annotation, a with item binding before the next, a setup.cfg holding a raw NUL, del setup, a walrus inside a lambda in a comprehension, a call before a local assignment, a local annotation without a value, a packaging import in a dead branch, a try/except ImportError fallback, a loop rebinding setup after the call, a dead call before the real call, an uncalled function before main, a conditional del before the real call, a call after return, a short-circuited call, and NUL names as escapes and raw bytes. The import-blind awk fallback is not asserted on fixtures that need import resolution. Closes: #169 Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Matthew Watkins <mwatkins@linuxfoundation.org>
ModeSevenIndustrialSolutions
force-pushed
the
fix/name-extraction
branch
from
October 2, 2026 13:41
be74d21 to
c7238e6
Compare
tykeal
approved these changes
Oct 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The project name is now parsed from
pyproject.tomlandsetup.pyrather than grepped. Valid files the old patterns missed now work, and the two cases where the wrong name was returned are fixed.Problem (#169)
pyproject.toml:(?<=^name = ")([^"]*)only matched double quotes with exactly that spacing, soname = 'x',name="x"andname = "x"gave no name. It also wasn't scoped to[project], so a[[tool.uv.index]] name = "pytorch"before[project]was returned as the project name.setup.py:(?<=name=")([^"]*)missed single quotes and spacing. It had no word boundary, sopackage_name="helper"matched and returnedhelper.Changes
action.yaml: bothfile-grep-regex-actionsteps are replaced by inline steps with the same step IDs andextracted_stringoutput, so everyif:condition and thecapturestep are unchanged.pyproject.toml: parsed withtomllib, reading[project].name, then[tool.poetry].name. Only a non-empty string counts, in both parsers, so a non-string[project]name falls through to Poetry whatever the parser mode.[project]-only scoping would have broken them.setup.py: parsed withast, reading the string-literalname=keyword of asetup()call. Imports, star imports, definitions, assignments and other binding statements (fortargets,with/except … as,:=,matchcaptures,del) bind names in source order; only names an assignment really rebinds count, not the base of an attribute or subscript target. Names resolve in evaluation order (a call or binding takes effect where it ends, sosetup = setup(...)calls first, aforloop binds before its body, and eachwithitem binds before the next runs), andsetupcounts only when bound to one from a packaging module (setuptools,distutils.core,numpy.distutils.core,skbuild), under any alias or module path. Rebinding a name also drops the dotted paths recorded beneath it, so afterimport helper as distutils,distutils.core.setup()doesn't count. A localdef setup, asetupfrom another module, a star import from elsewhere,helper.setup(...)or an unboundsetup()doesn't count. Adeforclassheader (decorators, defaults, bases) runs where it's defined, so asetup()there counts at that position. Annotations don't count: they're deferred underfrom __future__ import annotations, lazy from Python 3.14, and never evaluated for local variables. Control flow is followed:if, loop,tryandmatchbranches each start from the same state and merge where they meet, so a binding on a path that may not run (an untakenif, a loop body, anexcepthandler) leaves a name ambiguous rather than replacing it. A call counts only when every path that binds the name binds it to a packagingsetup(paths where it's unbound are ignored, sotry/except ImportErrorfallbacks keep working), and a call in a loop must hold on every pass. A call on a path that may not run (anifbranch, anexcepthandler, amatchcase, a loop or comprehension body, a laterand/oroperand, a branch of a conditional expression) is only a candidate: a call that certainly runs wins, so a dead branch can't supply the name ahead of the real call. In the function-body fallback, a function the file calls ranks above one it never does. A block stops atreturn,raise,breakorcontinue, so code after one never supplies the name, anddelleaves a name unbound. Module-level calls win; function and class bodies, which may never run, count only when module level calls no baresetup()(e.g.setup()inside amain()the file calls). Each body is then scanned as its own scope, starting from the bindings it inherits (the module's final ones, an enclosing function's, but not a class body's for its methods) with its own parameters bound locally, so a name bound in one function never leaks into another. As in Python, every name a function binds anywhere in its body (exceptglobal/nonlocalones), including a simplex: Twith no value, is local from the start, so calling it before it's bound reaches nothing. Comprehensions are scopes too: a call in one sees its loop targets and any earlier:=in it, while the targets never leak out; a:=inside a lambda stays in the lambda.python3is missing, too old fortomllib(e.g. 3.10 onubuntu-22.04), or can't parse the file, a portable awk match is used. It is scoped to the same TOML tables, or requiresnameas a whole word insetup.py.setup.cfgstep's PEP 508-style name check to the whole string, because a TOML or Python escape can embed a newline."foo\^@bar"(TOML) or"foo\x00bar"(setup.py) would otherwise reach the shell asfoobarand pass.setup.cfgstep gains the same raw-NUL guard, which it lacked, and now also matches the whole string and logs rejected values with%q, so all three sources are checked alike.repr()or%q, so they can't inject workflow commands.GITHUB_OUTPUTwith a random heredoc delimiter..github/workflows/testing.yaml: a newname-extractionjob, one job per parser mode (3 jobs):tomllibon the runner,no-tomllibin a realpython:3.10-slim, andno-pythoninubuntu:24.04. Both images are pinned by digest, and a guard step fails the job if an image doesn't provide its mode.[project]-over-Poetry files, aliasedsetupimports, module-qualified and unrelatedsetup()calls, shadowedsetupimports in either order,setup()in function bodies, a localdef setup, a star import from elsewhere, an unboundsetup(), a rebound packaging module root, imports in an unrelated function and a class body, attribute assignments, a shadowing parameter, aforloop rebindingsetup, a comprehension variable, a comprehension target shadowingsetup, amatchcapture rebindingsetup, asetup()call in a default value, a default that runs before itsdefrebindssetup, a walrus in a comprehension condition, a non-string[project]name with a Poetry name, asetup()call in a deferred annotation, awithitem binding before the next, asetup.cfgholding a raw NUL,del setup, a walrus inside a lambda in a comprehension, a call before a local assignment, a local annotation without a value, a packaging import in a dead branch, atry/except ImportErrorfallback, a loop rebindingsetupafter the call, a dead call before the real call, an uncalled function beforemain(), a conditionaldelbefore the real call, a call afterreturn, a short-circuited call, and NUL names as escapes and raw bytes.f/NN/with its expectations, oneuses: $/step per fixture runs withcontinue-on-error, and a final step asserts all four outputs of each (or that the action failed without emitting a name), reporting every failure. Fixtures that need import resolution aren't asserted inno-pythonmode, because the awk fallback can't resolve imports.README.md: the lookup-order section describes the parsing, the fallback and the name check.Validation
upstream/mainname = 'my-project'my-projectname="my-project"my-projectname = "my-project"my-project[[tool.uv.index]] name = "pytorch"before[project]pytorchmy-projectsetup(name='my-project')my-projectname = "my-project",my-projectpackage_name="helper"thenname="my-project"helpermy-projectpython3, with Python 3.9, 3.10 and 3.12, under macOS bash 3.2, and inubuntu:24.04with mawk and no Python. Existing fixtures (setup.cfg, fall-through, build-system-only) give the same results as before. I re-ran all seven fixtures through the extracted steps before committing.prek run,zizmor --persona=auditor,actionlint,shellcheckclean.ruff --select ALLon the embedded Python is clean.aislophas nothing to score (YAML and Markdown).Test GitHub Action 🧪, which runs on every PR once the layer below removes its path filter.pytorch,helper) are corrected.name=insetup.pynow yields nothing.extracted_stringas an undocumented environment variable. Nothing in this action or the org reads it.pypi-publish-action,python-audit-action,python-project-metadata-action) pin v0.1.8, so they need a release and pin bump to pick this up.Stack
This is the middle layer of a stack, and replaces #173, which it supersedes with the same commit:
Closes #169