README.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. Introduction
  2. ============
  3. This package contains utilities used to package some of STScI's Python
  4. projects; specifically those projects that comprise stsci_python_ and
  5. Astrolib_.
  6. It currently consists mostly of some setup_hook scripts meant for use with
  7. `distutils2/packaging`_ and/or pbr_, and a customized easy_install command
  8. meant for use with distribute_.
  9. This package is not meant for general consumption, though it might be worth
  10. looking at for examples of how to do certain things with your own packages, but
  11. YMMV.
  12. Features
  13. ========
  14. Hook Scripts
  15. ------------
  16. Currently the main features of this package are a couple of setup_hook scripts.
  17. In distutils2, a setup_hook is a script that runs at the beginning of any
  18. pysetup command, and can modify the package configuration read from setup.cfg.
  19. There are also pre- and post-command hooks that only run before/after a
  20. specific setup command (eg. build_ext, install) is run.
  21. stsci.distutils.hooks.use_packages_root
  22. '''''''''''''''''''''''''''''''''''''''
  23. If using the ``packages_root`` option under the ``[files]`` section of
  24. setup.cfg, this hook will add that path to ``sys.path`` so that modules in your
  25. package can be imported and used in setup. This can be used even if
  26. ``packages_root`` is not specified--in this case it adds ``''`` to
  27. ``sys.path``.
  28. stsci.distutils.hooks.version_setup_hook
  29. ''''''''''''''''''''''''''''''''''''''''
  30. Creates a Python module called version.py which currently contains four
  31. variables:
  32. * ``__version__`` (the release version)
  33. * ``__svn_revision__`` (the SVN revision info as returned by the ``svnversion``
  34. command)
  35. * ``__svn_full_info__`` (as returned by the ``svn info`` command)
  36. * ``__setup_datetime__`` (the date and time that setup.py was last run).
  37. These variables can be imported in the package's `__init__.py` for degugging
  38. purposes. The version.py module will *only* be created in a package that
  39. imports from the version module in its `__init__.py`. It should be noted that
  40. this is generally preferable to writing these variables directly into
  41. `__init__.py`, since this provides more control and is less likely to
  42. unexpectedly break things in `__init__.py`.
  43. stsci.distutils.hooks.version_pre_command_hook
  44. ''''''''''''''''''''''''''''''''''''''''''''''
  45. Identical to version_setup_hook, but designed to be used as a pre-command
  46. hook.
  47. stsci.distutils.hooks.version_post_command_hook
  48. '''''''''''''''''''''''''''''''''''''''''''''''
  49. The complement to version_pre_command_hook. This will delete any version.py
  50. files created during a build in order to prevent them from cluttering an SVN
  51. working copy (note, however, that version.py is *not* deleted from the build/
  52. directory, so a copy of it is still preserved). It will also not be deleted
  53. if the current directory is not an SVN working copy. For example, if source
  54. code extracted from a source tarball it will be preserved.
  55. stsci.distutils.hooks.tag_svn_revision
  56. ''''''''''''''''''''''''''''''''''''''
  57. A setup_hook to add the SVN revision of the current working copy path to the
  58. package version string, but only if the version ends in .dev.
  59. For example, ``mypackage-1.0.dev`` becomes ``mypackage-1.0.dev1234``. This is
  60. in accordance with the version string format standardized by PEP 386.
  61. This should be used as a replacement for the ``tag_svn_revision`` option to
  62. the egg_info command. This hook is more compatible with packaging/distutils2,
  63. which does not include any VCS support. This hook is also more flexible in
  64. that it turns the revision number on/off depending on the presence of ``.dev``
  65. in the version string, so that it's not automatically added to the version in
  66. final releases.
  67. This hook does require the ``svnversion`` command to be available in order to
  68. work. It does not examine the working copy metadata directly.
  69. stsci.distutils.hooks.numpy_extension_hook
  70. ''''''''''''''''''''''''''''''''''''''''''
  71. This is a pre-command hook for the build_ext command. To use it, add a
  72. ``[build_ext]`` section to your setup.cfg, and add to it::
  73. pre-hook.numpy-extension-hook = stsci.distutils.hooks.numpy_extension_hook
  74. This hook must be used to build extension modules that use Numpy. The primary
  75. side-effect of this hook is to add the correct numpy include directories to
  76. `include_dirs`. To use it, add 'numpy' to the 'include-dirs' option of each
  77. extension module that requires numpy to build. The value 'numpy' will be
  78. replaced with the actual path to the numpy includes.
  79. stsci.distutils.hooks.is_display_option
  80. '''''''''''''''''''''''''''''''''''''''
  81. This is not actually a hook, but is a useful utility function that can be used
  82. in writing other hooks. Basically, it returns ``True`` if setup.py was run
  83. with a "display option" such as --version or --help. This can be used to
  84. prevent your hook from running in such cases.
  85. stsci.distutils.hooks.glob_data_files
  86. '''''''''''''''''''''''''''''''''''''
  87. A pre-command hook for the install_data command. Allows filename wildcards as
  88. understood by ``glob.glob()`` to be used in the data_files option. This hook
  89. must be used in order to have this functionality since it does not normally
  90. exist in distutils.
  91. This hook also ensures that data files are installed relative to the package
  92. path. data_files shouldn't normally be installed this way, but the
  93. functionality is required for a few special cases.
  94. Commands
  95. --------
  96. build_optional_ext
  97. ''''''''''''''''''
  98. This serves as an optional replacement for the default built_ext command,
  99. which compiles C extension modules. Its purpose is to allow extension modules
  100. to be *optional*, so that if their build fails the rest of the package is
  101. still allowed to be built and installed. This can be used when an extension
  102. module is not definitely required to use the package.
  103. To use this custom command, add::
  104. commands = stsci.distutils.command.build_optional_ext.build_optional_ext
  105. under the ``[global]`` section of your package's setup.cfg. Then, to mark
  106. an individual extension module as optional, under the setup.cfg section for
  107. that extension add::
  108. optional = True
  109. Optionally, you may also add a custom failure message by adding::
  110. fail_message = The foobar extension module failed to compile.
  111. This could be because you lack such and such headers.
  112. This package will still work, but such and such features
  113. will be disabled.
  114. .. _stsci_python: http://www.stsci.edu/resources/software_hardware/pyraf/stsci_python
  115. .. _Astrolib: http://www.scipy.org/AstroLib/
  116. .. _distutils2/packaging: http://distutils2.notmyidea.org/
  117. .. _d2to1: http://pypi.python.org/pypi/d2to1
  118. .. _distribute: http://pypi.python.org/pypi/distribute