Skip to content

Commit

Permalink
Merge pull request #62 from ReadAlongs/py312
Browse files Browse the repository at this point in the history
Python 3.12 support
  • Loading branch information
dhdaines authored Feb 1, 2024
2 parents 35fdaf7 + 692feae commit f677539
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 102 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- master
workflow_dispatch:

jobs:
build_sdist:
name: Build source distribution
Expand All @@ -23,13 +25,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-2019, macos-11]
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- uses: actions/checkout@v3

- name: Build wheels
uses: pypa/cibuildwheel@v2.8.1
uses: pypa/cibuildwheel@v2.16.5

- uses: actions/upload-artifact@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
cmake_minimum_required(VERSION 3.14) # I like pie
cmake_minimum_required(VERSION 3.15)
include(CheckTypeSize)
include(CheckSymbolExists)
include(CheckLibraryExists)
include(TestBigEndian)

project(soundswallower VERSION 0.6.0
project(soundswallower VERSION 0.6.1
DESCRIPTION "An even smaller speech recognizer")

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
Expand Down
24 changes: 12 additions & 12 deletions js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Decoder {
if (config === undefined) config = {};
if (Module.defaultModel !== null && config.hmm === undefined)
config.hmm = Module.get_model_path(Module.defaultModel);
const cjson = allocateUTF8(JSON.stringify(config));
const cjson = stringToNewUTF8(JSON.stringify(config));
const cconfig = Module._config_parse_json(0, cjson);
Module._free(cjson);
this.cdecoder = Module._decoder_create(cconfig);
Expand Down Expand Up @@ -57,15 +57,15 @@ class Decoder {
* @throws {ReferenceError} Throws ReferenceError if key is not a known parameter.
*/
set_config(key, val) {
const ckey = allocateUTF8(key);
const ckey = stringToNewUTF8(key);
const cconfig = Module._decoder_config(this.cdecoder);
const type = Module._config_typeof(cconfig, ckey);
if (type == 0) {
Module._free(ckey);
throw new ReferenceError(`Unknown configuration parameter ${key}`);
}
if (type & ARG_STRING) {
const cval = allocateUTF8(val);
const cval = stringToNewUTF8(val);
Module._config_set_str(cconfig, ckey, cval);
Module._free(cval);
} else if (type & ARG_FLOATING) {
Expand All @@ -85,7 +85,7 @@ class Decoder {
* @throws {ReferenceError} Throws ReferenceError if key is not a known parameter.
*/
unset_config(key) {
const ckey = allocateUTF8(key);
const ckey = stringToNewUTF8(key);
const cconfig = Module._decoder_config(this.cdecoder);
const type = Module._config_typeof(cconfig, ckey);
if (type == 0) {
Expand All @@ -102,7 +102,7 @@ class Decoder {
* @throws {ReferenceError} Throws ReferenceError if key is not a known parameter.
*/
get_config(key) {
const ckey = allocateUTF8(key);
const ckey = stringToNewUTF8(key);
const cconfig = Module._decoder_config(this.cdecoder);
const type = Module._config_typeof(cconfig, ckey);
if (type == 0) {
Expand Down Expand Up @@ -131,7 +131,7 @@ class Decoder {
* @param {string} key Key whose existence to check.
*/
has_config(key) {
const ckey = allocateUTF8(key);
const ckey = stringToNewUTF8(key);
const cconfig = Module._decoder_config(this.cdecoder);
const rv = Module._config_typeof(cconfig, ckey) != 0;
Module._free(ckey);
Expand Down Expand Up @@ -415,7 +415,7 @@ class Decoder {
*/
lookup_word(word) {
this.assert_initialized();
const cword = allocateUTF8(word);
const cword = stringToNewUTF8(word);
const cpron = Module._decoder_lookup_word(this.cdecoder, cword);
Module._free(cword);
if (cpron == 0) return null;
Expand All @@ -441,8 +441,8 @@ class Decoder {
throw new Error(
`Word at position ${i} has missing text or pronunciation`
);
const ctext = allocateUTF8(text);
const cpron = allocateUTF8(pron);
const ctext = stringToNewUTF8(text);
const cpron = stringToNewUTF8(pron);
const update = i == words.length - 1;
const wid = Module._decoder_add_word(this.cdecoder, ctext, cpron, update);
Module._free(ctext);
Expand All @@ -463,13 +463,13 @@ class Decoder {
const logmath = Module._decoder_logmath(this.cdecoder);
const config = Module._decoder_config(this.cdecoder);
const lw = this.get_config("lw");
const cjsgf = allocateUTF8(jsgf_string);
const cjsgf = stringToNewUTF8(jsgf_string);
const jsgf = Module._jsgf_parse_string(cjsgf, 0);
Module._free(cjsgf);
if (jsgf == 0) throw new Error("Failed to parse JSGF");
let rule;
if (toprule !== null) {
const crule = allocateUTF8(toprule);
const crule = stringToNewUTF8(toprule);
rule = Module._jsgf_get_rule(jsgf, crule);
Module._free(crule);
if (rule == 0) throw new Error("Failed to find top rule " + toprule);
Expand All @@ -490,7 +490,7 @@ class Decoder {
*/
set_align_text(text) {
this.assert_initialized();
const ctext = allocateUTF8(text);
const ctext = stringToNewUTF8(text);
const rv = Module._decoder_set_align_text(this.cdecoder, ctext);
Module._free(ctext);
if (rv < 0) throw new Error("Failed to set alignment text");
Expand Down
2 changes: 1 addition & 1 deletion js/library_funcs.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
$allocateUTF8
$stringToNewUTF8
$ccall
23 changes: 14 additions & 9 deletions py/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
find_package(PythonExtensions REQUIRED)
find_package(Python COMPONENTS Interpreter Development)
find_package(Cython)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
find_program(CYTHON "cython")

set_property(TARGET soundswallower PROPERTY POSITION_INDEPENDENT_CODE on)

add_cython_target(_soundswallower _soundswallower.pyx)
add_library(_soundswallower MODULE ${_soundswallower})
target_link_libraries(_soundswallower soundswallower)
add_custom_command(
OUTPUT _soundswallower.c
DEPENDS _soundswallower.pyx
VERBATIM
COMMAND "${CYTHON}" "${CMAKE_CURRENT_SOURCE_DIR}/_soundswallower.pyx"
--output-file "${CMAKE_CURRENT_BINARY_DIR}/_soundswallower.c")

python_add_library(_soundswallower MODULE
"${CMAKE_CURRENT_BINARY_DIR}/_soundswallower.c" WITH_SOABI)
target_link_libraries(_soundswallower PRIVATE soundswallower)
target_include_directories(
_soundswallower PRIVATE ${PYTHON_INCLUDE_DIR}
_soundswallower PRIVATE ${PROJECT_SOURCE_DIR}/src
_soundswallower PRIVATE ${PROJECT_SOURCE_DIR}/include
_soundswallower PRIVATE ${CMAKE_BINARY_DIR} # for config.h
)
python_extension_module(_soundswallower)
install(TARGETS _soundswallower LIBRARY DESTINATION py/soundswallower)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/model DESTINATION py/soundswallower)
install(TARGETS _soundswallower LIBRARY DESTINATION soundswallower)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/model DESTINATION soundswallower)
86 changes: 66 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,72 @@
[build-system]
requires = [
"setuptools>=45,<64",
"wheel",
"scikit-build~=0.15",
"cmake",
"Cython",
"ninja"
"scikit-build-core",
"Cython"
]
build-backend = "setuptools.build_meta"
build-backend = "scikit_build_core.build"

[project]
name = "soundswallower"
version = "0.6.1"
description = "An even smaller speech recognizer"
readme = "README.md"
authors = [
{name = "David Huggins-Daines", email = "[email protected]"}
]
keywords = ["asr", "speech"]
classifiers = [
"Development Status :: 3 - Alpha",
"Programming Language :: C",
"Programming Language :: Cython",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Topic :: Multimedia :: Sound/Audio :: Speech",
]

[project.urls]
Homepage = "https://github.com/ReadAlongs/SoundSwallower"
Documentation = "https://soundswallower.readthedocs.io/"
Repository = "https://github.com/ReadAlongs/SoundSwallower.git"
Issues = "https://github.com/ReadAlongs/SoundSwallower/issues"

[project.scripts]
soundswallower = "soundswallower.cli:main"

[tool.cibuildwheel]
# Build the versions found in Ubuntu LTS, the stable PyPy, Anaconda on Windows
# ...and some other versions we want for Windows
# Build a reduced selection of binaries as there are tons of them
build = [
"pp38*",
"cp36-manylinux_*",
"cp38-manylinux_*",
"cp37-win*",
"cp38-win*",
"cp39-win*",
"cp310-*"
"pp310*",
"cp38-*",
"cp310-*",
"cp311-*",
"cp312-*",
]
# Build only universal wheels for Mac where possible, and skip 32-bit
# builds to avoid building a gigabyte of stuff all the time
skip = [
"cp*-macosx_x86_64",
"cp*-macosx_arm64",
"*_i686",
"*-win32",
]
# PyPy 3.8 will choke on CPython 3.8 build leftovers...
before-build = "rm -rf _skbuild"
# PyPy builds are broken on Windows, and skip 32-bit and musl
skip = ["*musl*", "*_i686", "*-win32", "pp*win*"]

[tool.cibuildwheel.macos]
archs = ["x86_64", "universal2", "arm64"]

[tool.isort]
profile = "black"

[tool.flake8]
extend-ignore = "E203"
max-line-length = "88"

[tool.scikit-build]
cmake.verbose = true
logging.level = "INFO"
wheel.packages = ["py/soundswallower"]
24 changes: 0 additions & 24 deletions setup.cfg

This file was deleted.

13 changes: 0 additions & 13 deletions setup.py

This file was deleted.

8 changes: 4 additions & 4 deletions tests/_hash_delete1.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Hash with chaining representation of the hash table
|key:-bla|len:4|val=8|->NULL
|key:-hmmdump|len:8|val=1|->|key:-subvq|len:6|val=7|->|key:-outlatdir|len:10|val=3|->NULL
|key:-svq4svq|len:8|val=2|->|key:-lminmemory|len:11|val=6|->NULL
|key:-beam|len:5|val=5|->NULL
|key:-bla|len:4|val=0x8|->NULL
|key:-hmmdump|len:8|val=0x1|->|key:-subvq|len:6|val=0x7|->|key:-outlatdir|len:10|val=0x3|->NULL
|key:-svq4svq|len:8|val=0x2|->|key:-lminmemory|len:11|val=0x6|->NULL
|key:-beam|len:5|val=0x5|->NULL
The total number of keys =7
10 changes: 5 additions & 5 deletions tests/_hash_delete2.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Hash with chaining representation of the hash table
|key:-bla|len:4|val=8|->NULL
|key:-hmmdump|len:8|val=1|->|key:-outlatdir|len:10|val=3|->NULL
|key:-svq4svq|len:8|val=2|->|key:-lminmemory|len:11|val=6|->NULL
|key:-lm|len:3|val=4|->NULL
|key:-beam|len:5|val=5|->NULL
|key:-bla|len:4|val=0x8|->NULL
|key:-hmmdump|len:8|val=0x1|->|key:-outlatdir|len:10|val=0x3|->NULL
|key:-svq4svq|len:8|val=0x2|->|key:-lminmemory|len:11|val=0x6|->NULL
|key:-lm|len:3|val=0x4|->NULL
|key:-beam|len:5|val=0x5|->NULL
The total number of keys =7
10 changes: 5 additions & 5 deletions tests/_hash_delete3.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Hash with chaining representation of the hash table
|key:-bla|len:4|val=8|->NULL
|key:-hmmdump|len:8|val=1|->|key:-subvq|len:6|val=7|->|key:-outlatdir|len:10|val=3|->NULL
|key:-lminmemory|len:11|val=6|->NULL
|key:-lm|len:3|val=4|->NULL
|key:-beam|len:5|val=5|->NULL
|key:-bla|len:4|val=0x8|->NULL
|key:-hmmdump|len:8|val=0x1|->|key:-subvq|len:6|val=0x7|->|key:-outlatdir|len:10|val=0x3|->NULL
|key:-lminmemory|len:11|val=0x6|->NULL
|key:-lm|len:3|val=0x4|->NULL
|key:-beam|len:5|val=0x5|->NULL
The total number of keys =7
10 changes: 5 additions & 5 deletions tests/_hash_delete4.res
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Hash with chaining representation of the hash table
|key:-bla|len:4|val=8|->NULL
|key:-subvq|len:6|val=7|->|key:-outlatdir|len:10|val=3|->NULL
|key:-svq4svq|len:8|val=2|->|key:-lminmemory|len:11|val=6|->NULL
|key:-lm|len:3|val=4|->NULL
|key:-beam|len:5|val=5|->NULL
|key:-bla|len:4|val=0x8|->NULL
|key:-subvq|len:6|val=0x7|->|key:-outlatdir|len:10|val=0x3|->NULL
|key:-svq4svq|len:8|val=0x2|->|key:-lminmemory|len:11|val=0x6|->NULL
|key:-lm|len:3|val=0x4|->NULL
|key:-beam|len:5|val=0x5|->NULL
The total number of keys =7

0 comments on commit f677539

Please sign in to comment.