diff --git a/HISTORY.md b/HISTORY.md index ab872ff4e3..0d4b2b6780 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -18,6 +18,8 @@ * Validate md5 of STB library after download (#2087). + * Add `__version__` to `__init__.py` (#2092). + ### mlpack 3.2.1 ###### 2019-10-01 * Enforce CMake version check for ensmallen (#2032). diff --git a/src/mlpack/CMakeLists.txt b/src/mlpack/CMakeLists.txt index fce358817f..e9c2c89c37 100644 --- a/src/mlpack/CMakeLists.txt +++ b/src/mlpack/CMakeLists.txt @@ -140,6 +140,10 @@ if (BUILDING_PYTHON_BINDINGS) COMMENT "Configuring setup.py...") add_dependencies(python_configure python_copy) add_dependencies(python_configured python_configure) + + # Append the package version to __init__.py after all the imports are loaded. + file(APPEND ${CMAKE_BINARY_DIR}/src/mlpack/bindings/python/mlpack/__init__.py + "__version__='${PACKAGE_VERSION}'\n") endif () # If we are building Markdown documentation, we have to run some setup after we