Skip to content

Migrate IR and PxdWriter to headerkit#61

Draft
elijahr wants to merge 9 commits into
masterfrom
elijahr/headerkit-migration
Draft

Migrate IR and PxdWriter to headerkit#61
elijahr wants to merge 9 commits into
masterfrom
elijahr/headerkit-migration

Conversation

@elijahr

@elijahr elijahr commented Feb 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replace duplicated IR classes, PxdWriter, Cython type registries, and keyword lists with thin shim modules that re-export from headerkit
  • Shims provide 100% backward-compatible imports (zero changes needed for consuming code)
  • The ir_writer shim pre-configures stub_cimport_prefix="autopxd.stubs" to preserve autopxd2's stub cimport behavior
  • Update PycparserBackend.parse() signature to match headerkit's ParserBackend protocol
  • Delete test_ir.py (24 tests) and test_cython_types.py (15 tests) now maintained in headerkit
  • Net: -2,901 lines deleted, +104 lines added

Dependency

Requires headerkit v0.6.0 (PR pending).

Test plan

  • 359 tests pass, 2 skipped (pre-existing)
  • All pre-commit hooks pass (ruff, mypy --strict)
  • Stub cimport output identical (from autopxd.stubs.stdarg cimport va_list)
  • CI passes

Replace duplicated IR classes, PxdWriter, Cython type registries, and
keyword lists with thin shim modules that re-export from headerkit.
The shims provide 100% backward-compatible imports so no consuming
code needs changes.

The ir_writer shim subclasses headerkit's PxdWriter with
stub_cimport_prefix="autopxd.stubs" pre-configured, preserving
autopxd2's stub cimport behavior.

