Skip to content

Commit 486ff1d

Browse files
committed
feat: support CPython 3.14
1 parent 9a05180 commit 486ff1d

9 files changed

Lines changed: 240 additions & 34 deletions

File tree

‎.github/workflows/code-quality.yaml‎

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,54 @@ on:
88
- synchronize
99

1010
jobs:
11+
legacy-python-3-6:
12+
runs-on: ubuntu-24.04
13+
container: ubuntu:20.04
14+
steps:
15+
- uses: actions/checkout@v7
16+
- name: Set up Python 3.6
17+
uses: actions/setup-python@v7
18+
with:
19+
python-version: "3.6"
20+
- name: Display Python version
21+
run: python -c "import sys; print(sys.version)"
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
python -m pip install flake8 pytest pytest-mock
26+
python -m pip install -r requirements.txt
27+
python -m pip install --no-deps .
28+
- name: Lint with flake8
29+
run: python -m flake8 .
30+
- name: Test with pytest
31+
run: python -m pytest
32+
1133
build:
12-
# compatible for py 3.6
13-
runs-on: ubuntu-20.04
34+
runs-on: ${{ matrix.runner }}
1435
strategy:
15-
# You can use PyPy versions in python-version.
1636
matrix:
17-
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
37+
include:
38+
- python-version: "3.7"
39+
runner: ubuntu-22.04
40+
- python-version: "3.8"
41+
runner: ubuntu-24.04
42+
- python-version: "3.9"
43+
runner: ubuntu-24.04
44+
- python-version: "3.10"
45+
runner: ubuntu-24.04
46+
- python-version: "3.11"
47+
runner: ubuntu-24.04
48+
- python-version: "3.12"
49+
runner: ubuntu-24.04
50+
- python-version: "3.13"
51+
runner: ubuntu-24.04
52+
- python-version: "3.14"
53+
runner: ubuntu-24.04
1854

