Skip to content

Commit

Permalink
Read version from Python
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Nov 10, 2023
1 parent d9c2c7c commit a554b27
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 69 deletions.
1 change: 0 additions & 1 deletion libmambapy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pybind11_add_module(
src/libmambapy/core/longpath.manifest
src/libmambapy/core/core.cpp
src/libmambapy/core/main.cpp
src/libmambapy/core/version.cpp
)

target_include_directories(core PRIVATE src/libmambapy/core)
Expand Down
15 changes: 15 additions & 0 deletions libmambapy/setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
import importlib.util
import os
import pathlib

import skbuild
import skbuild.constants

__dir__ = pathlib.Path(__file__).parent.absolute()


def CMAKE_INSTALL_DIR():
"""Where scikit-build configures CMAKE_INSTALL_PREFIX."""
return os.path.abspath(skbuild.constants.CMAKE_INSTALL_DIR())


def libmambapy_version():
"""Get the version of libmambapy from its version module."""
spec = importlib.util.spec_from_file_location(
"libmambapy_version", __dir__ / "src/libmambapy/version.py"
)
ver = importlib.util.module_from_spec(spec)
spec.loader.exec_module(ver)
return ver.__version__


skbuild.setup(
version=libmambapy_version(),
packages=["libmambapy", "libmambapy.core"],
package_dir={"": "src"},
package_data={"libmambapy": ["py.typed", "__init__.pyi"]},
Expand Down
7 changes: 2 additions & 5 deletions libmambapy/src/libmambapy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import libmambapy.core.version
import libmambapy.version
from libmambapy.core.bindings import * # Legacy which used to combine everything

# Shim submodules as core submodules
version = libmambapy.core.version

# Define top-level attributes
__version__ = version.__version__
__version__ = libmambapy.version.__version__
1 change: 0 additions & 1 deletion libmambapy/src/libmambapy/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@

PYBIND11_MODULE(core, m)
{
mambapy::version::bind_submodule(m.def_submodule("version"));
mambapy::bindings::bind_submodule(m.def_submodule("bindings"));
}
5 changes: 0 additions & 5 deletions libmambapy/src/libmambapy/core/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@

namespace mambapy
{
namespace version
{
void bind_submodule(pybind11::module_ m);
}

namespace bindings
{
void bind_submodule(pybind11::module_ m);
Expand Down
28 changes: 0 additions & 28 deletions libmambapy/src/libmambapy/core/version.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions libmambapy/src/libmambapy/core/version.cpp.tmpl

This file was deleted.

2 changes: 2 additions & 0 deletions libmambapy/src/libmambapy/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version_info = (1, 5, 1)
__version__ = ".".join(map(str, version_info))
2 changes: 2 additions & 0 deletions libmambapy/src/libmambapy/version.py.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version_info = ({{ version_major }}, {{ version_minor }}, {{ version_patch }})
__version__ = ".".join(map(str, version_info))
2 changes: 1 addition & 1 deletion releaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
templates = {
"libmamba": "libmamba/include/mamba/version.hpp.tmpl",
"micromamba": "micromamba/src/version.hpp.tmpl",
"libmambapy": "libmambapy/src/libmambapy/core/version.cpp.tmpl",
"libmambapy": "libmambapy/src/libmambapy/version.py.tmpl",
}


Expand Down

0 comments on commit a554b27

Please sign in to comment.