Skip to content

Commit

Permalink
Add stubs and optimize stretch compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
gregogiudici committed Feb 13, 2025
1 parent 71c7ad3 commit a73ff36
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ build
*.pyd
*.egg-info
.vscode
.vs
.vs
venv/
39 changes: 32 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,10 @@ if (NOT SKBUILD)
after editing C++ files.")
endif()

# if(NOT CMAKE_BUILD_TYPE)
# set(CMAKE_BUILD_TYPE Release)
# endif()

# set(CMAKE_CXX_FLAGS "-Wall -Wextra")
# set(CMAKE_CXX_FLAGS_DEBUG "-g")
# set(CMAKE_CXX_FLAGS_RELEASE "-O3")
# Set default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

# Try to import all Python components potentially needed by nanobind
find_package(Python 3.8
Expand Down Expand Up @@ -66,6 +63,34 @@ nanobind_add_module(
src/signalsmith-bindings.cpp
)

# Optimize Signalsmith library
if (MSVC)
target_compile_options(Signalsmith PRIVATE /O2 /fp:fast)
target_link_options(Signalsmith PRIVATE /GL /LTCG)
else()
if(NOT APPLE)
target_compile_options(Signalsmith PRIVATE -O3 -ffast-math)
else()
target_compile_options(Signalsmith PRIVATE -O3)
endif()
target_link_options(Signalsmith PRIVATE -flto)
endif()


# Create a stub file for type hints
nanobind_add_stub(
Signalsmith_stub
MODULE Signalsmith
OUTPUT Signalsmith.pyi
MARKER_FILE py.typed
PYTHON_PATH $<TARGET_FILE_DIR:Signalsmith>
DEPENDS Signalsmith
)


# Install directive for scikit-build-core
install(TARGETS Signalsmith LIBRARY DESTINATION python_stretch)

# Install stub files
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/py.typed ${CMAKE_CURRENT_BINARY_DIR}/Signalsmith.pyi DESTINATION python_stretch)

10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
[build-system]
requires = ["scikit-build-core >=0.10", "nanobind >=2.0.0"]
requires = [
"scikit-build-core >=0.10",
"nanobind >=2.0.0",
"typing_extensions; python_version < '3.11'"
]
build-backend = "scikit_build_core.build"

[project]
name = "python-stretch"
version = "0.2.0"
description = "A Python Wrapprer of the Signalsmith Stretch C++ library for pitch and time stretching"
version = "0.3.0"
description = "A Python Wrapper of the Signalsmith Stretch C++ library for pitch and time stretching"
readme = "README.md"
requires-python = ">=3.9"
authors = [
Expand Down
2 changes: 1 addition & 1 deletion src/python_stretch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is required to make Python treat the directories as containing packages
__doc__ = "A simple python library for pitch shifting and time stretching"
__version__ = "0.2.0"
__version__ = "0.3.0"

from . import Signalsmith
27 changes: 0 additions & 27 deletions tests/test_pystretch.py

This file was deleted.

0 comments on commit a73ff36

Please sign in to comment.