Distutils RST
Distutils RST
.. contents::
SciPy structure
'''''''''''''''
The aim of this document is to describe how to add new tools to SciPy.
#!/usr/bin/env python3
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration('mypackage',parent_package,top_path)
return config
if __name__ == "__main__":
from numpy.distutils.core import setup
#setup(**configuration(top_path='').todict())
setup(configuration=configuration)
+ ``config.get_subpackage(subpackage_name,subpackage_path=None)`` ---
returns a list of subpackage configurations. Subpackage is looked in the
current directory under the name ``subpackage_name`` but the path
can be specified also via optional ``subpackage_path`` argument.
If ``subpackage_name`` is specified as ``None`` then the subpackage
name will be taken the basename of ``subpackage_path``.
Any ``*`` used for subpackage names are expanded as wildcards.
+ ``config.add_subpackage(subpackage_name,subpackage_path=None)`` ---
add SciPy subpackage configuration to the current one. The meaning
and usage of arguments is explained above, see
``config.get_subpackage()`` method.
::
config.add_data_files('foo.dat',
('fun',['gun.dat','nun/pun.dat','/tmp/sun.dat']),
'bar/car.dat'.
'/full/path/to/can.dat',
)
::
::
def generate_source(ext,build_dir):
import os
from distutils.dep_util import newer
target = os.path.join(build_dir,'somesource.c')
if newer(target,__file__):
# create target file
return target
+ ``config.get_info(*names)`` ---
.. _templating:
.. index::
single: code generation
Fortran files
-------------
A named repeat rule is useful when the same set of repeats must be
used several times in a block. It is specified using <rule1=item1,
item2, item3,..., itemN>, where N is the number of times the block
should be repeated. On each repeat of the block, the entire
expression, '<...>' will be replaced first with item1, and then with
item2, and so forth until N repeats are accomplished. Once a named
repeat specification has been introduced, the same repeat rule may be
used **in the current block** by referring only to the name
(i.e. <rule1>).
A short repeat rule looks like <item1, item2, item3, ..., itemN>. The
rule specifies that the entire expression, '<...>' should be replaced
first with item1, and then with item2, and so forth until N repeats
are accomplished.
Pre-defined names
^^^^^^^^^^^^^^^^^
- <prefix=s,d,c,z>
- <_c=s,d,c,z>
Other files
------------
7. A loop in the NumPy C source code may have a ``@TYPE@`` variable, targeted
for string substitution, which is preprocessed to a number of otherwise
identical loops with several strings such as ``INT``, ``LONG``, ``UINT``,
``ULONG``. The ``@TYPE@`` style syntax thus reduces code duplication and
maintenance burden by mimicking languages that have generic type support.
The above rules may be clearer in the following template source example:
.. code-block:: NumPyC
:linenos:
:emphasize-lines: 3, 13, 29, 31
/**begin repeat
*
* #TOTYPE = BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG,
* LONGLONG, ULONGLONG, DATETIME,
* TIMEDELTA#
* #totype = npy_byte, npy_ubyte, npy_short, npy_ushort, npy_int, npy_uint,
* npy_long, npy_ulong, npy_longlong, npy_ulonglong,
* npy_datetime, npy_timedelta#
*/
/**begin repeat1
*
* #FROMTYPE = TIMEDELTA#
* #fromtype = npy_timedelta#
*/
static void
@FROMTYPE@_to_@TOTYPE@(void *input, void *output, npy_intp n,
void *NPY_UNUSED(aip), void *NPY_UNUSED(aop))
{
const @fromtype@ *ip = input;
@totype@ *op = output;
while (n--) {
*op++ = (@totype@)*ip++;
}
}
/**end repeat1**/
/**end repeat**/
.. _conv_template.py:
https://github.com/numpy/numpy/blob/main/numpy/distutils/conv_template.py
+ ``all_strings(lst)``
+ ``has_f_sources(sources)``
+ ``has_cxx_sources(sources)``
+ ``get_dependencies(sources)``
+ ``is_local_src_dir(directory)``
+ ``get_ext_source_files(ext)``
+ ``get_script_files(scripts)``
+ ``get_lib_source_files(lib)``
+ ``get_data_files(data)``
+ ``get_frame(level=0)`` --- return frame object from call stack with given level.
+ ``cyg2win32(path)``
+ ``mingw32()`` --- return ``True`` when using mingw32 environment.
``numpy.distutils.system_info`` module
--------------------------------------
+ ``get_info(name,notfound_action=0)``
+ ``combine_paths(*args,**kws)``
+ ``show_all()``
``numpy.distutils.cpuinfo`` module
----------------------------------
+ ``cpuinfo``
``numpy.distutils.log`` module
------------------------------
+ ``set_verbosity(v)``
``numpy.distutils.exec_command`` module
---------------------------------------
+ ``get_pythonexe()``
+ ``find_executable(exe, path=None)``
+ ``exec_command( command, execute_in='', use_shell=None, use_tee=None, **env )``
"""
Package docstring, typically with a brief description and function listing.
"""
config.add_library('library',
sources=[...],
config_fc={'noopt':(__file__,1)})
in the first 20 lines of the source and use the ``f77flags`` for
specified type of the fcompiler (the first character ``C`` is optional).