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

Build and publish to PyPI via CI, use Limited API (Stable ABI) #2

Merged
merged 16 commits into from
Feb 14, 2024

Conversation

laurence-myers
Copy link
Collaborator

@laurence-myers laurence-myers commented Jan 27, 2024

  • Remove support for Python v2
  • Move project metadata into pyproject.toml
    • Add Adam Biser to the list of authors
    • Add myself (Laurence Dougal Myers) to the list of maintainers
    • Add minimum Python version of 3.8
    • Increase version to 2.0 (due to breaking changes)
    • Use SPDX identifier for license, change the classifier to GPLv3
  • Replace distutils with setuptools
  • Add GitHub Actions CI
  • Use the Limited API (Static ABI) when building wheels for Python v3.11 or higher. This should allow the wheel to run on any future Python version.
    • setup.py: When building Python v3.11 or higher:
      • Set macro Py_LIMITED_API
      • Set option py_limited_api
      • Add tags cp311 and abi3 (cp311 is the lowest supported version)
    • pyopl.cpp:
      • Use a heap-allocated (dynamic) type to define PyOPLType. (Static types aren't supported by the Limited API.)
      • Replace tp_alloc() call with direct call to PyType_GenericAlloc. (The type object doesn't seem to be accessible in the Limited API, and I couldn't work out how to look up the tp_alloc pointer without a type object, so I've just assumed it will always use the default generic allocator.)
  • Convert README to Markdown
  • pyopl.pyi: give type hint bytearray for buffer
  • .gitignore: ignore IDEA project dir, wheel build dirs, and venv (virtual environment) dir

Minimum supported version

The minimum supported version of Python is v3.8, since this is the oldest actively maintained version.

Python release status chart 2024-01-27 12_18_24-Status of Python versions — Mozilla Firefox

https://devguide.python.org/versions/

ABI3 audit

It's possible to tag a wheel as adhering to abi3 when it doesn't really, so I ran abi3audit, which didn't find any problems.

2024-01-27 12_36_59-pyopl – Repository Diff_ pyopl cpp

Testing

I've only tested the module on Python 3.11, Windows 64-bit.

PyPI entry

https://test.pypi.org/project/PyOPL/

Here's how the PyPI entry looks.

Click to see screenshots 2024-01-27 12_44_20-PyOPL · TestPyPI — Mozilla Firefox 2024-01-27 12_44_40-PyOPL · TestPyPI — Mozilla Firefox 2024-01-27 12_44_49-PyOPL · TestPyPI — Mozilla Firefox

CI workflow

Here's an example CI run.

https://github.com/Malvineous/pyopl/actions/runs/7668724733

Click to see screenshots 2024-01-27 12_48_41-release_pre-2 0-3 · Malvineous_pyopl@93bdb92 — Mozilla Firefox 2024-01-27 12_48_36-release_pre-2 0-3 · Malvineous_pyopl@93bdb92 — Mozilla Firefox 2024-01-27 12_48_29-release_pre-2 0-3 · Malvineous_pyopl@93bdb92 — Mozilla Firefox

Building on Python 3.12 is skipped, because the build for v3.11 supports the stable ABI, so no need for a new wheel.

2024-01-27 12_49_10-release_pre-2 0-3 · Malvineous_pyopl@93bdb92 — Mozilla Firefox

Closes #1

- Move metadata from setup.py into pyproject.toml
  - Add Adam Biser to the list of authors
  - Add myself (Laurence Dougal Myers) to the list of maintainers
  - Add minimum Python version of 2.7
  - Increase version to 1.4
- Produce a wheel
- setup.py: replace `distutils` with `setuptools`
- README: convert to Markdown; add more contributor copyrights; update the example scripts.
- .gitignore: ignore IDEA project dir, wheel build dirs, and venv (virtual environment) dir
Skip Python 3.6, which produces `UNKNOWN-` eggs due to bugs picking up system-level build dependencies,
and Python 3.7. They've both reached EOL and are no longer supported.

Taken directly from the docs.

@see https://cibuildwheel.readthedocs.io/en/v2.16.2/setup/#github-actions
Remove cibuildwheel config to skip Python 3.6 and 3.7, just set the minimum version to v3.8
… artifacts. Use v4 of upload/download actions.
- Use SPDX license identifier. (Otherwise, PyPI tries to list the license file body)
- Change license classifier to specifically reference GPLv3 (only).
- Add an email for Adam Biser in `authors`, to avoid bugs in PyPI using a mix of authors with/without email.

@see pypi/warehouse#9400
@laurence-myers
Copy link
Collaborator Author

@adambiser If you have time, I'd appreciate if you could have a quick look over my changes, particularly the C++ side.

Copy link
Owner

@Malvineous Malvineous left a comment

Choose a reason for hiding this comment

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

Can't comment too much on the accuracy of the code as it's been years since I've been involved with Python, but nothing immediately stands out as problematic - it looks good. Thanks for taking the time to do all these updates!

Copy link
Contributor

@adambiser adambiser left a comment

Choose a reason for hiding this comment

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

The changes look correct to me.

This should allow all future versions of Python to run PyOPL, without needing a wheel
built just for that version.

## Changes

- setup.py: When building Python v3.11 or higher:
  - Set macro `Py_LIMITED_API`
  - Set option `py_limited_api`
  - Add tags `cp311` and `abi3` (cp311 is the lowest supported version)
- pyopl.cpp:
  - Use a heap-allocated (dynamic) type. (Static types aren't supported by the Static ABI)
  - Replace `tp_alloc()` call with direct call to `PyType_GenericAlloc`. (The type object doesn't seem to be accessible in the static ABI, and I couldn't work out how to look up the `tp_alloc` pointer, so I've just assumed it will always use the default generic allocator)
- Change version to 2.0
- Publish to PyPI proper (not the Test PyPI)
- Fix tests by CDing into the project directory.
- Fix types to be compatible with Python v3.8.
- Fix travelling up to test parent directory
- Fix "path is on mount 'D:', start on mount 'C:'" on Windows by explicitly changing drive
@laurence-myers
Copy link
Collaborator Author

Thank you both for the reviews. 🙂

I fixed up some issues, and added a simple regression test, mostly to make sure the wheels run properly on each build.

I'll merge the changes and publish a new version to PyPI soon(ish, when I feel up to it).

@laurence-myers laurence-myers changed the title Build and publish to PyPI via CI, use Limite API (Stable ABI) Build and publish to PyPI via CI, use Limited API (Stable ABI) Feb 14, 2024
@laurence-myers laurence-myers merged commit 06ad45e into master Feb 14, 2024
3 checks passed
@laurence-myers laurence-myers deleted the pypi-update branch March 3, 2024 02:16
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.

Python v3 support
3 participants