Repository navigation
packaging: Add Python 3.12 support - #209
Draft
caravanuden wants to merge 1 commit into
Draft
caravanuden wants to merge 1 commit into
caravanuden wants to merge 1 commit into
Conversation
TensorFlow first ships Python 3.12 wheels in 2.16, but basic-pitch pinned tensorflow<2.15.1 (and tensorflow-macos on macOS, which has no 3.12 wheels), so installs failed on 3.12 (spotify#159, spotify#188). - On Python >= 3.12, depend on tensorflow>=2.16.1 (all platforms), plus tf-keras and tensorboard. Markers for Python <= 3.11 are unchanged. - Add basic_pitch/_keras.py, which imports tf_keras when available and falls back to tensorflow.keras. TF >= 2.16 ships Keras 3 as tf.keras, while the model/layer code is written against Keras 2. Using a module import rather than TF_USE_LEGACY_KERAS works regardless of import order. - Pin setuptools<81 on 3.12: resampy<0.4.3 imports pkg_resources. - tests: librosa.get_duration(filename=) -> path= (filename removed in librosa 1.0). - Add 3.12 to classifiers, tox envlist, CI matrix and README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
pip install basic-pitchfails on Python 3.12 (fixes #159, fixes #188).TensorFlow is pinned
<2.15.1, but TensorFlow first ships Python 3.12 wheelsin 2.16. On macOS the core dependencies pull
tensorflow-macos<2.15.1, whichalso has no 3.12 wheels.
Solution
tensorflow>=2.16.1on all platforms(plain
tensorflowhas native macOS arm64 wheels;tensorflow-macosisdiscontinued), plus
tf-kerasandtensorboard(TensorFlow >= 2.20 nolonger bundles TensorBoard, which
visualize.pyneeds fortf.summary.audio). This applies to the core dependencies and the[tf]extra; markers for Python <= 3.11 are unchanged.
basic_pitch/_keras.py, which importstf_keraswhen installed andotherwise falls back to
tensorflow.keras, and route alltf.kerasusagesthrough it. TensorFlow >= 2.16 exposes Keras 3 as
tf.keras, but the modeland layer code targets Keras 2. I chose this over
TF_USE_LEGACY_KERAS,which stops working whenever
tensorflowis imported beforebasic_pitchand changes Keras for users' own code.
setuptools<81on Python >= 3.12:resampy<0.4.3importspkg_resources, which 3.12 venvs don't ship and setuptools 81 removed. Theresampy pin itself is kept, since the test fixtures were regenerated when it
was added (ef94d1a).
librosa.get_duration(filename=)withpath=(
filenamewas removed in librosa 1.0).(ubuntu/windows/macos) and README.
Result
basic-pitch installs and runs on Python 3.12; behavior on Python <= 3.11 is
unchanged.
Tested locally on macOS arm64 with Python 3.12, TensorFlow 2.21 and tf-keras
2.21:
pytest tests --ignore tests/data: 13 passed.tests/data: local failures trace tosox/ffmpegbinaries missing on mymachine (CI installs them), so I'm relying on CI for these and for
Linux/Windows.
mainalready fail withcurrent black (
__init__.py,constants.py,predict.py,tests/data/test_medleydb_pitch.py); this PR leaves them alone.Possible follow-ups, not in this PR: Python 3.13 support; dropping EOL Python
3.8/3.9 (and the stale 3.7 README mention); bumping
actions/setup-pythonandactions/checkout; relaxing theresampy<0.4.3pin (and dropping thesetuptools pin) after regenerating fixtures.
🤖 Generated with Claude Code