Skip to content

Commit ad2d4ab

Browse files
committed
pyproject: Use pyproject.toml for building wheels
1 parent 2748f70 commit ad2d4ab

File tree

9 files changed

+109
-102
lines changed

9 files changed

+109
-102
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ build/
55
dist/
66
.eggs/
77
sounddevice.egg-info/
8+
.venv*/

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
include LICENSE
22
include *.rst
33
include doc/requirements.txt
4-
include sounddevice_build.py
4+
recursive-include _custom_build *.py
5+
include sounddevice.py
56
recursive-include doc *.rst *.py
67
recursive-include examples *.py

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.5.0

_custom_build/__init__.py

Whitespace-only changes.

_custom_build/backend.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""A Thin backend wrapper for setuptools.build_meta
2+
3+
See https://setuptools.pypa.io/en/latest/build_meta.html
4+
"""
5+
6+
from setuptools import build_meta as _orig
7+
from setuptools.build_meta import *
8+
import sounddevice_build
9+
import os
10+
import platform
11+
import shutil
12+
13+
sounddevice_build.main()
14+
15+
DARWIN = "Darwin"
16+
WINDOWS = "Windows"
17+
MACOSX_VERSIONS = ["maccosx_10_6_x86_64", "macosx_10_6_universal2"]
18+
19+
20+
def get_platform_specific_wheel_name() -> str:
21+
"""Return the platform specific wheel name."""
22+
current_platform = os.environ.get("PYTHON_SOUNDDEVICE_PLATFORM", platform.system())
23+
architecture = os.environ.get("PYTHON_SOUNDDEVICE_ARCHITECTURE", platform.architecture()[0])
24+
oses = "any"
25+
26+
if current_platform == DARWIN:
27+
oses = ".".join(MACOSX_VERSIONS)
28+
elif current_platform == WINDOWS:
29+
oses = "win32" if architecture == "32bit" else "win_amd64"
30+
31+
with open("VERSION", "r") as f:
32+
version = f.read().strip()
33+
34+
return f"sounddevice-{version}-py3-none-{oses}.whl"
35+
36+
37+
def prepare_meta_for_build_wheel(config_settings=None):
38+
"""This function may be used in the future to customize platform specific portaudio libraries."""
39+
return _orig.prepare_metadata_for_build_wheel(config_settings=config_settings)
40+
41+
42+
def get_requires_for_build_wheel(config_settings=None):
43+
return _orig.get_requires_for_build_wheel(config_settings=config_settings)
44+
45+
46+
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
47+
"""Intercept the build wheel function and copy the wheel to a platform specific name.
48+
49+
We build the wheel as ususal for the package but intercept the output so that we can rename it.
50+
"""
51+
52+
wheel_file = _orig.build_wheel(wheel_directory, config_settings=config_settings, metadata_directory=metadata_directory)
53+
old_wheel_path = os.path.join(wheel_directory, wheel_file)
54+
new_wheel_path = os.path.join(wheel_directory, get_platform_specific_wheel_name())
55+
56+
shutil.move(old_wheel_path, new_wheel_path)
57+
58+
return new_wheel_path

sounddevice_build.py renamed to _custom_build/sounddevice_build.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from cffi import FFI
22

33
ffibuilder = FFI()
4-
ffibuilder.set_source('_sounddevice', None)
4+
ffibuilder.set_source("_sounddevice", None)
55
ffibuilder.cdef("""
66
int Pa_GetVersion( void );
77
const char* Pa_GetVersionText( void );
@@ -314,5 +314,10 @@
314314
int PaWasapi_IsLoopback( PaDeviceIndex device );
315315
""")
316316

317-
if __name__ == '__main__':
317+
318+
def main():
318319
ffibuilder.compile(verbose=True)
320+
321+
322+
if __name__ == "__main__":
323+
main()

pyproject.toml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
11
[build-system]
2-
requires = ["setuptools >= 61.0"]
3-
build-backend = "setuptools.build_meta"
2+
requires = ["setuptools", "wheel", "CFFI>=1.0.0"]
3+
build-backend = "backend"
4+
backend-path = ["_custom_build"]
5+
6+
[project]
7+
name = "sounddevice"
8+
description = "Play and Record Sound with Python"
9+
requires-python = ">=3.7"
10+
readme = "README.rst"
11+
license = { file = "LICENSE" }
12+
keywords = ["sound", "audio", "play", "record", "playrec", "PortAudio"]
13+
authors = [{ name = "Matthias Geier", email = "[email protected]" }]
14+
classifiers = [
15+
"License :: OSI Approved :: MIT License",
16+
"Operating System :: OS Independent",
17+
"Programming Language :: Python",
18+
"Programming Language :: Python :: 3",
19+
"Topic :: Multimedia :: Sound/Audio"
20+
]
21+
urls = { "Source" = "https://github.com/spatialaudio/python-sounddevice" }
22+
dependencies = ["CFFI>=1.0.0"]
23+
dynamic = ["version"]
24+
25+
[project.optional-dependencies]
26+
NumPy = ["NumPy"]
27+
28+
[tool.setuptools]
29+
zip-safe = false
30+
py-modules = ["sounddevice", "_sounddevice"]
31+
packages = ["_sounddevice_data"]
32+
33+
[tool.setuptools.package-data]
34+
"_sounddevice_data"= [
35+
"portaudio-binaries/*.dll",
36+
"portaudio-binaries/*.dylib",
37+
"portaudio-binaries/*.md"
38+
]
39+
40+
[tool.setuptools.dynamic]
41+
version = { "file" = "VERSION" }

setup.py

Lines changed: 0 additions & 96 deletions
This file was deleted.

sounddevice.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
https://python-sounddevice.readthedocs.io/
4949
5050
"""
51-
__version__ = '0.5.0'
5251

5352
import atexit as _atexit
5453
import os as _os

0 commit comments

Comments
 (0)