google / or-tools

Google's Operations Research tools:
https://developers.google.com/optimization/
Apache License 2.0
10.82k stars 2.09k forks source link

cmake: Rework python.cmake #2858

Open Mizux opened 2 years ago

Mizux commented 2 years ago

After few discussions with conda-forge maintainer few things to improve:

ps: feel free to give feedback and I will add them to this list.

DevNote

You can (re)read the thread on or-tools integration to conda forge, TLDR: it wasn't as smooth as it should have so let's fix what we can on the or-tools cmake side if possible... src: https://github.com/conda-forge/staged-recipes/pull/16147

Some preliminary PoC can be done using https://github.com/Mizux/python-native which compile in few dozen of seconds contrary to ortools...

For 0. could use:

import subprocess, sys
from email.parser import BytesHeaderParser
p = subprocess.run([sys.executable, '-m', 'pip', 'show', 'pip', '--files'], stdout=subprocess.PIPE)
h = BytesHeaderParser().parsebytes(p.stdout)
print(h['Version'])
21.3

src: https://github.com/conda-forge/staged-recipes/pull/16147#issuecomment-945934282 note: --files seems not needed.

For 1. https://github.com/google/or-tools/blob/86d4c543f717fa8716a9d66c25143660668bf825/ortools/python/setup.py.in#L49 basically replace this or adding a "is external lib" check then do nothing -> which could be done by checking property IMPORTED ? https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED.html

BastianZim commented 2 years ago

(Conda-forge maintainer here)

For 0.

Yes it's not needed. I had seen it suggested as a way to get it formatted but it seems like it's the same. Pypa is also currently working on a --json flag. ref: https://github.com/pypa/pip/issues/5261

For 1.:

I'm currently just replacing the installation part with

message(FATAL_ERROR "Can't find python module \"${MODULE_NAME}\", please install it using your system package manager.")

Installation: https://github.com/google/or-tools/blob/86d4c543f717fa8716a9d66c25143660668bf825/cmake/python.cmake#L42-L46

As a quick fix.

For 3)

I like poetry as a build backend: https://github.com/python-poetry/poetry-core