PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/docs/development/building.rst

https://gitlab.com/Rockyspade/astropy
ReStructuredText | 120 lines | 97 code | 23 blank | 0 comment | 0 complexity | 90acbb220a202f2eccc98fd31e084d3f MD5 | raw file
  1. ====================================
  2. Building Astropy and its Subpackages
  3. ====================================
  4. The build process currently uses the `setuptools
  5. <https://bitbucket.org/pypa/setuptools>`_ package to build and install the
  6. astropy core (and any affiliated packages that use the template). The user
  7. doesn't necessarily need to have `setuptools`_ installed, as it will
  8. automatically bootstrap itself using the ``ez_setup.py`` file in the source
  9. distribution if it isn't installed for the user.
  10. Astropy-helpers
  11. ---------------
  12. As of Astropy v0.4, Astropy also uses an external package called
  13. `astropy-helpers <https://github.com/astropy/astropy-helpers>`_ to provide some
  14. of its build and installation functionality. A copy of astropy-helpers is
  15. included with the Astropy source distribution, but also includes a mechanism to
  16. automatically download bug fixes from PyPI. The reason for providing these
  17. helpers as a separate package is that it makes it easier for affiliated
  18. packages to take advantage of these same utilities without requiring Astropy to
  19. be installed *first*. See `APE4
  20. <https://github.com/astropy/astropy-APEs/blob/master/APE4.rst>`_ for the full
  21. background on this.
  22. Astropy-helpers is automatically bootstrapped to the Astropy build/installation
  23. script (``setup.py``) via a script called ``ah_bootstrap.py`` that is imported
  24. by ``setup.py``. This script will do its best to ensure that the user has an
  25. up-to-date copy of astropy-helpers before building the package. The
  26. auto-upgrade mechanism in particular allows pushing platform-specific fixes for
  27. the build process without releasing a new version of Astropy (or any affiliated
  28. package that uses astropy-helpers).
  29. The behavior of the ``ah_bootstrap.py`` script can also be modified by options
  30. in the project's ``setup.cfg`` file under a section called ``[ah_boostrap]``.
  31. APE4 provides `more details
  32. <https://github.com/astropy/astropy-APEs/blob/master/APE4.rst#astropy_helpers-bootstrap-script>`_.
  33. The astropy-helpers distribution provides a Python package called
  34. ``astropy_helpers``. Code that previously referenced the modules
  35. ``astropy.setup_helpers`` and ``astropy.version_helpers`` should now depend on
  36. astropy-helpers and use ``astrop_helpers.setup_helpers`` and
  37. ``astropy_helpers.version_helpers`` respectively. Likewise, astropy-helpers
  38. includes tools for building Astropy's documentation. The ``astropy.sphinx``
  39. package is deprecated in favor of ``astropy_helpers.sphinx``. As such,
  40. astropy-helpers is a dependency of building Astropy's documentation.
  41. Customizing setup/build for subpackages
  42. ---------------------------------------
  43. As is typical, there is a single ``setup.py`` file that is used for the whole
  44. ``astropy`` package. To customize setup parameters for a given sub-package, a
  45. ``setup_package.py`` file can be defined inside a package, and if it is present,
  46. the setup process will look for the following functions to customize the build
  47. process:
  48. * ``get_package_data``
  49. This function, if defined, should return a dictionary mapping the name of
  50. the subpackage(s) that need package data to a list of data file paths
  51. (possibly including wildcards) relative to the path of the package's source
  52. code. e.g. if the source distribution has a needed data file
  53. ``astropy/wcs/tests/data/3d_cd.hdr``, this function should return
  54. ``{'astropy.wcs.tests':['data/3d_cd.hdr']}``. See the ``package_data``
  55. option of the :func:`distutils.core.setup` function.
  56. It is recommended that all such data be in a directory named ``data`` inside
  57. the package within which it is supposed to be used. This package data should
  58. be accessed via the `astropy.utils.data.get_pkg_data_filename` and
  59. `astropy.utils.data.get_pkg_data_fileobj` functions.
  60. * ``get_extensions``
  61. This provides information for building C or Cython extensions. If defined,
  62. it should return a list of `distutils.core.Extension` objects controlling
  63. the Cython/C build process (see below for more detail).
  64. * ``get_build_options``
  65. This function allows a package to add extra build options. It
  66. should return a list of tuples, where each element has:
  67. - *name*: The name of the option as it would appear on the
  68. commandline or in the ``setup.cfg`` file.
  69. - *doc*: A short doc string for the option, displayed by
  70. ``setup.py build --help``.
  71. - *is_bool* (optional): When `True`, the option is a boolean
  72. option and doesn't have an associated value.
  73. Once an option has been added, its value can be looked up using
  74. ``astropy_helpers.setup_helpers.get_distutils_build_option``.
  75. * ``get_external_libraries``
  76. This function declares that the package uses libraries that are
  77. included in the astropy distribution that may also be distributed
  78. elsewhere on the users system. It should return a list of library
  79. names. For each library, a new build option is created,
  80. ``'--use-system-X'`` which allows the user to request to use the
  81. system's copy of the library. The package would typically call
  82. ``astropy_helpers.setup_helpers.use_system_library`` from its
  83. ``get_extensions`` function to determine if the package should use
  84. the system library or the included one.
  85. * ``requires_2to3``
  86. This function declares whether the package requires processing
  87. through the `2to3`_ tool to run on Python 3. If not included, it
  88. defaults to `True`. The use of `2to3`_ is phased out in astropy
  89. and is retained for use in affiliate packages which have not switched
  90. to using `six`_ instead. See :ref:`dev-portable` for more information.
  91. The ``astropy_helpers.setup_helpers`` modules includes an
  92. ``update_package_files`` function which automatically searches the given source
  93. path for ``setup_package.py`` modules and calls each of the above functions, if
  94. they exist. This makes it easy for affiliated packages to use this machinery
  95. in their own ``setup.py``.
  96. .. _six: http://pythonhosted.org/six/
  97. .. _2to3: https://docs.python.org/2/library/2to3.html