Skip to content

feat(cli): python#1088

Merged
ErnestM1234 merged 18 commits intomainfrom
e/cli/add-python-claude-parse
Mar 9, 2026
Merged

feat(cli): python#1088
ErnestM1234 merged 18 commits intomainfrom
e/cli/add-python-claude-parse

Conversation

@ErnestM1234
Copy link
Contributor

@ErnestM1234 ErnestM1234 commented Mar 8, 2026

add python registration support: t('hello, {name}', name='john', _max_chars=10), also supports declare_static()/declare_var() syntax

Greptile Summary

This PR adds Python translation support to the CLI, introducing a new @generaltranslation/python-extractor package and wiring it into the existing push pipeline. It handles t('hello, {name}', name='john', _max_chars=10) call extraction along with the declare_static() / declare_var() DSL for static and runtime variable interpolation. The refactored shared post-processing utilities (calculateHashes, dedupeUpdates, linkStaticUpdates) are a clean improvement that eliminates duplication between the React and Python pipelines.

Key changes:

  • New python-extractor package: tree-sitter-based AST extraction of t() / msg() calls from Python source files, including cross-file helper resolution and cartesian expansion of declare_static variants.
  • Framework auto-detection for pyproject.toml, requirements.txt, and setup.py using proper parsers.
  • createPythonInlineUpdates CLI integration, routed via isPythonLibrary type guard in translation/parse.ts.
  • calculateHashes / dedupeUpdates / linkStaticUpdates extracted to a shared extraction/postProcess.ts.

Issues found:

  • resolveFunctionInFile in resolveFunctionVariants.ts uses synchronous fs.readFileSync inside an async function, blocking the event loop during cross-file resolution. It should use fs.promises.readFile.

Confidence Score: 4/5

  • Safe to merge after addressing the blocking synchronous file I/O in cross-file resolution.
  • The core extraction logic is well-tested with a comprehensive fixture suite, and the refactored post-processing pipeline is a clean improvement. The one flagged issue (synchronous file read in async context) is a quality/performance concern rather than a functional blocker for the common extraction path. The fix is straightforward and isolated to one location.
  • packages/python-extractor/src/resolveFunctionVariants.ts (replace fs.readFileSync with fs.promises.readFile on line 67)

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["CLI push command\n(translation/parse.ts)"] --> B{"isPythonLibrary?"}
    B -- yes --> C["createPythonInlineUpdates\n(python/parse/)"]
    B -- no --> D["createInlineUpdates\n(react/parse/)"]

    C --> E["matchFiles\n(.py glob)"]
    E --> F["extractFromPythonSource\n(python-extractor)"]
    F --> G["extractImports\n(GT import aliases)"]
    G --> H["extractCalls\n(t / msg calls)"]
    H --> I{"hasStaticHelpers?"}
    I -- yes --> J["parseStringExpression\n(StringNode tree)"]
    J --> K["resolveDeclareStaticArg\n/ resolveDeclareVarArg"]
    K --> L["resolveFunctionCall\n(cross-file resolution)"]
    L --> M["resolveFunctionInFile\n(crossFileCache)"]
    I -- no --> N["extractStringContent\n(plain string)"]
    J --> O["nodeToStrings\n(cartesian expand)"]
    N --> P["ExtractionResult[]"]
    O --> P
    P --> Q["mapExtractionResultsToUpdates"]
    Q --> R["calculateHashes"]
    R --> S["dedupeUpdates"]
    S --> T["linkStaticUpdates\n(sharedStaticId)"]
    T --> U["Updates[]"]
Loading

