Skip to content

Commit 131f4bf

Browse files
committed
feat: Switch to parsing the TOML instead of the text file.
1 parent efc4213 commit 131f4bf

File tree

4 files changed

+169
-171
lines changed

4 files changed

+169
-171
lines changed

.github/workflows/update.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Update stable_abi.txt
1+
name: Update stable_abi.toml
22

33
on:
44
workflow_dispatch:
@@ -8,22 +8,26 @@ on:
88

99
jobs:
1010
update:
11-
name: Update stable_abi.txt
11+
name: Update stable_abi.toml
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v3
15-
- name: Fetch latest stable_abi.txt
15+
- name: Fetch latest stable_abi.toml
1616
run: |
17-
curl https://raw.githubusercontent.com/python/cpython/main/Misc/stable_abi.txt > stable_abi.txt
18-
- name: Parse stable_abi.txt to produce python3.def
17+
curl https://raw.githubusercontent.com/python/cpython/main/Misc/stable_abi.toml > stable_abi.toml
18+
- name: Install Python TOML parser
1919
run: |
20-
./parse-stable-abi.py < stable_abi.txt > src/python3.def
20+
sudo apt-get install --yes python3-pip
21+
pip install tomli
22+
- name: Parse stable_abi.toml to produce python3.def
23+
run: |
24+
./parse-stable-abi.py < stable_abi.toml > src/python3.def
2125
- name: Create Pull Request
2226
uses: peter-evans/create-pull-request@v4
2327
with:
2428
delete-branch: true
2529
add-paths: |
2630
src/python3.def
27-
title: 'Update python3.def using stable_abi.txt from the latest main'
28-
commit-message: 'chore: Update python3.def using stable_abi.txt from the latest main'
29-
body: 'Source: https://raw.githubusercontent.com/python/cpython/main/Misc/stable_abi.txt'
31+
title: 'Update python3.def using stable_abi.toml from the latest main'
32+
commit-message: 'chore: Update python3.def using stable_abi.toml from the latest main'
33+
body: 'Source: https://raw.githubusercontent.com/python/cpython/main/Misc/stable_abi.toml'

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,11 @@ PYO3_CROSS_LIB_DIR=target/python3-dll cargo build --target x86_64-pc-windows-gnu
7575
Maintenance
7676
-----------
7777

78-
This crate embeds the `stable_abi.txt` definitions file from CPython
79-
in the `Misc` subdirectory.
78+
This crate embeds Module-Defitions based on the `stable_abi.toml` file from CPython.
8079

8180
The upstream version of this file is located in the [CPython project][cpython]
82-
repository under the same path.
81+
repository under the path `Misc/stable_abi.toml`.
8382
This file should be updated for every subsequent CPython release
8483
(e.g. for CPython 3.12).
8584

86-
[cpython]: https://github.com/python/cpython/blob/main/Misc/stable_abi.txt
85+
[cpython]: https://github.com/python/cpython/blob/main/Misc/stable_abi.toml

parse-stable-abi.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
#!/usr/bin/env python3
2-
# Parses Python Stable ABI symbol definitions from the manifest in the CPython repository located at https://github.com/python/cpython/blob/main/Misc/stable_abi.txt
2+
# Parses Python Stable ABI symbol definitions from the manifest in the CPython repository located at https://github.com/python/cpython/blob/main/Misc/stable_abi.toml
33
# and produces a definition file following the format described at https://docs.microsoft.com/en-us/cpp/build/reference/module-definition-dot-def-files.
44
import sys
5+
import tomli
6+
7+
stable_abi = tomli.load(sys.stdin.buffer)
58

69
print("LIBRARY python3.dll")
710
print("EXPORTS")
811

912
count = 0
1013

11-
for line in sys.stdin:
12-
if line.startswith("function"):
13-
is_data = False
14-
elif line.startswith("data"):
15-
is_data = True
16-
else:
17-
continue
18-
14+
for function in stable_abi["function"].keys():
15+
print(function)
1916
count += 1
20-
name = line.split()[1]
2117

22-
if is_data:
23-
print(f"{name} DATA")
24-
else:
25-
print(name)
18+
for data in stable_abi["data"].keys():
19+
print(f"{data} DATA")
20+
count += 1
2621

27-
assert count >= 859
22+
assert count >= 861

0 commit comments

Comments
 (0)