diff --git a/CHANGELOG.md b/CHANGELOG.md index b448dfb..fdb5dda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/). +## Unreleased + +### :bug: Fixes + +- Raise an exception at both build and runtime when using an unsupported Python version, + instead of crashing with a segmentation fault at runtime (in the rare cases where + `backports.zstd` was installed despite the `requires-python` marker) + ## [1.2.0] - 2025-12-06 [1.2.0]: https://github.com/rogdham/backports.zstd/releases/tag/v1.2.0 diff --git a/setup.py b/setup.py index e6c6034..3f45818 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,10 @@ from setuptools import Extension, setup +if not ((3, 9) <= sys.version_info < (3, 14)): + raise RuntimeError(f"Unsupported Python version: {sys.version}") + + # create a LICENSE_zstd.txt file # wheels distributions needs to ship the license of the zstd library ROOT_PATH = Path(__file__).parent.absolute() diff --git a/src/python/backports/zstd/__init__.py b/src/python/backports/zstd/__init__.py index 58b68b1..741e0fe 100644 --- a/src/python/backports/zstd/__init__.py +++ b/src/python/backports/zstd/__init__.py @@ -1,5 +1,9 @@ """Python bindings to the Zstandard (zstd) compression library (RFC-8878).""" +import sys +if not ((3, 9) <= sys.version_info < (3, 14)): + raise RuntimeError(f"Unsupported Python version: {sys.version}") + __all__ = ( # backports.zstd 'COMPRESSION_LEVEL_DEFAULT',