1

As distutils is being removed from Python in the > 3.10 versions, and setuptools will not be added to the stdlib, I want to replace an existing setup.py recipe for building/installing a C++ library Cython extension (i.e. not primarily a Python package, not run in a venv, etc.) with some custom code.

The Cython part is working fine, and I just about managed to construct an equivalent call to the C++ compiler from that previously executed by distutils, by using config-var info from sysconfig... though the latter was very trial and error, with no documentation or particular consistency to the config-var collection as far as I could tell.

But I am now stuck on identifying what directory to install my build extension .so into, within the target prefix of my build. Depending on the platform and path scheme in use, and the prefix itself, the subdirs could be in lib or lib64, a pythonX.Y subdir of some sort, and a final site-packages, dist-packages or other directory. This decision was previously made by distutils but I can't find any equivalent code to return such path decisions in other stdlib packages.

Any suggestions of answers or best-practice approaches? (Other than "use setuptools", please!)

andybuckley
  • 1,114
  • 2
  • 11
  • 24
  • It's all in `sysconfig` as far as I know. – sinoroc May 10 '22 at 17:34
  • Does this answer your question? [Programmatically determine pip 'user install' location Scripts directory](https://stackoverflow.com/questions/62162970/programmatically-determine-pip-user-install-location-scripts-directory) – sinoroc May 10 '22 at 17:36
  • But in general, you should let _pip_ install things in the right places. Can you build wheels of your library? – sinoroc May 10 '22 at 17:39
  • Unfortunately `sysconfig` doesn't replicate all the features of `distutils.sysconfig`: in particular the `get_python_lib()` function, which accepted a `prefix` kwarg, is not replicated by the `sysconfig.get_path("platlib")` call (as suggested in msg393018 of the issue used to manage the `distutils` removal: https://bugs.python.org/issue41282 ) Prefix-specific path calculations seem to have been left out. – andybuckley May 12 '22 at 06:39
  • As mentioned, this is an "added extra" Python interface to a library that is not primarily Pythonic. We don't want to distribute via PyPI and pip or similar, we just want to compile an extension lib and copy it into the position appropriate for the active Python version, within our library's custom install prefix. And without adding non-stdlib dependencies: because it's not primarily a Python pkg, users won't be using venvs, etc. I don't think wheels can be built without installing `setuptools` and `wheel`? – andybuckley May 12 '22 at 06:44
  • 1
    `distutils` is not removed yet. It is scheduled to be removed in Python 3.12. -- Is there anything in [PEP 632](https://peps.python.org/pep-0632/) that can help you find alternatives for the distutils functions you need? -- You can always copy-paste the distutils code you need into your own `setup.py`. -- Somehow I had in mind that distutils had been extracted to a package on PyPI, but maybe you do not want that anymore than installing setuptools. -- Otherwise I would suggest asking the question on the [_packaging_ category of Python Discuss form](https://discuss.python.org/c/packaging/14). – sinoroc May 12 '22 at 10:27
  • No, unfortunately PEP 632 just directs to use `sysconfig` but doesn't mention that some `distutils.sysconfig` functionality has not been replicated there. And indeed, we want to avoid Python non-stdlib dependencies completely. Thanks for the suggestions! – andybuckley May 12 '22 at 10:57

0 Answers0