How to create both a c extension and a pure python package
Thomas Jollans
tjol at tjol.eu
Wed Mar 10 10:41:36 EST 2021
On 09/03/2021 23:42, Marco Sulla wrote:
> As title. Currently I ended up using this trick in my setup.py:
>
>
> if len(argv) > 1 and argv[1] == "c":
> sys.argv = [sys.argv[0]] + sys.argv[2:]
> setuptools.setup(ext_modules = ext_modules, **common_setup_args)
> else:
> setuptools.setup(**common_setup_args)
>
>
> So if I pass "c" as the first argument of ./setup.py , the c extension
> is builded, otherwise the py version is packaged.
>
> Is there not a better way to do this?
Why are you doing this?
If all you want is for it to be possible to install the package from
source on a system that can't use the C part, you could just declare
your extension modules optional, with the "optional" argument to
setuptools.Extension. see
(https://docs.python.org/3/distutils/apiref.html#distutils.core.Extension)
- Thomas
More information about the Python-list
mailing list