[arch-general] python-cmake?

Eli Schwartz eschwartz at archlinux.org
Thu Nov 28 17:39:01 UTC 2019


On November 28, 2019 9:31:19 AM EST, "Iyán Méndez Veiga" <me at iyanmv.com> wrote:
> Hi,
> 
> First of all, sorry if this is a really stupid question, but I've been
> trying 
> to search for a while and I couldn't find an answer.

It's a confusing question, because it is a confusing module. :) I'll try to clarify your confusion below.


> Is the python module 'cmake' provided in some package in Arch? I mean,
> I know 
> that there is the cmake package in [extra] but there is no
> python-cmake, and 
> when I try 'import cmake' of course the module is not found.
> 
> This works if I install cmake with pip:
> 
> $ python -m env test
> $ source test/bin/activate
> $ (test) pip install cmake
> $ (test) python
> $>>> import cmake
> 
> Thanks,
> Iyán


What you installed is a bundled, prebuilt copy of cmake stuffed into $venv/lib/python3.8/site-packages/cmake/data/

This data directory contains the same hierarchy of bin/ lib/ and share/ that pacman -S cmake would install to /usr instead.

There is also a $venv/lib/python3.8/site-packages/cmake/__init__.py which contains a single set of functions, cmake() cpack() and ctest(), which search for the hidden binaries in $venv/lib/python3.8/site-packages/cmake/data/bin/ and execute them using subprocess.call()

You're not supposed to use these functions at all. They only exist so that pip can install a setuptools entry point, which allows you to source $venv/bin/activate and then be able to run `cmake` in a command prompt, which will run $venv/bin/cmake, which imports python, uses it to find the hidden data directory, and finally executes the cmake binary.

You cannot even additionally use the module as a shortcut to subprocess.call within your own python-based project, since it hardcodes sys.argv[1:] as the arguments to pass to cmake.

The PyPI package "cmake" is *not* meant to be used in python scripts, and its only purpose is to very inefficiently abuse PyPI as a distribution mechanism that is easier to use than flatpak or snapd, because people are more likely to have pip installed than either of those, and because their Linux distro is probably named "Ubuntu" so they cannot otherwise easily get a modern version of cmake.

Similar modules exist in the NodeJS ecosystem that abuse npmjs.org to install nom modules that contain no JavaScript, but do contain a bash script. Because downloading bash scripts into $HOME/bin/ is hard, but npm install mycoolscript is "easy".

tl;dr
Wherever you saw the advice to pip install cmake was probably misinformed. This does not provide python bindings to cmake.

-- 
Eli Schwartz
Bug Wrangler and Trusted User


More information about the arch-general mailing list