Update PycparserBackend.parse() signature to match headerkit's
ParserBackend protocol (accepts keyword-only params it doesn't use).

Delete test_ir.py (24 tests) and test_cython_types.py (15 tests)
which are now maintained in headerkit. All 359 remaining tests pass.
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the autopxd project by extracting core functionalities related to Intermediate Representation (IR) and Cython .pxd writing into a new, dedicated library called headerkit. This strategic move centralizes common parsing and writing logic, reducing code duplication and improving maintainability across related projects. The changes are implemented with backward compatibility in mind, using shim modules to ensure existing autopxd consumers can upgrade seamlessly without modifying their import paths.

Highlights

  • Core Logic Migration: Migrated duplicated Intermediate Representation (IR) classes, the PxdWriter, Cython type registries, and keyword lists from autopxd to the headerkit library.
  • Backward Compatibility: Implemented thin shim modules that re-export functionalities from headerkit, ensuring 100% backward-compatible imports for consuming code with zero changes required.
  • Pycparser Backend Update: Updated the PycparserBackend.parse() method signature to align with headerkit's ParserBackend protocol, introducing new parameters for parsing configuration.
  • Test Suite Consolidation: Removed test_ir.py (24 tests) and test_cython_types.py (15 tests) from autopxd, as their functionalities and tests are now maintained within headerkit.
  • Dependency Management: Added headerkit as a core dependency, specifically requiring headerkit v0.6.0.
  • Codebase Reduction: Achieved a significant reduction in codebase size, with a net change of -2,901 lines deleted and +104 lines added.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .pre-commit-config.yaml
    • Added headerkit as a development dependency for pre-commit hooks.
  • autopxd/init.py
    • Removed type: ignore[call-arg] comments from use_default_includes parameters in translate function calls.
  • autopxd/backends/pycparser_backend.py
    • Updated the parse method signature to include use_default_includes, recursive_includes, max_depth, and project_prefixes parameters, aligning with the ParserBackend protocol.
  • autopxd/cython_types.py
    • Replaced extensive local definitions of Cython type registries and lookup functions with imports from headerkit.writers._cython_types.
    • Added __all__ export list for backward compatibility.
  • autopxd/ir.py
    • Replaced extensive local definitions of IR classes and the ParserBackend protocol with imports from headerkit.ir.
    • Added __all__ export list for backward compatibility.
  • autopxd/ir_writer.py
    • Replaced the large local implementation of PxdWriter and write_pxd with imports from headerkit.writers.cython.
    • Modified the local PxdWriter to inherit from headerkit's PxdWriter and pre-configure the stub_cimport_prefix.
  • autopxd/keywords.py
    • Replaced local definitions of Cython and C keywords with imports from headerkit.writers._cython_keywords.
    • Added __all__ export list for backward compatibility.
  • pyproject.toml
    • Added headerkit to the project's core dependencies.
  • test/test_cython_types.py
    • Removed the entire test file, as its tests are now maintained in the headerkit repository.
  • test/test_ir.py
    • Removed the entire test file, as its tests are now maintained in the headerkit repository.
Activity
  • The author confirmed that 359 tests passed, with 2 pre-existing skipped tests.
  • All pre-commit hooks (ruff, mypy --strict) passed successfully.
  • The stub cimport output was verified to be identical, ensuring no regressions.
  • The author indicated that CI is expected to pass.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request is a major refactoring that migrates significant parts of the codebase (IR, PxdWriter, type registries) to a new external library, headerkit. This greatly reduces code duplication and centralizes the logic. The changes are well-structured, creating shim modules to maintain backward compatibility.

My review focuses on a few points related to dependency management and reliance on private APIs, which could affect the project's stability and build reproducibility. Overall, this is an excellent cleanup.

Comment thread pyproject.toml Outdated
]
requires-python = ">=3.10"
dependencies = ["Click", "pycparser"]
dependencies = ["Click", "pycparser", "headerkit"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The headerkit dependency is not pinned to the specific development version required by this PR, which is inconsistent with .pre-commit-config.yaml and will likely cause installation issues for anyone trying to build from this branch. To ensure the project is buildable, please pin it to the same git branch/commit.

Suggested change
dependencies = ["Click", "pycparser", "headerkit"]
dependencies = ["Click", "pycparser", "headerkit @ git+https://github.com/axiomantic/headerkit.git@elijahr/autopxd2-migration"]

Comment thread .pre-commit-config.yaml Outdated
additional_dependencies:
- pycparser
- click
- headerkit @ git+https://github.com/axiomantic/headerkit.git@v0.6.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better stability and reproducibility, it's recommended to pin this dependency to a specific commit hash instead of a branch name. Branches can be updated or deleted, which could break the pre-commit setup for others or in the future.

Comment thread autopxd/cython_types.py Outdated
Comment on lines +3 to +12
from headerkit.writers._cython_types import (
CYTHON_STDLIB_HEADERS,
CYTHON_STDLIB_TYPES,
HEADERKIT_STUB_TYPES,
LIBCPP_HEADERS,
LIBCPP_TYPES,
get_cython_module_for_type,
get_libcpp_module_for_type,
get_stub_module_for_type,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Importing from a private module (_cython_types) can be fragile as its API is not guaranteed to be stable across headerkit versions. It would be more robust to import these from a public API within headerkit if possible. Consider exposing these symbols in headerkit.writers.cython or a similar public module.

Comment thread autopxd/keywords.py Outdated
Comment on lines +3 to +7
from headerkit.writers._cython_keywords import (
C_keywords,
cython_keywords,
keywords,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Similar to cython_types.py, this module imports from a private headerkit module (_cython_keywords). This creates a dependency on headerkit's internal implementation, which might change unexpectedly. It's recommended to rely on public APIs. Please consider exposing these keywords through a public module in headerkit.

BREAKING CHANGE: Remove autopxd.cython_types and autopxd.keywords
modules (zero consumers after migration to headerkit shims).

Remove dead elif/else branches in translate() for backends not
supporting full ParserBackend protocol (both backends now do).

Remove unused IGNORE_DECLARATIONS and STDINT_DECLARATIONS from
declarations.py. Fix stale test reference in contributing docs.

Bump to 4.0.0.
BREAKING CHANGE: The pycparser backend has been removed. libclang is
now the only parser backend. Install libclang via your system package
manager or headerkit's install_libclang tool.

Remove pycparser_backend.py, declarations.py, regenerate_stubs.py,
and all pycparser fake header stubs (stubs/include/, stubs/darwin-include/).
Remove pycparser from runtime dependencies.

Simplify resolve_backend() and CLI: --backend only accepts "auto" or
"libclang". Remove validate_libclang_options() (moot with single backend).
Remove FALLBACK_WARNING (no pycparser fallback).

Convert all pycparser-specific tests to use libclang backend.
Update all documentation to reflect single-backend architecture.
The expected file was written for the old pycparser-based writer. The
headerkit CythonWriter produces a different (correct) ordering:
forward declarations and typedefs first, then enums with cdef instead
of ctypedef, globals before struct bodies, ctypedef struct for Buffer,
and parameter names stripped from function pointer typedefs.
@elijahr elijahr marked this pull request as draft February 28, 2026 23:35
Configure Dependabot for pip and github-actions ecosystems with weekly
schedules and grouped minor/patch updates. Add a scheduled workflow to
run pre-commit autoupdate weekly and create PRs for hook version bumps.
- Add .github/dependabot.yml for pip and github-actions ecosystems
- Add pre-commit autoupdate workflow (weekly, via peter-evans/create-pull-request)
- Bump headerkit dependency to >=0.6.1,<1.0.0
- Update pre-commit mypy headerkit pin to v0.6.1
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.

1 participant