Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,18 @@ jobs:
run: |
$wheels = (Get-ChildItem dist\*.whl -Recurse).FullName
$releaseFound = $false
for ($attempt = 1; $attempt -le 40; $attempt++) {
for ($attempt = 1; $attempt -le 120; $attempt++) {
& gh release view $env:TAG --repo $env:GH_REPO *> $null
if ($LASTEXITCODE -eq 0) {
$releaseFound = $true
break
}
Write-Host "Waiting for the JavaScript release $env:TAG ($attempt/40)..."
Write-Host "Waiting for the JavaScript release $env:TAG ($attempt/120)..."
Start-Sleep -Seconds 30
}

if (-not $releaseFound) {
throw "JavaScript GitHub release $env:TAG was not found after 20 minutes"
throw "JavaScript GitHub release $env:TAG was not found after 60 minutes"
}

$arguments = @('release', 'upload', $env:TAG, '--repo', $env:GH_REPO, '--clobber')
Expand Down
16 changes: 8 additions & 8 deletions .pipelines/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ parameters:
- name: PublishPyPI
displayName: Publish Python packages to PyPI
type: boolean
default: false
default: true
- name: signingIdentity
type: object
default:
Expand Down Expand Up @@ -297,7 +297,7 @@ extends:
}

$ready = $false
for ($attempt = 1; $attempt -le 20; $attempt++) {
for ($attempt = 1; $attempt -le 60; $attempt++) {
$jobs = Invoke-GitHubApi "$($run.jobs_url)?per_page=100"
$assembly = @($jobs.jobs | Where-Object name -EQ 'assemble-release')
if ($assembly.Count -eq 1 -and $assembly[0].status -eq 'completed') {
Expand All @@ -310,11 +310,11 @@ extends:
if ($run.status -eq 'completed' -and $run.conclusion -ne 'success') {
throw "Python tag workflow concluded '$($run.conclusion)'"
}
Write-Host "Waiting for Python release assembly (attempt $attempt/20)..."
Write-Host "Waiting for Python release assembly (attempt $attempt/60)..."
Start-Sleep -Seconds 60
}
if (-not $ready) {
throw 'Python release assembly did not pass within 20 minutes'
throw 'Python release assembly did not pass within 60 minutes'
}

- stage: Release_GitHub
Expand Down Expand Up @@ -367,7 +367,7 @@ extends:
```bash
npm install @microsoft/dynwinrt
npm install -D @microsoft/dynwinrt-codegen
python -m pip install dynwinrt dynwinrt-codegen
python -m pip install --pre dynwinrt dynwinrt-codegen
```

## What's Included
Expand Down Expand Up @@ -426,7 +426,7 @@ extends:
}
}
$ready = $false
for ($attempt = 1; $attempt -le 40; $attempt++) {
for ($attempt = 1; $attempt -le 120; $attempt++) {
$release = Invoke-GitHubApi $uri
if ($release.target_commitish -ne '$(Build.SourceVersion)') {
throw "GitHub release target '$($release.target_commitish)' does not match $(Build.SourceVersion)"
Expand All @@ -439,11 +439,11 @@ extends:
if ($wheels.Count -gt 10) {
throw "Expected 10 Python wheel assets, found $($wheels.Count)"
}
Write-Host "Waiting for Python release wheels ($($wheels.Count)/10, attempt $attempt/40)..."
Write-Host "Waiting for Python release wheels ($($wheels.Count)/10, attempt $attempt/120)..."
Start-Sleep -Seconds 30
}
if (-not $ready) {
throw 'The complete tested Python wheel set was not attached within 20 minutes'
throw 'The complete tested Python wheel set was not attached within 60 minutes'
}

- task: DownloadGitHubRelease@0
Expand Down
217 changes: 87 additions & 130 deletions bindings/py/README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,20 @@
# dynwinrt

`dynwinrt` is the native CPython runtime for generated dynwinrt projections.
Release wheels support CPython 3.11 through 3.14 on Windows x64 and ARM64.
The floor is intentionally the first CPython line for which the release
infrastructure can install and execute a native Windows ARM64 interpreter; the
project does not ship cross-compiled, untested ARM64 wheels.
`dynwinrt` is the native CPython runtime for Python projections generated by
[`dynwinrt-codegen`](https://pypi.org/project/dynwinrt-codegen/). It supports
CPython 3.11–3.14 on Windows x64 and ARM64.

Install the runtime and the standalone generator from an approved feed or a
downloaded release:
## Install

```powershell
python -m pip install dynwinrt dynwinrt-codegen
python -m pip install --pre dynwinrt dynwinrt-codegen
dynwinrt-codegen generate --namespace Windows.Foundation --class-name Uri `
--lang py --output generated_uri
```

Generated Python package manifests pin `dynwinrt` to exactly the version of
`dynwinrt-codegen` that emitted them.

## Develop

Run `uv run maturin develop` to build the package

Use `uv run pytest` to run the tests

After modification `uv sync --reinstall` may be needed to reinstall the package

The wheel includes `__init__.pyi` and `py.typed` for static type checking.

## Release process

`.github\workflows\python-release.yml` builds and consumes every CPython
3.11–3.14 runtime wheel on x64 and native ARM64. It also builds standalone
`py3-none-win_amd64` and `py3-none-win_arm64` codegen wheels, then exercises the
installed command with Rust removed from `PATH`.

Pull requests run the x64 matrix. ARM64 jobs run only for manual dispatches and
`v*` release tags on GitHub-hosted `windows-11-vs2026-arm` runners. A release
remains blocked rather than producing ARM64 artifacts if one of its native
CPython versions cannot build or pass its isolated consumer test.

To release:

1. Create the ordinary repository release tag (for example,
`v0.1.0-preview.20`). The workflow derives the Python package version from
the tag and updates its build workspaces without modifying the repository.
PEP 440 normalizes `preview.N` wheel versions to `rcN`.
2. The official 1ES ADO release pipeline creates the shared GitHub release and
publishes the npm packages. After all ten Python wheels pass their
consumption tests, the GitHub workflow uploads them alongside the npm
tarballs. It never creates a separate Python GitHub release.
3. The ADO pipeline waits for the complete wheel set, downloads it through the
repository's GitHub service connection, and revalidates every filename,
platform tag, Python ABI tag, metadata record, type stub, and native payload.
4. PyPI publication is opt-in: the ADO `PublishPyPI` parameter is disabled by
default. When explicitly enabled with `DoEsrp`, ADO publishes the eight
`dynwinrt` wheels first and the two `dynwinrt-codegen` wheels second through
the Microsoft ESRP release identity. PyPI publication is not available from
GitHub Actions.

Before the first release, onboard both PyPI project names to the configured ESRP
service connection and confirm the signing identity, owners, and approvers.
Generated package manifests pin `dynwinrt` to the exact version of
`dynwinrt-codegen` that produced them. The runtime wheel includes
`__init__.pyi` and `py.typed` for static type checking.

Generated `IReference<T>` values are projected as `T | None`; native values,
`None`, and generated `IReference_*` wrappers are accepted as inputs.
Expand All @@ -81,7 +35,7 @@ Regenerated bindings no longer block inside async methods. Existing code that
expects an immediate result must use `await operation` or `operation.wait()`.

`asyncio` task cancellation calls `IAsyncInfo.Cancel()` on the underlying
WinRT operation. Operations with scalar progress values also expose
WinRT operation. Operations with supported progress values also expose
`operation.progress(callback)`. Fast operations can finish before registration;
in that case no future progress exists and registration is a no-op.

Expand All @@ -98,8 +52,9 @@ restricted WinRT error information when Windows provides it.

Generated collection projections implement the standard `collections.abc`
protocols: vectors behave as sequences, maps as mappings, and WinRT iterables
and iterators work with `iter()` and `next()`. Mutable vectors and maps support
normal indexing, slicing, assignment, insertion, and deletion.
and iterators work with `iter()` and `next()`. Mutable vectors support indexing,
slicing, assignment, insertion, and deletion; mutable maps support standard
mapping assignment and deletion.

Method inputs accept normal Python sequences and mappings in place of compatible
WinRT collection interfaces. Byte arrays accept `bytes` and `bytearray`; GUID,
Expand Down Expand Up @@ -184,40 +139,27 @@ Generated runtime classes that implement `IClosable` support `with` and an
idempotent `close()` method. Prefer deterministic cleanup instead of relying on
Python garbage collection.

## Experimental WinUI bootstrap

When `Microsoft.UI.Xaml.Application` is generated with the WinUI metadata
provider and controls resources, codegen also emits
`Application.create_with_metadata_provider(...)` and `Application.create(...)`.
The latter installs `XamlControlsResources` and configures unpackaged resource
resolution when the required metadata is available.

Public composable constructors keep their existing exact-class behavior. A
Python subclass of such a class is constructed with a non-null aggregated outer,
so ordinary inherited WinUI properties and methods retain one COM identity.
Metadata-supported native overrides are exposed through local overridable
interfaces. WinUI `IFrameworkElementOverrides.MeasureOverride`,
`ArrangeOverride`, and `OnApplyTemplate` are supported; size callbacks receive
and return `(width, height)` tuples. Callbacks run synchronously on the creating
WinUI apartment under the `ContextVar` context captured during construction.
Exceptions are reported through `sys.unraisablehook` and returned to WinUI as a
failing HRESULT. Unsupported override ABI shapes raise `TypeError` during
subclass construction.

The WinUI 2.3 metadata contract used by the live test is
`IFrameworkElementOverrides`
(`ffc6fd98-f38c-5904-9ce4-97a3427cf4ba`): inherited by `StackPanel`, with
`MeasureOverride(Size) -> Size` at slot 6, `ArrangeOverride(Size) -> Size` at
slot 7, `OnApplyTemplate() -> void` at slot 8, and
`GoToElementStateCore(HSTRING, Boolean) -> Boolean` at slot 9. `Size` is two
ABI `f32` fields. Parameters are borrowed for the synchronous call and the
result is caller-owned out storage. StackPanel is metadata-agile, while Python
override callbacks remain intentionally bound to their creating UI apartment.

Publicly composable controls can also register a Python subclass for XAML
markup activation:
## Experimental WinUI support

When the required WinUI metadata is generated, `Application.create()` installs
`XamlControlsResources` and configures unpackaged resource resolution.
`Application.create_with_metadata_provider(...)` is available when the
application supplies its own provider.

Python subclasses of public composable controls preserve one COM identity for
inherited properties and methods. Metadata-supported
`measure_override`, `arrange_override`, and `on_apply_template` callbacks run
synchronously on the creating UI apartment with the `contextvars` context
captured during construction. Unsupported native override shapes fail during
construction instead of falling back to an unsafe ABI.

After creating the generated application, publicly composable controls can
register a Python subclass for activation by `XamlReader`:

```python
from generated.microsoft.ui.xaml.controls import StackPanel
from generated.microsoft.ui.xaml.markup import XamlReader

class PythonPanel(StackPanel):
def measure_override(self, available_size):
return available_size
Expand All @@ -226,44 +168,36 @@ registration = StackPanel.register_xaml_runtime_class(
"MyApp.Controls.PythonPanel",
PythonPanel,
)
panel = StackPanel(XamlReader.load(
'<local:PythonPanel xmlns:local="using:MyApp.Controls" />'
))
# Remove every instance from the XAML tree before releasing Python owners.
raw_panel = XamlReader.load(
'<local:PythonPanel '
'xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" '
'xmlns:local="using:MyApp.Controls" />'
)
if raw_panel is None:
raise RuntimeError("XamlReader returned no value")
panel = StackPanel(raw_panel)

# First remove every instance from the XAML tree and release application owners.
panel = None
raw_panel = None
registration.unregister()
registration.release_instances()
```

Registrations are process-local, duplicate names fail, and dropping or closing
the returned registration removes new lookups. The composed Application
metadata provider checks Python registrations before
`XamlControlsXamlMetaDataProvider`. Its `IXamlType` delegates inherited content
and member metadata to the declared WinUI base and activates through the Python
constructor on the registering STA. Constructor callbacks and captured `ContextVar` context remain available for
new activation until unregister. XAML-created Python owners stay process-rooted
until `release_instances()` so live native controls cannot lose their override
targets; call it only after those controls leave the XAML tree. Unsupported native
override ABIs, generic names, collection/dictionary/markup-extension bases, and
Python-defined XAML members fail closed.

This deliberately does **not** call `RoRegisterActivationFactories`: ordinary
`RoActivateInstance("MyApp.Controls.PythonPanel")` remains unavailable.
`XamlReader` does not need that global activation path; WinUI resolves the name
through `IXamlMetadataProvider` and calls `IXamlType.ActivateInstance` directly
(WinUI source: `components/metadata/MetadataAPI.cpp` and
`ExtMetadataProvider/XamlType.cpp`). A class that must be activated outside this
Application/XAML provider boundary still requires a static WinMD plus packaged
manifest/in-process server registration. Protected composition and
system-returned classes remain non-constructible.
Registrations are process-local, and duplicate names fail. Unregistering,
closing, or dropping the registration prevents new XAML metadata lookups.
XAML-created Python owners remain rooted until `release_instances()`; call it
only after every corresponding native control has left the XAML tree.
Registration does not make the class globally activatable through
`RoActivateInstance`.

Generated `Application.start()` and `DispatcherQueue.run_event_loop()` calls
remain on the caller's native thread but release the Python GIL while WinUI
pumps messages. WinRT callbacks reacquire the GIL, and worker-thread asyncio
code can use `DispatcherQueue.try_enqueue()` to return to the UI thread.
stay on the caller's native thread but release the Python GIL while WinUI pumps
messages. WinRT callbacks reacquire the GIL, and worker threads can use
`DispatcherQueue.try_enqueue()` to return to the UI thread.

Use a projected lifetime scope inside the COM apartment so generated wrappers
release their native values before `RoUninitialize`:
Use a projection lifetime scope inside the COM apartment so wrappers release
their native values before `RoUninitialize`:

```python
from dynwinrt import RoApartment, projected_lifetime_scope
Expand All @@ -273,17 +207,40 @@ with RoApartment(0), projected_lifetime_scope():
# Create and use WinUI objects here.
```

Scopes nest in LIFO order. Wrappers that survive the scope remain Python
objects, but their native values are released and further WinRT calls fail
instead of releasing COM references after apartment teardown.
Scopes nest in LIFO order. Wrappers that survive a closed scope remain Python
objects, but their native values are released and further WinRT calls fail.

Normal construction remains unavailable for protected-only composable classes
and system-returned classes without public activation metadata. Named Python
XAML registration does not support generic names, collection or dictionary
bases, markup-extension bases, or Python-defined XAML members.

The live x64 smoke test accepts explicit WinAppSDK metadata and bootstrap
inputs:
## Develop

From `bindings\py`:

```powershell
.\tests\e2e\python_winui_e2e.ps1 `
-WinuiWinmd <Microsoft.UI.Xaml.winmd> `
-RefList <winmd-reference-list.txt> `
-BootstrapDll <Microsoft.WindowsAppRuntime.Bootstrap.dll> `
-Major 2 -Minor 3
```
python -m pip install "maturin>=1.11,<2" "pytest>=8.3.5" "mypy>=1.13,<2"
python -m maturin develop
python -m pytest
```

## Release process

The release tag supplies one unified npm/Cargo version. For example,
`v0.1.0-preview.21` produces npm version `0.1.0-preview.21` and Python version
`0.1.0rc21` after PEP 440 normalization.

1. GitHub Actions builds and consumes eight CPython 3.11–3.14 runtime wheels
and two standalone codegen wheels on Windows x64 and native ARM64.
2. The official 1ES ADO pipeline builds both npm packages and waits for the
complete Python wheel matrix.
3. ADO creates one shared GitHub Release with the npm tarballs. GitHub Actions
attaches the ten tested Python wheels, and ADO downloads and revalidates the
complete set.
4. With `DoEsrp` enabled, ADO publishes both npm packages. `PublishPyPI`
defaults to enabled and publishes the eight `dynwinrt` wheels before the two
`dynwinrt-codegen` wheels. Disable it only for a non-PyPI rehearsal.

PyPI publication uses the Microsoft ESRP release identity and is not available
from GitHub Actions.
1 change: 1 addition & 0 deletions bindings/py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ build-backend = "maturin"
[project]
name = "dynwinrt"
description = "Python bindings for dynamic WinRT API invocation"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11,<3.15"
license = {text = "MIT"}
authors = [
Expand Down
6 changes: 3 additions & 3 deletions docs/status/PYTHON_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ of a dynamic projection.
wheel set to the shared JavaScript GitHub release.
- [ ] Publish signed/provenanced wheels to an approved internal Python feed.
- [x] Route production PyPI publication through the official 1ES ADO release
pipeline and Microsoft ESRP identity, behind the opt-in `PublishPyPI`
parameter that is disabled by default.
- [ ] Complete one-time ESRP/PyPI onboarding for `dynwinrt` and
pipeline and Microsoft ESRP identity. `PublishPyPI` is enabled by default
for tag releases and can be disabled for non-PyPI rehearsals.
- [x] Complete one-time ESRP/PyPI onboarding for `dynwinrt` and
`dynwinrt-codegen`, including release owners and approvers.
- [x] Add complete tested Python wheel assets and installation notes to GitHub
releases.
Expand Down
Loading
Loading