Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit cf41f35

Browse files
authored
Refactor setup.py and publish workflow (#59)
This change includes building PortAudio for the specific platform on install. Prior to this, the user had to install PortAudio from the system package manager before installing PyAudio. Now, we can ship with Pyaudio included and give users microphone support just from the pip install. Another part of this refactor, introduced the ability to build multi-platform wheels through ciwheelbuilder. This should make installing spokestack faster/easier for all platforms.
1 parent 43f24b8 commit cf41f35

File tree

8 files changed

+141
-50
lines changed

8 files changed

+141
-50
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build and upload to PyPI
2+
3+
on:
4+
push:
5+
pull_request:
6+
release:
7+
types:
8+
- published
9+
10+
jobs:
11+
build_wheels:
12+
name: Build wheels on ${{ matrix.os }}
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
os: [ubuntu-20.04, windows-2019, macos-10.15]
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
with:
21+
submodules: recursive
22+
23+
- uses: actions/setup-python@v2
24+
name: Install Python
25+
with:
26+
python-version: "3.8"
27+
28+
- name: Install Visual C++ for Python 2.7
29+
if: runner.os == 'Windows'
30+
run: choco install vcpython27 -f -y
31+
32+
- name: Build wheels
33+
uses: joerick/cibuildwheel@v1.10.0
34+
35+
- uses: actions/upload-artifact@v2
36+
with:
37+
path: ./wheelhouse/*.whl
38+
39+
build_sdist:
40+
name: Build source distribution
41+
runs-on: ubuntu-latest
42+
steps:
43+
- uses: actions/checkout@v2
44+
with:
45+
submodules: recursive
46+
47+
- uses: actions/setup-python@v2
48+
name: Install Python
49+
with:
50+
python-version: "3.8"
51+
52+
- name: Build sdist
53+
run: python setup.py sdist
54+
55+
- uses: actions/upload-artifact@v2
56+
with:
57+
path: dist/*.tar.gz
58+
59+
upload_pypi:
60+
needs: [build_wheels, build_sdist]
61+
runs-on: ubuntu-latest
62+
# publish when a GitHub Release is created
63+
if: github.event_name == 'release' && github.event.action == 'published'
64+
steps:
65+
- uses: actions/download-artifact@v2
66+
with:
67+
name: artifact
68+
path: dist
69+
70+
- uses: pypa/gh-action-pypi-publish@master
71+
with:
72+
user: ${{ secrets.PYPI_USERNAME }}
73+
password: ${{ secrets.PYPI_PASSWORD }}

.github/workflows/python-publish.yml

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

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "spokestack/extensions/webrtc/filter_audio"]
22
path = spokestack/extensions/webrtc/filter_audio
33
url = https://github.com/irungentoo/filter_audio.git
4+
[submodule "spokestack/extensions/portaudio"]
5+
path = spokestack/extensions/portaudio
6+
url = https://github.com/PortAudio/portaudio

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
recursive-include spokestack/extensions/portaudio

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "Cython"]
2+
requires = ["setuptools", "wheel", "numpy", "Cython"]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license_files = LICENSE.txt
77
# black compatible flake8 config
88
max-line-length = 88
99
extend-ignore = E203, W503
10+
exclude = spokestack/extensions
1011

1112
[tool.isort]
1213
# black compatible isort config

setup.py

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,57 @@
11
import os
2+
import subprocess
3+
import sys
4+
5+
from setuptools import Extension, find_packages, setup
6+
from setuptools.command.build_py import build_py
7+
8+
9+
try:
10+
from numpy import get_include
11+
except ImportError:
12+
subprocess.check_call([sys.executable, "-m", "pip", "install", "numpy"])
13+
from numpy import get_include
14+
15+
try:
16+
from Cython.Build import cythonize
17+
except ImportError:
18+
subprocess.check_call([sys.executable, "-m", "pip", "install", "Cython"])
19+
from Cython.Build import cythonize
20+
21+
22+
class CustomBuild(build_py): # type: ignore
23+
"""Custom build command to build PortAudio."""
24+
25+
def run(self) -> None:
26+
"""Custom run function that builds and installs PortAudio/PyAudio."""
27+
28+
if sys.platform == "mingw":
29+
# build with MinGW for windows
30+
command = ["./configure && make && make install"]
31+
elif sys.platform in ["win32", "win64"]:
32+
# win32/64 users should install the PyAudio wheel or Conda package
33+
command = None
34+
else:
35+
# macos or linux
36+
command = ["./configure && make"]
37+
38+
if command:
39+
# build PortAudio with system specific command
40+
subprocess.run(
41+
command,
42+
shell=True,
43+
check=True,
44+
cwd="spokestack/extensions/portaudio",
45+
)
46+
# install PyAudio after PortAudio has been built
47+
subprocess.run(
48+
[sys.executable, "-m", "pip", "install", "pyaudio"],
49+
shell=True,
50+
check=True,
51+
)
52+
# run the normal build process
53+
build_py.run(self)
254

3-
import numpy as np
4-
import setuptools
5-
from Cython.Build import cythonize
655

756
SOURCES = [
857
os.path.join("spokestack/extensions/webrtc", source)
@@ -40,17 +89,17 @@
4089
]
4190

4291
EXTENSIONS = [
43-
setuptools.Extension(
92+
Extension(
4493
"spokestack.extensions.webrtc.agc",
4594
["spokestack/extensions/webrtc/agc.pyx"] + SOURCES,
4695
include_dirs=["filter_audio/agc/include/"],
4796
),
48-
setuptools.Extension(
97+
Extension(
4998
"spokestack.extensions.webrtc.nsx",
5099
["spokestack/extensions/webrtc/nsx.pyx"] + SOURCES,
51100
include_dirs=["filter_audio/ns/include/"],
52101
),
53-
setuptools.Extension(
102+
Extension(
54103
"spokestack.extensions.webrtc.vad",
55104
["spokestack/extensions/webrtc/vad.pyx"] + SOURCES,
56105
include_dirs=["filter_audio/agc/include/"],
@@ -59,23 +108,23 @@
59108
with open("README.md", "r") as fh:
60109
long_description = fh.read()
61110

62-
setuptools.setup(
111+
setup(
63112
name="spokestack",
64-
version="0.0.17",
113+
version="0.0.18",
65114
author="Spokestack",
66115
author_email="support@spokestack.io",
67116
description="Spokestack Library for Python",
68117
long_description=long_description,
69118
long_description_content_type="text/markdown",
70119
url="https://github.com/spokestack/spokestack-python",
71-
packages=setuptools.find_packages(),
120+
packages=find_packages(),
72121
classifiers=[
73122
"Programming Language :: Python :: 3",
74123
"License :: OSI Approved :: Apache Software License",
75124
"Operating System :: OS Independent",
76125
],
77126
python_requires=">=3.8",
78-
setup_requires=["setuptools", "numpy", "Cython"],
127+
setup_requires=["setuptools", "wheel", "numpy", "Cython"],
79128
install_requires=[
80129
"numpy",
81130
"Cython",
@@ -84,6 +133,7 @@
84133
"requests",
85134
],
86135
ext_modules=cythonize(EXTENSIONS),
87-
include_dirs=[np.get_include()],
136+
include_dirs=[get_include()],
137+
cmdclass={"build_py": CustomBuild},
88138
zip_safe=False,
89139
)

spokestack/extensions/portaudio

Submodule portaudio added at 3f7bee7

0 commit comments

Comments
 (0)