1955
steps:
20-
- uses: actions/checkout@v3
56+
- uses: actions/checkout@v7
2157
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v4
58+
uses: actions/setup-python@v7
2359
with:
2460
python-version: ${{ matrix.python-version }}
2561
# You can test your matrix by printing the current Python version
@@ -28,21 +64,56 @@ jobs:
2864
- name: Install dependencies
2965
run: |
3066
python -m pip install --upgrade pip
31-
pip install flake8 pytest pytest-mock build
32-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
67+
python -m pip install flake8 pytest pytest-mock build
68+
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
69+
python -m pip install --no-deps .
3370
- name: Lint with flake8
3471
run: |
3572
# stop the build if there are Python syntax errors
36-
flake8 .
73+
python -m flake8 .
3774
- name: Test with pytest
3875
run: |
39-
pytest
76+
python -m pytest
4077
- name: Audit concurrency, memory, and thread cleanup
41-
if: matrix.python-version == '3.12'
78+
if: matrix.python-version == '3.12' || matrix.python-version == '3.14'
4279
run: python scripts/resource_audit.py --evaluations 20000 --workers 8
4380
- name: Build production distributions
44-
if: matrix.python-version == '3.12'
81+
if: matrix.python-version == '3.12' || matrix.python-version == '3.14'
4582
run: python -m build
4683
- name: Verify wheel contains production packages only
47-
if: matrix.python-version == '3.12'
84+
if: matrix.python-version == '3.12' || matrix.python-version == '3.14'
4885
run: python -c "import glob, zipfile; names = zipfile.ZipFile(glob.glob('dist/*.whl')[0]).namelist(); assert not any(name.startswith(('tests/', 'featbit_openfeature/')) for name in names)"
86+
- name: Install and smoke-test the built wheel
87+
if: matrix.python-version == '3.14'
88+
run: |
89+
python -m venv "$RUNNER_TEMP/featbit-wheel-test"
90+
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip install --upgrade pip
91+
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip install dist/*.whl
92+
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip check
93+
"$RUNNER_TEMP/featbit-wheel-test/bin/python" scripts/wheel_smoke.py \
94+
--bootstrap tests/fbclient_test_data.json \
95+
--expected-version-file release/package.json
96+
97+
minimum-dependencies:
98+
runs-on: ubuntu-24.04
99+
steps:
100+
- uses: actions/checkout@v7
101+
- name: Set up Python 3.14
102+
uses: actions/setup-python@v7
103+
with:
104+
python-version: "3.14"
105+
- name: Install exact minimum dependencies
106+
run: |
107+
python -m pip install --upgrade pip
108+
python -m pip install pytest pytest-mock
109+
python -m pip install \
110+
certifi==2018.4.16 \
111+
urllib3==1.26.5 \
112+
python-dateutil==2.8.2 \
113+
websocket-client==1.0.0
114+
python -m pip install --no-deps .
115+
python -m pip check
116+
- name: Test with pytest
117+
run: python -m pytest
118+
- name: Audit concurrency, memory, and thread cleanup
119+
run: python scripts/resource_audit.py --evaluations 20000 --workers 8

‎.github/workflows/release.yaml‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ jobs:
1919
deploy:
2020
permissions:
2121
contents: write
22-
runs-on: ubuntu-latest
22+
runs-on: ubuntu-24.04
2323
environment: py-production
2424
steps:
25-
- uses: actions/checkout@v4
25+
- uses: actions/checkout@v7
2626
- name: Read current version
2727
id: version
2828
run: |
@@ -31,26 +31,39 @@ jobs:
3131
with open("release/package.json") as file:
3232
print("value=%s" % json.load(file)["version"])
3333
PY
34-
- name: Create GitHub Release
35-
env:
36-
GH_TOKEN: ${{ github.token }}
37-
run: |
38-
gh release create "v${{ steps.version.outputs.value }}" \
39-
--title "v${{ steps.version.outputs.value }}" \
40-
--notes-file release/description.md
4134
- name: Set up Python
42-
uses: actions/setup-python@v4
35+
uses: actions/setup-python@v7
4336
with:
44-
python-version: '3.x'
37+
python-version: '3.14'
4538
- name: Install dependencies
4639
run: |
4740
python -m pip install --upgrade pip
48-
pip install build
41+
python -m pip install build twine
4942
- name: Build package
5043
run: python -m build
44+
- name: Check package metadata
45+
run: python -m twine check dist/*
46+
- name: Install and smoke-test the built wheel
47+
env:
48+
VERSION: ${{ steps.version.outputs.value }}
49+
run: |
50+
python -m venv "$RUNNER_TEMP/featbit-wheel-test"
51+
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip install --upgrade pip
52+
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip install dist/*.whl
53+
"$RUNNER_TEMP/featbit-wheel-test/bin/python" -m pip check
54+
"$RUNNER_TEMP/featbit-wheel-test/bin/python" scripts/wheel_smoke.py \
55+
--bootstrap tests/fbclient_test_data.json \
56+
--expected-version "$VERSION"
57+
- name: Create GitHub Release
58+
env:
59+
GH_TOKEN: ${{ github.token }}
60+
VERSION: ${{ steps.version.outputs.value }}
61+
run: |
62+
gh release create "v$VERSION" \
63+
--title "v$VERSION" \
64+
--notes-file release/description.md
5165
- name: Publish package distributions to PyPI
5266
uses: pypa/gh-action-pypi-publish@v1.12.4
5367
with:
5468
user: __token__
5569
password: ${{ secrets.PYPI_PASSWORD }}
56-
verify-metadata: false

‎README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ If you want to use your own data source, see [Offline Mode](#offline-mode).
1818
## Get Started
1919

2020
### Installation
21-
Install the SDK using pip. This version is compatible with Python 3.6 through 3.12.
21+
Install the SDK using pip. This version is compatible with Python 3.6 through 3.14.
22+
CI is configured to test compatibility through Python 3.14, including the
23+
full unit suite and SDK resource-lifecycle audit.
24+
Free-threaded CPython 3.14 builds are not currently tested or supported.
2225

2326
```shell
2427
pip install fb-python-sdk

‎dev-requirements.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
certifi>=2018.4.16
2-
urllib3>=1.22.0
2+
urllib3>=1.26.5
33
websocket-client>=1.0.0
44
python-dateutil>=2.8.2
55
flake8
66
pytest
77
pytest-mock
88
autopep8
99
build
10-
twine
10+
twine

‎release/description.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version: 1.1.8
2+
version: 1.1.9
33

44
## Break changes
55

@@ -16,6 +16,8 @@ version: 1.1.8
1616

1717
## Updates
1818

19+
- support and test CPython versions 3.13 and 3.14
20+
- require urllib3 1.26.5 or newer for CPython 3.14 compatibility
1921
- handle Python versions 3.12.x
2022
- make client, WebSocket, event, and notice shutdown deterministic and idempotent
2123
- isolate runtime event and shutdown failures from application code

‎release/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version":"1.1.8"
2+
"version":"1.1.9"
33
}

‎requirements.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
certifi>=2018.4.16
2-
urllib3>=1.22.0
2+
urllib3>=1.26.5
33
python-dateutil>=2.8.2
4-
websocket-client>=1.0.0
4+
websocket-client>=1.0.0

‎scripts/wheel_smoke.py‎

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#!/usr/bin/env python3
2+
"""Exercise the installed wheel through the public offline client API."""
3+
4+
import argparse
5+
import base64
6+
import json
7+
import site
8+
import threading
9+
from importlib import metadata
10+
from pathlib import Path
11+
12+
import fbclient
13+
from fbclient.client import FBClient
14+
from fbclient.config import Config
15+
16+
17+
PACKAGE_NAME = "fb-python-sdk"
18+
FAKE_ENV_SECRET = base64.b64encode(b"fake_env_secret").decode()
19+
FAKE_URL = "http://fake"
20+
USER_ENABLED = {"key": "test-user-1", "name": "test-user-1", "country": "us"}
21+
USER_DISABLED = {
22+
"key": "test-user-3",
23+
"name": "test-user-3",
24+
"country": "cn",
25+
"major": "cs",
26+
}
27+
28+
29+
def parse_args():
30+
parser = argparse.ArgumentParser()
31+
parser.add_argument("--bootstrap", type=Path, required=True)
32+
parser.add_argument("--expected-version")
33+
parser.add_argument("--expected-version-file", type=Path)
34+
return parser.parse_args()
35+
36+
37+
def assert_installed_package():
38+
package_path = Path(fbclient.__file__).resolve()
39+
site_paths = [Path(path).resolve() for path in site.getsitepackages()]
40+
assert any(package_path.is_relative_to(path) for path in site_paths), (
41+
"fbclient was not imported from the wheel environment: %s" % package_path
42+
)
43+
44+
45+
def assert_metadata(expected_version):
46+
distribution = metadata.distribution(PACKAGE_NAME)
47+
if expected_version:
48+
assert distribution.version == expected_version
49+
50+
package_metadata = distribution.metadata
51+
assert package_metadata["Requires-Python"] == ">=3.6, <3.15"
52+
classifiers = package_metadata.get_all("Classifier") or []
53+
assert "Programming Language :: Python :: 3.14" in classifiers
54+
requirements = distribution.requires or []
55+
assert any(requirement.startswith("urllib3>=1.26.5") for requirement in requirements)
56+
return distribution.version
57+
58+
59+
def featbit_thread_ids():
60+
return {
61+
thread.ident
62+
for thread in threading.enumerate()
63+
if thread.ident is not None and thread.name.startswith("featbit-")
64+
}
65+
66+
67+
def exercise_client(bootstrap_path):
68+
baseline_threads = featbit_thread_ids()
69+
states = []
70+
config = Config(
71+
FAKE_ENV_SECRET,
72+
event_url=FAKE_URL,
73+
streaming_url=FAKE_URL,
74+
offline=True,
75+
)
76+
client = FBClient(config)
77+
78+
def on_status_change(state):
79+
states.append(state.state_type.name)
80+
81+
client.update_status_provider.add_listener(on_status_change)
82+
try:
83+
assert client.initialize_from_external_json(bootstrap_path.read_text())
84+
assert client.initialize
85+
assert states == ["OK"]
86+
assert client.variation("ff-test-bool", USER_ENABLED, False) is True
87+
assert client.variation("ff-test-bool", USER_DISABLED, True) is False
88+
assert client.variation("missing-flag", USER_ENABLED, False) is False
89+
for _ in range(100):
90+
assert client.variation("ff-test-bool", USER_ENABLED, False) is True
91+
finally:
92+
client.update_status_provider.remove_listener(on_status_change)
93+
client.stop()
94+
client.stop()
95+
96+
leaked_threads = featbit_thread_ids() - baseline_threads
97+
assert not leaked_threads, "FeatBit worker threads leaked: %s" % leaked_threads
98+
return states
99+
100+
101+
def main():
102+
args = parse_args()
103+
expected_version = args.expected_version
104+
if args.expected_version_file:
105+
expected_version = json.loads(
106+
args.expected_version_file.read_text()
107+
)["version"]
108+
assert_installed_package()
109+
version = assert_metadata(expected_version)
110+
states = exercise_client(args.bootstrap)
111+
print(json.dumps({"package": PACKAGE_NAME, "states": states, "version": version}))
112+
113+
114+
if __name__ == "__main__":
115+
main()

‎setup.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ def parse_requirements(filename):
5151
'Programming Language :: Python :: 3.10',
5252
'Programming Language :: Python :: 3.11',
5353
'Programming Language :: Python :: 3.12',
54+
'Programming Language :: Python :: 3.13',
55+
'Programming Language :: Python :: 3.14',
5456
],
5557
extras_require={
5658
"dev": dev_reqs
5759
},
58-
python_requires='>=3.6, <3.13'
60+
python_requires='>=3.6, <3.15'
5961
)

0 commit comments

Comments
 (0)