Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document py-limited-api option #583

Open
bgilbert opened this issue Nov 11, 2023 · 0 comments
Open

Document py-limited-api option #583

bgilbert opened this issue Nov 11, 2023 · 0 comments

Comments

@bgilbert
Copy link
Contributor

bgilbert commented Nov 11, 2023

To tag a wheel containing C extension modules as compatible with multiple Python releases, one must specify the undocumented py-limited-api option, setting it to the minimum Python version supported by the wheel. Otherwise the wheel will be tagged for the current Python release only, even if its C extension modules are built against the Python Limited API.

For the record, in setup.cfg this looks like:

[bdist_wheel]
py-limited-api = cp311

Or in pyproject.toml: — see #582 (comment)

[tool.distutils.bdist_wheel]
py-limited-api = "cp311"

Or in setup.py:

setup(
    [...],
    options={'bdist_wheel': {'py_limited_api': 'cp311'}},
)

The latter is useful (alongside define_macros=[('Py_LIMITED_API', '0x...')]) if you need to programmatically disable the abi3 compatibility tag on older Python releases that haven't stabilized the API functions you need.

Please document this. I found it quite confusing: I defined Py_LIMITED_API, specified Extension(..., py_limited_api=True), and still got an incorrectly tagged wheel. It isn't necessarily obvious that setuptools and wheel don't share configuration, and the lack of documentation makes the problem hard to track down.

Sachaa-Thanasius added a commit to Sachaa-Thanasius/audioop that referenced this issue Apr 24, 2024
AbstractUmbra added a commit to AbstractUmbra/audioop that referenced this issue Apr 25, 2024
* Initial attempt to make some changes for abi3-compatibility.

* Massive rearrangement.
- Put source files in one package.
- Add an __init__.py and __init__.pyi to provide a target for type stubs.
 - Probably too eager; typeshed will probably provide these until 3.12 is EOL.
- Change setup configuration to
 a. Put as much as possible in pyproject.toml.
 b. Eliminate the need for setup.cfg.
 c. Don't break everything when attempting to build with `build` — the audioop header file just wasn't being seen.
- Most importantly, make it abi3. i.e., the resulting wheel should be compatible for >=3.12 environments.

* Account for some type errors and missing braces for an if clause.

* Slight bit of cleanup in pyproject.toml and setup.py.

* Revert the upgraded requirement to 3.12; it's true and makes it less annoying to publish before 3.13.0.

* Fix license name

Used the wrong one out of habit.

* Don't lie too much for the abi tag.
- More of a footgun than anything.

* change ci to work on PRs

* pin to the 3.13 rc for devcontainer, not a specific patch version

* update project meta, name and python version constraints

* Based on feedback, do restrict install to >=3.13.
- Add a note in setup.py about the limited API compatibility being more permissive but would lead to potential clobbering if requires-python matched it.

* Fix typo in comment and expand slightly.

* Add a py.typed file.

* change ci to work on PRs

* pin to the 3.13 rc for devcontainer, not a specific patch version

* update project meta, name and python version constraints

* Remove setup.cfg again and update project name.

* Ugly, but adding this back for a moment might fix the merge conflict?

* And now delete it again.

* Initial attempt to make some changes for abi3-compatibility.

* Massive rearrangement.
- Put source files in one package.
- Add an __init__.py and __init__.pyi to provide a target for type stubs.
 - Probably too eager; typeshed will probably provide these until 3.12 is EOL.
- Change setup configuration to
 a. Put as much as possible in pyproject.toml.
 b. Eliminate the need for setup.cfg.
 c. Don't break everything when attempting to build with `build` — the audioop header file just wasn't being seen.
- Most importantly, make it abi3. i.e., the resulting wheel should be compatible for >=3.12 environments.

* Account for some type errors and missing braces for an if clause.

* Slight bit of cleanup in pyproject.toml and setup.py.

* Revert the upgraded requirement to 3.12; it's true and makes it less annoying to publish before 3.13.0.

* Fix license name

Used the wrong one out of habit.

* Don't lie too much for the abi tag.
- More of a footgun than anything.

* Based on feedback, do restrict install to >=3.13.
- Add a note in setup.py about the limited API compatibility being more permissive but would lead to potential clobbering if requires-python matched it.

* Fix typo in comment and expand slightly.

* Add a py.typed file.

* Implement the limited api and abi3 tag in a less hacky way.

Source: pypa/wheel#583

* Hardcode the limited api version on the wheel (both the macro and the tag) to be 3.13.
- This should be the final necessary measure to avoid clobbering.

* Remove a now unnecessary comment.

* Improve types beyond what typeshed has.
- Typeshed has argument types as `bytes` to substitute for buffers since buffers didn't have a representation in the type system for a long time. Now that `collections.abc.Buffer` exists, there's a better alternative.
 - This means that memoryview, bytarray, etc. won't show up as type-checker errors when given as inputs.
- Tests actually type-check as a result. No changes to logic were made, just type annotations.
- TODO: Consider upstreaming to typeshed?

Reference material:
- https://docs.python.org/3/library/typing.html#typing.ByteString
- https://docs.python.org/3/library/collections.abc.html#collections.abc.Buffer
- https://peps.python.org/pep-0688
 - "No special meaning for bytes" mentions why these were annotated with `bytes` before.
- https://typing.readthedocs.io/en/latest/source/modernizing.html#typing-bytestring

---------

Co-authored-by: Alex Nørgaard <umbra@abstractumbra.dev>
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

No branches or pull requests

1 participant