GrossfieldLab / loos

LOOS: a lightweight object-oriented structure analysis library
http://grossfieldlab.github.io/loos/
GNU General Public License v3.0
122 stars 26 forks source link

add `__version__` to python module #122

Open lgsmith opened 3 months ago

lgsmith commented 3 months ago

Is your feature request related to a problem? Please describe

I just like to be able to check the software version from the python import, as opposed to querying conda or rooting around in an install dir. Makes reporting other issues easier too.

Describe the solution you'd like

Add a __version__ attribute to the python module, which is customary for python modules.

Describe alternatives you've considered

You can currently solve this problem with conda list | grep loos...

Additional context

None

agrossfield commented 3 months ago

I think the right way to do this is to get the information from Cmake into the c++ library at compile time, then export that function to the python.

This website (https://community.gigperformer.com/t/getting-cmake-variables-from-c/17711) documents a way to have CMake generate a version.hpp file with the necessary information. Creating a function to return the info would be easy, as would exporting the info to python.

Not sure about how we'd get the function called to set version, though.

lgsmith commented 3 months ago

I think we just need to literally put it in the python module swig creates at the top level, and also in the pyloos. We could probably use a shell script to sed it in, or a python script that replaces it in, after those files are created during the build process. There are comments about this in PEP8.

So it could be as simple as putting:

__version__ = 'VERSION'

in the module files, then having a script that build runs replace VERSION with the correct version number.

agrossfield commented 2 months ago

@tromo committed https://github.com/GrossfieldLab/loos/commit/3a3d2f3b930aecf92d40216a306509c14ced93c0, which should fix this. Once you've confirmed it works for you, you can close the issue.