-
Notifications
You must be signed in to change notification settings - Fork 150
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
pyproject: Use pyproject.toml for building wheels #560
Open
abelgladstone
wants to merge
1
commit into
spatialaudio:master
Choose a base branch
from
abelgladstone:feature-pyproject
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
include LICENSE | ||
include *.rst | ||
include doc/requirements.txt | ||
include sounddevice_build.py | ||
recursive-include _custom_build *.py | ||
include sounddevice.py | ||
recursive-include doc *.rst *.py | ||
recursive-include examples *.py |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.5.0 |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""A Thin backend wrapper for setuptools.build_meta | ||
|
||
See https://setuptools.pypa.io/en/latest/build_meta.html | ||
""" | ||
|
||
from setuptools import build_meta as _orig | ||
from setuptools.build_meta import * | ||
import sounddevice_build | ||
import os | ||
import platform | ||
import shutil | ||
|
||
sounddevice_build.main() | ||
|
||
DARWIN = "Darwin" | ||
WINDOWS = "Windows" | ||
MACOSX_VERSIONS = ["maccosx_10_6_x86_64", "macosx_10_6_universal2"] | ||
|
||
|
||
def get_platform_specific_wheel_name() -> str: | ||
"""Return the platform specific wheel name.""" | ||
current_platform = os.environ.get("PYTHON_SOUNDDEVICE_PLATFORM", platform.system()) | ||
architecture = os.environ.get("PYTHON_SOUNDDEVICE_ARCHITECTURE", platform.architecture()[0]) | ||
oses = "any" | ||
|
||
if current_platform == DARWIN: | ||
oses = ".".join(MACOSX_VERSIONS) | ||
elif current_platform == WINDOWS: | ||
oses = "win32" if architecture == "32bit" else "win_amd64" | ||
|
||
with open("VERSION", "r") as f: | ||
version = f.read().strip() | ||
|
||
return f"sounddevice-{version}-py3-none-{oses}.whl" | ||
|
||
|
||
def prepare_meta_for_build_wheel(config_settings=None): | ||
"""This function may be used in the future to customize platform specific portaudio libraries.""" | ||
return _orig.prepare_metadata_for_build_wheel(config_settings=config_settings) | ||
|
||
|
||
def get_requires_for_build_wheel(config_settings=None): | ||
return _orig.get_requires_for_build_wheel(config_settings=config_settings) | ||
|
||
|
||
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None): | ||
"""Intercept the build wheel function and copy the wheel to a platform specific name. | ||
|
||
We build the wheel as ususal for the package but intercept the output so that we can rename it. | ||
""" | ||
|
||
wheel_file = _orig.build_wheel(wheel_directory, config_settings=config_settings, metadata_directory=metadata_directory) | ||
old_wheel_path = os.path.join(wheel_directory, wheel_file) | ||
new_wheel_path = os.path.join(wheel_directory, get_platform_specific_wheel_name()) | ||
|
||
shutil.move(old_wheel_path, new_wheel_path) | ||
|
||
return new_wheel_path |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,41 @@ | ||
[build-system] | ||
requires = ["setuptools >= 61.0"] | ||
build-backend = "setuptools.build_meta" | ||
requires = ["setuptools", "wheel", "CFFI>=1.0.0"] | ||
build-backend = "backend" | ||
backend-path = ["_custom_build"] | ||
|
||
[project] | ||
name = "sounddevice" | ||
description = "Play and Record Sound with Python" | ||
requires-python = ">=3.7" | ||
readme = "README.rst" | ||
license = { file = "LICENSE" } | ||
keywords = ["sound", "audio", "play", "record", "playrec", "PortAudio"] | ||
authors = [{ name = "Matthias Geier", email = "[email protected]" }] | ||
classifiers = [ | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Topic :: Multimedia :: Sound/Audio" | ||
] | ||
urls = { "Source" = "https://github.com/spatialaudio/python-sounddevice" } | ||
dependencies = ["CFFI>=1.0.0"] | ||
dynamic = ["version"] | ||
|
||
[project.optional-dependencies] | ||
NumPy = ["NumPy"] | ||
|
||
[tool.setuptools] | ||
zip-safe = false | ||
py-modules = ["sounddevice", "_sounddevice"] | ||
packages = ["_sounddevice_data"] | ||
|
||
[tool.setuptools.package-data] | ||
"_sounddevice_data"= [ | ||
"portaudio-binaries/*.dll", | ||
"portaudio-binaries/*.dylib", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this causes all wheels to contain all binaries. This should be limited. Also, the |
||
"portaudio-binaries/*.md" | ||
] | ||
|
||
[tool.setuptools.dynamic] | ||
version = { "file" = "VERSION" } |
This file was deleted.
Oops, something went wrong.
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this should be ...
... but the whole function seems unnecessary, since it is imported already?