Skip to content

Commit

Permalink
chore: migrate to pyproject.toml
Browse files Browse the repository at this point in the history
pyproject.toml is now a preferred place to implement many things that used to be in setup.py. This modernizes the setup and the dependency management, and removes the need for some of the workarounds for extensions and versioning.
  • Loading branch information
tlecomte committed May 5, 2024
1 parent ae129e7 commit 8b16f3b
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 103 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
scripts/friture text eol=lf
appimage/friture.yml text eol=lf
appimage/friture.desktop text eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -x
which python3
python3 -c 'import sys; print(sys.version)'

pip3 install -r requirements.txt
pip3 install .

# pyinstaller needs to have the extensions built explicitely
python3 setup.py build_ext --inplace
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/install-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -x
which python3
python3 -c 'import sys; print(sys.version)'

pip3 install -r requirements.txt
pip3 install .

# pyinstaller needs to have the extensions built explicitely
python3 setup.py build_ext --inplace
Expand Down
8 changes: 4 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ virtualenv -p /usr/bin/python3.11 buildenv
source ./buildenv/bin/activate
```

8. Install Friture requirements (PyQt5, etc.)
8. Install Friture dependencies (PyQt5, etc.)
```
pip3.11 install -r requirements.txt
pip3.11 install .
```

9. Build Cython extensions
Expand Down Expand Up @@ -114,7 +114,7 @@ virtualenv buildenv
8. Install dependencies

```
pip install -r requirements.txt
pip install .
```

9. Build Cython extensions
Expand All @@ -131,7 +131,7 @@ python main.py

## Dependencies

See [requirements.txt](requirements.txt)
See [pyproject.toml](pyproject.toml)

## UI and resource files

Expand Down
65 changes: 65 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[build-system]
requires = [
"setuptools",

# Cython and numpy are needed when running setup.py, to build extensions
"numpy==1.26.4",
"Cython==0.29.33",
]
build-backend = "setuptools.build_meta"

[project]
name = "friture"
description = "Real-time visualization of live audio data"
license = {file = "COPYING.txt"}
readme = "README.rst"
authors = [
{name = "Timothée Lecomte", email = "[email protected]"},
]
keywords = ["audio", "spectrum", "spectrogram"]
classifiers=[
"Programming Language :: Python",
"Programming Language :: Cython",
"Development Status :: 4 - Beta",
"Environment :: MacOS X",
"Environment :: Win32 (MS Windows)",
"Environment :: X11 Applications :: Qt",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent",
"Topic :: Multimedia :: Sound/Audio :: Analysis",
"Topic :: Multimedia :: Sound/Audio :: Speech"
]
dynamic = ["version"]
dependencies = [
"sounddevice==0.4.5",
"rtmixer==0.1.4",
"docutils==0.21.2",
"numpy==1.26.4",
"PyQt5==5.15.10",
"appdirs==1.4.4",
"pyrr==0.10.3",
]

[project.scripts]
friture = "friture.analyzer:main"

[project.urls]
Homepage = "http://www.friture.org"
Repository = "https://github.com/tlecomte/friture"
Issues = "https://github.com/tlecomte/friture/issues"

[tool.setuptools]
packages=[
"friture",
"friture.plotting",
"friture.generators",
"friture.signal",
"friture_extensions"
]

[tool.setuptools.data-files]
"share/applications" = ["appimage/friture.desktop"]

[tool.setuptools.dynamic]
version = {attr = "friture.__version__"}
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

10 changes: 0 additions & 10 deletions scripts/friture

This file was deleted.

90 changes: 9 additions & 81 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-
from setuptools import setup
from setuptools.extension import Extension
from os.path import join, dirname # for README content reading
import friture # for the version number

# see INSTALL file for details
# to create a source package
Expand All @@ -19,83 +17,13 @@
# to fix pep8 issues automatically (replace -d by -i if the changes are fine):
# autopep8 --max-line-length=170 -d -r friture

# solve chicken-and-egg problem that setup.py needs to import Numpy to build the extensions,
# but Numpy is not available until it is installed as a setup dependency
# see: https://stackoverflow.com/a/54128391
class LateIncludeExtension(Extension):
def __init__(self, *args, **kwargs):
self.__include_dirs = []
super().__init__(*args, **kwargs)
ext_modules = [Extension("friture_extensions.exp_smoothing_conv",
["friture_extensions/exp_smoothing_conv.pyx"]),
Extension("friture_extensions.linear_interp",
["friture_extensions/linear_interp.pyx"]),
Extension("friture_extensions.lookup_table",
["friture_extensions/lookup_table.pyx"]),
Extension("friture_extensions.lfilter",
["friture_extensions/lfilter.pyx"])]

@property
def include_dirs(self):
import numpy
return self.__include_dirs + [numpy.get_include()]

@include_dirs.setter
def include_dirs(self, dirs):
self.__include_dirs = dirs

# extensions
ext_modules = [LateIncludeExtension("friture_extensions.exp_smoothing_conv",
["friture_extensions/exp_smoothing_conv.pyx"]),
LateIncludeExtension("friture_extensions.linear_interp",
["friture_extensions/linear_interp.pyx"]),
LateIncludeExtension("friture_extensions.lookup_table",
["friture_extensions/lookup_table.pyx"]),
LateIncludeExtension("friture_extensions.lfilter",
["friture_extensions/lfilter.pyx"])]

# Friture runtime dependencies
# these will be installed when calling 'pip install friture'
# they are also retrieved by 'requirements.txt'
install_requires = [
"sounddevice==0.4.5",
"rtmixer==0.1.4",
"docutils==0.21.2",
"numpy==1.26.4",
"PyQt5==5.15.10",
"appdirs==1.4.4",
"pyrr==0.10.3",
]

# Cython and numpy are needed when running setup.py, to build extensions
setup_requires=["numpy==1.26.4", "Cython==0.29.33"]

with open(join(dirname(__file__), 'README.rst')) as f:
long_description = f.read()

setup(name="friture",
version=friture.__version__,
description='Real-time visualization of live audio data',
long_description=long_description,
license="GNU GENERAL PUBLIC LICENSE",
author='Timothée Lecomte',
author_email='[email protected]',
url='http://www.friture.org',
keywords=["audio", "spectrum", "spectrogram"],
classifiers=[
"Programming Language :: Python",
"Programming Language :: Cython",
"Development Status :: 4 - Beta",
"Environment :: MacOS X",
"Environment :: Win32 (MS Windows)",
"Environment :: X11 Applications :: Qt",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent",
"Topic :: Multimedia :: Sound/Audio :: Analysis",
"Topic :: Multimedia :: Sound/Audio :: Speech"
],
packages=['friture',
'friture.plotting',
'friture.generators',
'friture.signal',
'friture_extensions'],
scripts=['scripts/friture'],
ext_modules=ext_modules,
install_requires=install_requires,
setup_requires=setup_requires,
include_package_data=True,
data_files = [('share/applications', ['appimage/friture.desktop'])],
)
setup(ext_modules=ext_modules)
4 changes: 2 additions & 2 deletions winbuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ Write-Host "==========================================="

Write-Host ""
Write-Host "==========================================="
Write-Host "Installing requirements"
Write-Host "Installing dependencies"
Write-Host "==========================================="

& pip install -r requirements.txt
& pip install .

Write-Host ""
Write-Host "==========================================="
Expand Down

0 comments on commit 8b16f3b

Please sign in to comment.