-
Notifications
You must be signed in to change notification settings - Fork 729
Build a proper Python package #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
742069f
refactor: merge everything into one SWIG module
dhdaines e2fa80f
build: make a real python module using cmake_build_extension
dhdaines fa596a5
fix: make README more sensible
dhdaines 7518726
fix: bring back the all-in-one directory, seems to work
dhdaines 79ba0f8
fix: update tests for new model name
dhdaines 1bcd988
build: install __init__.py instead of creating one
dhdaines 6ed57f5
build: test (sort of) python module
dhdaines d5d8a8c
fix: make tests be tests
dhdaines File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [build-system] | ||
| requires = [ | ||
| "wheel", | ||
| "setuptools>=45", | ||
| "setuptools_scm[toml]>=6.0", | ||
| "cmake_build_extension", | ||
| ] | ||
| build-backend = "setuptools.build_meta" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| cmake-build-extension~=0.5.1 | ||
| pytest~=7.1.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| [metadata] | ||
| name = pocketsphinx5 | ||
| version = 5.0.0rc0 | ||
| description = Official Python bindings for PocketSphinx5 | ||
| long_description = file: README.md | ||
| long_description_content_type = text/markdown | ||
| author = David Huggins-Daines | ||
| author_email = [email protected] | ||
| license = MIT | ||
| platforms = any | ||
| url = https://github.com/cmusphinx/pocketsphinx | ||
| project_urls = | ||
| Source = https://github.com/cmusphinx/pocketsphinx | ||
| Tracker = https://github.com/cmusphinx/pocketsphinx/issues | ||
| keywords = | ||
| classifiers = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import inspect | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import cmake_build_extension | ||
| import setuptools | ||
|
|
||
| # This example is compliant with PEP517 and PEP518. It uses the setup.cfg file to store | ||
| # most of the package metadata. However, build extensions are not supported and must be | ||
| # configured in the setup.py. | ||
| setuptools.setup( | ||
| ext_modules=[ | ||
| cmake_build_extension.CMakeExtension( | ||
| # This could be anything you like, it is used to create build folders | ||
| name="PocketSphinx5", | ||
| # Name of the resulting package name (import mymath_swig) | ||
| install_prefix="pocketsphinx5", | ||
| # Selects the folder where the main CMakeLists.txt is stored | ||
| # (it could be a subfolder) | ||
| source_dir=str(Path(__file__).parent.absolute()), | ||
| cmake_configure_options=[ | ||
| # This option points CMake to the right Python interpreter, and helps | ||
| # the logic of FindPython3.cmake to find the active version | ||
| f"-DPython3_ROOT_DIR={Path(sys.prefix)}", | ||
| "-DCALL_FROM_SETUP_PY:BOOL=ON", | ||
| "-DBUILD_SHARED_LIBS:BOOL=OFF", | ||
| ] | ||
| ), | ||
| ], | ||
| cmdclass=dict( | ||
| # Enable the CMakeExtension entries defined above | ||
| build_ext=cmake_build_extension.BuildExtension, | ||
| # If the setup.py or setup.cfg are in a subfolder wrt the main CMakeLists.txt, | ||
| # you can use the following custom command to create the source distribution. | ||
| # sdist=cmake_build_extension.GitSdistFolder | ||
| ), | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,16 @@ | ||
| find_package(SWIG) | ||
|
|
||
| # Set SWIG policies | ||
| cmake_policy(SET CMP0078 NEW) | ||
| cmake_policy(SET CMP0086 NEW) | ||
| find_package(SWIG 4.0) | ||
| if(SWIG_FOUND) | ||
| set(UseSWIG_MODULE_VERSION 2) | ||
| # mysteriously necessary | ||
| include(${SWIG_USE_FILE}) | ||
| add_subdirectory(python) | ||
| endif() | ||
|
|
||
| set_property( | ||
| SOURCE pocketsphinx.i | ||
| PROPERTY SWIG_DEPENDS | ||
| ps_decoder.i ps_lattice.i typemaps.i iterators.i | ||
| cmd_ln.i fe.i feat.i fsg_model.i jsgf.i ngram_model.i logmath.i) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,54 @@ | ||
| find_package(Python3 COMPONENTS Interpreter Development) | ||
| set_property(SOURCE ../pocketsphinx.i PROPERTY SWIG_MODULE_NAME pocketsphinx) | ||
| swig_add_library(pocketsphinx_python | ||
|
|
||
| # Handle where to install the resulting Python package | ||
| if(CALL_FROM_SETUP_PY) | ||
| # The CMakeExtension will set CMAKE_INSTALL_PREFIX to the root | ||
| # of the resulting wheel archive | ||
| set(POCKETSPHINX_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) | ||
| else() | ||
| message(FATAL_ERROR | ||
| "Please do not try to build the Python module outside of setup.py") | ||
| endif() | ||
|
|
||
| # Set the Python module name (.py file) properly | ||
| set_property(SOURCE ../pocketsphinx.i PROPERTY SWIG_MODULE_NAME bindings) | ||
| # SWIG-ify and compile the bindings | ||
| swig_add_library(bindings | ||
| TYPE MODULE | ||
| LANGUAGE python | ||
| OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/pocketsphinx5 | ||
| OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR} | ||
| SOURCES | ||
| ../pocketsphinx.i | ||
| ) | ||
| swig_link_libraries(pocketsphinx_python pocketsphinx Python3::Python) | ||
| set_property(SOURCE ../sphinxbase.i PROPERTY SWIG_MODULE_NAME sphinxbase) | ||
| swig_add_library(sphinxbase_python | ||
| LANGUAGE python | ||
| SOURCES | ||
| ../sphinxbase.i | ||
| ) | ||
| swig_link_libraries(sphinxbase_python pocketsphinx Python3::Python) | ||
| # Link the bindings with pocketsphinx and Python | ||
| target_link_libraries(bindings PRIVATE pocketsphinx Python3::Python) | ||
| # Build the library in the proper place and not the weird random CMake place | ||
| set_target_properties(bindings PROPERTIES | ||
| LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pocketsphinx5) | ||
| # This does something, not sure what | ||
| set_property(TARGET bindings PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE) | ||
| # Enable parsing the doxygen comments (FIXME: does this work?) | ||
| set_property(TARGET bindings PROPERTY SWIG_COMPILE_OPTIONS -doxygen) | ||
|
|
||
| # Installation stuff | ||
| # Get the autogenerated Python file | ||
| get_property(WRAPPER_PY_FILE | ||
| TARGET bindings | ||
| PROPERTY SWIG_SUPPORT_FILES) | ||
| # Install the autogenerated Python file | ||
| install( | ||
| FILES ${WRAPPER_PY_FILE} | ||
| DESTINATION ${POCKETSPHINX_INSTALL_PREFIX} | ||
| COMPONENT bindings) | ||
| # Install the __init__ply file | ||
| install( | ||
| FILES __init__.py | ||
| DESTINATION ${POCKETSPHINX_INSTALL_PREFIX}) | ||
| # Install the SWIG library | ||
| install( | ||
| TARGETS bindings | ||
| COMPONENT bindings | ||
| LIBRARY DESTINATION ${POCKETSPHINX_INSTALL_PREFIX} | ||
| ARCHIVE DESTINATION ${POCKETSPHINX_INSTALL_PREFIX} | ||
| RUNTIME DESTINATION ${POCKETSPHINX_INSTALL_PREFIX}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The answer is "no", for macos anyway.