Skip to content

Isolate the current directory when probing gitfame for the author - #70

Merged
jaraco merged 1 commit into
mainfrom
bugfix/69-safe-path-gitfame
Aug 23, 2026
Merged

jaraco merged 1 commit into
mainfrom
bugfix/69-safe-path-gitfame

Conversation

@jaraco

@jaraco jaraco commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Closes #69.

author_from_vcs() spawned gitfame from the project directory with no protection against the cwd shadowing the stdlib. In coherent's flat layout that's a live hazard: a project with a top-level logging.py (e.g. compilers.common) makes gitfame's import logging resolve to the project module, gitfame produces no author, and the build later dies in Message.parse_contributor.

Now the probe runs via jaraco.compat.py310.safe_path, released as 4.4.0 for this purpose:

  • safe_path.command(...) prefixes sys.executable and, below 3.11, -I.
  • safe_path.environ() sets PYTHONSAFEPATH=1 unconditionally.

That keeps the isolation self-supplied rather than depending on the caller's environment, and it covers 3.10, where PYTHONSAFEPATH is a silent no-op — the reason the reusable workflow's PYTHONSAFEPATH: '1' masked this everywhere except the 3.10 matrix leg. coherent.deps moves onto the same shared shim in coherent-oss/coherent.deps#24, replacing its local copy.

tests/test_discovery.py builds a throwaway git repo carrying a shadowing logging.py and asserts the author resolves. Verified it fails without the fix (author_from_vcs() returns None, the precondition for the reported crash) and passes with it.

🤖 Generated with Claude Code

@jaraco
jaraco force-pushed the bugfix/69-safe-path-gitfame branch from 450d03b to 3ad2784 Compare August 23, 2026 15:55
@jaraco

jaraco commented Aug 23, 2026

Copy link
Copy Markdown
Member Author

Also degrades an indeterminate author gracefully: parse_contributor returns None instead of raising AttributeError, Author-Email is omitted from the metadata rather than emitted as None, and render_toml emits an empty authors list.

Let's not make this change; it adds lots of conditionality to the implementation that I'd like to avoid.

Without an explicit safe path, a project module shadowing one of
gitfame's stdlib imports (e.g. a top-level logging.py) breaks author
discovery, and PYTHONSAFEPATH alone doesn't cover Python 3.10.

Closes #69

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jaraco
jaraco force-pushed the bugfix/69-safe-path-gitfame branch from 3ad2784 to 4aefeed Compare August 23, 2026 16:19
@jaraco

jaraco commented Aug 23, 2026

Copy link
Copy Markdown
Member Author

Agreed, and dropped — the branch is amended (4aefeed), so the diff is now just __init__.py, discovery.py, and the new test. Description updated to match.

For the record, there was no strong motivation to keep it:

  • Once the cwd isolation is in place, an indeterminate author means no git repo, no commits, or no gitfame — not a state worth building through quietly.
  • version_from_vcs() fails under those same conditions, so tolerating a missing author doesn't yield a working build; it just relocates the failure.
  • The pass_none part was dead weight regardless: when the author can't be resolved, Message['Author-Email'] comes back as '' rather than None (the email policy stores it that way), so the crash is exp.match('') returning None. pass_none never fired.

What's given up is only the legibility of the symptom — an unresolvable author again surfaces as AttributeError: 'NoneType' object has no attribute 'groupdict'. If that ever becomes worth addressing, the fix without added conditionality is at the source: stop author_from_vcs from swallowing the exception, so the actual cause surfaces instead of teaching downstream code to tolerate None.

@jaraco
jaraco merged commit e75fb2b into main Aug 23, 2026
28 checks passed
@jaraco
jaraco deleted the bugfix/69-safe-path-gitfame branch August 23, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

author_from_vcs runs gitfame without cwd isolation; a stdlib-shadowing project module breaks the build

1 participant