Comments Outside Diff (1)

  1. python-extractor-detailed-plan.md, line 1 (link)

    This detailed plan document is committed to the repo root and is now stale. Its "Phase 2 (Future)" section lists declare_static, declare_var, and msg() support as not yet implemented, but this PR implements all three features.

    Committed design documents tend to drift out of sync and can mislead future contributors. Consider removing this file or relocating it to a docs/ or .github/ directory if you want to preserve it as a living design reference.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: python-extractor-detailed-plan.md
    Line: 1
    
    Comment:
    This detailed plan document is committed to the repo root and is now stale. Its "Phase 2 (Future)" section lists `declare_static`, `declare_var`, and `msg()` support as not yet implemented, but this PR implements all three features.
    
    Committed design documents tend to drift out of sync and can mislead future contributors. Consider removing this file or relocating it to a `docs/` or `.github/` directory if you want to preserve it as a living design reference.
    
    How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 57ce390

Greptile also left 1 inline comment on this PR.

@ErnestM1234 ErnestM1234 requested a review from a team as a code owner March 8, 2026 03:44
@ErnestM1234
Copy link
Contributor Author

@greptileai plz re-review

@archie-mckenzie
Copy link
Contributor

@greptile-ai re-review

@ErnestM1234
Copy link
Contributor Author

@greptileai plz re-review

@ErnestM1234
Copy link
Contributor Author

@greptileai plz re-review

@archie-mckenzie
Copy link
Contributor

@greptile-ai re-review

@archie-mckenzie
Copy link
Contributor

@claude review pls

@claude
Copy link

claude bot commented Mar 9, 2026

Claude encountered an error —— View job


I'll analyze this and get back to you.

@ErnestM1234 ErnestM1234 merged commit 2cad388 into main Mar 9, 2026
33 checks passed
@ErnestM1234 ErnestM1234 deleted the e/cli/add-python-claude-parse branch March 9, 2026 21:42
Comment on lines +67 to +71
source = fs.readFileSync(filePath, 'utf8');
} catch {
crossFileCache.set(cacheKey, null);
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolveFunctionInFile is async but uses synchronous fs.readFileSync() to read files. This blocks the Node.js event loop during cross-file helper resolution, which can cause noticeable stalls when projects have deep re-export chains.

Use fs.promises.readFile to keep the function non-blocking:

Suggested change
source = fs.readFileSync(filePath, 'utf8');
} catch {
crossFileCache.set(cacheKey, null);
return null;
}
let source: string;
try {
source = await fs.promises.readFile(filePath, 'utf8');
} catch {
crossFileCache.set(cacheKey, null);
return null;
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/python-extractor/src/resolveFunctionVariants.ts
Line: 67-71

Comment:
`resolveFunctionInFile` is `async` but uses synchronous `fs.readFileSync()` to read files. This blocks the Node.js event loop during cross-file helper resolution, which can cause noticeable stalls when projects have deep re-export chains.

Use `fs.promises.readFile` to keep the function non-blocking:

```suggestion
  let source: string;
  try {
    source = await fs.promises.readFile(filePath, 'utf8');
  } catch {
    crossFileCache.set(cacheKey, null);
    return null;
  }
```

How can I resolve this? If you propose a fix, please make it concise.

@github-actions github-actions bot mentioned this pull request Mar 9, 2026
ErnestM1234 pushed a commit that referenced this pull request Mar 9, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## gt@2.8.0

### Minor Changes

- [#1088](#1088)
[`2cad388`](2cad388)
Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat: add
python support for registration

### Patch Changes

- Updated dependencies
\[[`2cad388`](2cad388)]:
    -   @generaltranslation/python-extractor@0.1.0

## @generaltranslation/python-extractor@0.1.0

### Minor Changes

- [#1088](#1088)
[`2cad388`](2cad388)
Thanks [@ErnestM1234](https://github.com/ErnestM1234)! - feat: add
python support for registration

## gtx-cli@2.8.0

### Patch Changes

- Updated dependencies
\[[`2cad388`](2cad388)]:
    -   gt@2.8.0

## locadex@1.0.112

### Patch Changes

- Updated dependencies
\[[`2cad388`](2cad388)]:
    -   gt@2.8.0

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

2 participants