Skip to content

Add optional ahead-of-time native module compiler - #139

Open
sharktide wants to merge 4 commits into
mainfrom
optimizer/aot-build
Open

sharktide wants to merge 4 commits into
mainfrom
optimizer/aot-build

Conversation

@sharktide

@sharktide sharktide commented Dec 6, 2026 •

Copy link
Copy Markdown
Owner

Add repy-aot for trusted REPY modules, optional Cython/setuptools build dependencies, checked compilation directives, explicit typed mode, platform-specific extension output with Python fallback, staged new-directory builds and cross-platform integration tests. Native artifacts are built offline rather than on application startup. Cython semantics are opt-in and must be validated; no claims of universal compatibility or speedup.

Summary by Sourcery

Add an optional offline native-compilation workflow for trusted REPY modules while retaining generated Python as a fallback.

New Features:

  • Add an optional repy-aot command to build trusted REPY modules as platform-specific native extensions, alongside generated Python fallbacks.
  • Support explicit Cython typed mode, Python-only output, and dotted-module artifacts for overlaying into existing packages.

Enhancements:

  • Require a new output directory and validate module names and generated Python before publishing build artifacts.

Build:

  • Add an aot optional dependency group for Cython and setuptools.

CI:

  • Add an AOT workflow that tests native builds across Ubuntu, Windows, macOS, and multiple Python versions.

Documentation:

  • Document AOT usage, import fallback behavior, typed-mode semantics, trust considerations, and build/deployment guidance in docs/aot.md.

Tests:

  • Add coverage for Python-only output, output-directory protection, invalid input, dotted module trees, native/fallback imports, and typed compilation.

@sourcery-ai

sourcery-ai Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Define the public AOT build function and command-line options for producing Python-only or native module artifacts.

  • pyproject.toml L29
  • restructuredpython/aot.py L62-75, L111-132

Implementation

Implement module-name validation, checked Cython compilation, and staged publication of generated Python and native artifacts.

  • restructuredpython/aot.py L1-61, L76-110

Configuration

Declare optional AOT build dependencies and run cross-platform, multi-Python AOT tests in CI.

  • .github/workflows/aot.yml L1-26
  • pyproject.toml L23-25

Documentation

Document installation, artifact/import behavior, typed-mode implications, overlay builds, and trust constraints.

  • docs/aot.md L1-36

Tests

Check Python fallback, destination and input validation, native and typed builds, and dotted-module artifact layout.

  • tests/test_aot.py L1-95

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've found 4 issues


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread restructuredpython/aot.py Resolved
Comment thread restructuredpython/aot.py
Comment on lines +83 to +84
fallback = output / relative
fallback.parent.mkdir(parents=True)

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 · Dotted imports resolve to another package

When a dotted module name is built and a regular package with the same parent name exists elsewhere on sys.path, build_module creates package directories without __init__.py, so Python selects the regular package and ignores the generated namespace-package portion; importing the requested module fails or loads the other package’s version.

Ensure generated dotted modules resolve to the build output even when a regular package with the same name is on sys.path.

Comment thread docs/aot.md Resolved
Comment thread restructuredpython/aot.py Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant