PyD and distutils¶
PyD provides patches to distutils so it can use DMD, LDC, and GDC.
See also
Mostly, this consists of a different setup
that must be called, and a different Extension
that must be used:
from pyd.support import setup, Extension
projName = 'hello'
setup(
name=projName,
version='0.1',
ext_modules=[
Extension(projName, ['hello.d'],
extra_compile_args=['-w'],
build_deimos=True,
d_lump=True
)
],
)
Command line flags¶
compiler¶
Specify the D compiler to use. Expects one of dmd, ldc, gdc.
python setup.py install --compiler=ldc
Default: dmd
debug¶
Have the D compiler compile things with debugging information.
python setup.py install --debug
Extension arguments¶
In addition to the arguments accepted by distutils’ Extension, PyD’s Extension accepts the following arguments:
raw_only¶
When True
, suppress linkage of all of PyD except the bare C API.
Equivalent to setting with_pyd and with_main to False
.
Default: False
with_pyd¶
Setting this flag to False
suppresses compilation and linkage of PyD.
with_main effectively becomes False
as well; PydMain won’t be used
unless PyD is in use.
Default: True
with_main¶
Setting this flag to False
suppresses the use of PydMain, allowing
the user to write a C-style init function instead.
Default: True
build_deimos¶
Build object files for deimos headers. Ideally, this should not be necessary; however some compilers (*cough* ldc) try to link to PyObject typeinfo. If you get link errors like
undefined symbol: _D6deimos6python12methodobject11PyMethodDef6__initZ
try setting this flag to True
.
Default: False
d_property¶
Have D compilers enable property checks (i.e. trying to call functions without parens will result in an error)
Default: False
string_imports¶
Specify string import files to pass to D compilers. Takes a list of strings which are either paths to import files or paths to directories containing import files.
Default: []
pydexe¶
PyD also provides a custom command to compile D code that embeds python. The format of setup.py stays the same.
from pyd.support import setup, Extension, pydexe_sanity_check
pydexe_sanity_check()
projName = 'pyind'
srcs = ['pyind.d']
setup(
name=projName,
version='1.0',
ext_modules=[
Extension(projName, srcs,
build_deimos=True, d_lump=True
)
],
)
Mixing C and D extensions¶
It is totally possible. Use PyD’s setup
.
from distutils.core import Extension as cExtension
from pyd.support import setup, Extension
module1 = Extension("x", sources = ['xclass.c'])
module2 = Extension("y", sources = ['hello.d'], build_deimos=True, d_lump=True)
setup(
name = "x",
version = '1.0',
description = "eat a taco",
ext_modules = [
module1,
module2
]
);