cfgfile.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. The Config File
  2. ===============
  3. All paths in the config file are relative to the directory where the config
  4. file is located, unless noted otherwise.
  5. Application section
  6. -------------------
  7. .. describe:: name
  8. The user-readable name of your application. This will be used for various
  9. display purposes in the installer, and for shortcuts and the folder in
  10. 'Program Files'.
  11. .. describe:: version
  12. The version number of your application.
  13. .. describe:: publisher (optional)
  14. The publisher name that shows up in the *Add or Remove programs* control panel.
  15. .. versionadded:: 1.10
  16. .. describe:: entry_point
  17. The function to launch your application, in the format ``module:function``.
  18. Dots are allowed in the module part. pynsist will create a script like this,
  19. plus some boilerplate::
  20. from module import function
  21. function()
  22. .. describe:: script (optional)
  23. Path to the Python script which launches your application, as an alternative
  24. to ``entry_point``.
  25. Ensure that this boilerplate code is at the top of your script::
  26. #!python3.6
  27. import sys, os
  28. import site
  29. scriptdir, script = os.path.split(os.path.abspath(__file__))
  30. pkgdir = os.path.join(scriptdir, 'pkgs')
  31. # Ensure .pth files in pkgdir are handled properly
  32. site.addsitedir(pkgdir)
  33. sys.path.insert(0, pkgdir)
  34. The first line tells it which version of Python to run with. If you use
  35. binary packages, packages compiled for Python 3.3 won't work with Python 3.4.
  36. The other lines make sure it can find the packages installed along with your
  37. application.
  38. .. describe:: target (optional)
  39. parameters (optional)
  40. Lower level definition of a shortcut, to create start menu entries for help
  41. pages or other non-Python entry points. You shouldn't normally use this for
  42. Python entry points.
  43. .. note::
  44. Either ``entry_point``, ``script`` or ``target`` must be specified, but not
  45. more than one. Specifying ``entry_point`` is normally easiest and most
  46. reliable.
  47. .. describe:: icon (optional)
  48. Path to a ``.ico`` file to be used for shortcuts to your application and
  49. during the install/uninstall process. Pynsist has a default generic icon, but
  50. you probably want to replace it.
  51. .. describe:: console (optional)
  52. If ``true``, shortcuts will be created using ``python.exe``, which opens
  53. a console for the process. If ``false``, or not specified, they will use
  54. ``pythonw.exe``, which doesn't create a console. In that case, stdout and
  55. stderr from Python code will be redirected to a log file in :envvar:`APPDATA`.
  56. .. describe:: extra_preamble (optional)
  57. Path to a file containing extra Python commands to be run before your code is
  58. launched, for example to set environment variables needed by pygtk. This is
  59. only valid if you use ``entry_point`` to specify how to launch your application.
  60. If you use the Python API, this parameter can also be passed as a file-like
  61. object, such as :class:`io.StringIO`.
  62. .. describe:: license_file (optional)
  63. Path to a text file containing the license under which your software is to
  64. be distributed. If given, an extra step before installation will check the
  65. user's agreement to abide by the displayed license. If not given, the extra
  66. step is omitted.
  67. .. _shortcut_config:
  68. Shortcut sections
  69. -----------------
  70. One shortcut will always be generated for the application. You can add extra
  71. shortcuts by defining sections titled :samp:`Shortcut {Name}`. For example:
  72. .. code-block:: ini
  73. [Shortcut IPython Notebook]
  74. entry_point=IPython.html.notebookapp:launch_new_instance
  75. icon=scripts/ipython_nb.ico
  76. console=true
  77. .. describe:: entry_point
  78. script (optional)
  79. icon (optional)
  80. console (optional)
  81. target (optional)
  82. parameters (optional)
  83. extra_preamble (optional)
  84. These options all work the same way as in the Application section.
  85. Microsoft offers guidance on `what shortcuts to include in the Start screen/menu
  86. <https://msdn.microsoft.com/en-us/library/windows/desktop/jj673981(v=vs.85).aspx#decide_the_right_entry_points_to_include_in_the_start_screen>`__.
  87. Most applications should only need one shortcut, and things like help and
  88. settings should be accessed inside the app rather than as separate shortcuts.
  89. .. _command_config:
  90. Command sections
  91. ----------------
  92. .. versionadded:: 1.7
  93. Your application can install commands to be run from the Windows command prompt.
  94. This is not standard practice for desktop applications on Windows, but if your
  95. application specifically provides a command line interface, you can define
  96. one or more sections titled :samp:`Command {name}`::
  97. [Command guessnumber]
  98. entry_point=guessnumber:main
  99. If you use this, the installer will modify the system :envvar:`PATH` environment
  100. variable.
  101. .. describe:: entry_point
  102. As with shortcuts, this specifies the Python function to call, in the format
  103. ``module:function``.
  104. .. describe:: console (optional)
  105. If ``true`` (default), the ``.exe`` wrapper for the command will open a
  106. console if it's not already inside one. If ``false``, it will be a GUI
  107. application, which doesn't use a console.
  108. If the user runs the command directly, they do so in a console anyway.
  109. But commands with ``console=false`` can be useful if your GUI application
  110. needs to run a subprocess without a console window popping up.
  111. .. describe:: extra_preamble (optional)
  112. As for shortcuts, a file containing extra code to run before importing the
  113. module from ``entry_point``. This should rarely be needed.
  114. .. _cfg_python:
  115. Python section
  116. --------------
  117. .. describe:: version
  118. The Python version to download and bundle with your application, e.g. ``3.6.3``.
  119. Python 3.5 or later are supported. For older versions of Python, use Pynsist
  120. 1.x.
  121. .. describe:: bitness (optional)
  122. ``32`` or ``64``, to use 32-bit (x86) or 64-bit (x64) Python. On Windows, this
  123. defaults to the version you're using, so that compiled modules will match. On
  124. other platforms, it defaults to 32-bit.
  125. .. describe:: include_msvcrt (optional)
  126. The default is ``true``,
  127. which will include an app-local copy of the Microsoft Visual C++ Runtime,
  128. required for Python to run. The installer will only install this if it doesn't
  129. detect a system installation of the runtime.
  130. Setting this to ``false`` will not include the C++ Runtime. Your application may
  131. not run for all users until they install it manually (`download from Microsoft
  132. <https://www.microsoft.com/en-us/download/details.aspx?id=48145>`__). You may
  133. prefer to do this for security reasons: the separately installed runtime will
  134. get updates through Windows Update, but app-local copies will not.
  135. Users on Windows 10 should already have the runtime installed systemwide, so
  136. this does won't affect them. Users on Windows Vista, 7, 8 or 8.1 *may* already
  137. have it, depending on what else is installed.
  138. .. versionadded:: 1.9
  139. .. note::
  140. Pynsist 1.x also included a ``format=`` option to select between two ways to
  141. use Python: *bundled* or *installer*. Pynsist 2 only supports *bundled*
  142. Python. For the installer option, use Pynsist 1.x.
  143. .. _cfg_include:
  144. Include section
  145. ---------------
  146. To write these lists, put each value on a new line, with more indentation than
  147. the line with the key:
  148. .. code-block:: ini
  149. key=value1
  150. value2
  151. value3
  152. .. describe:: pypi_wheels (optional)
  153. A list of packages in the format ``name==version`` to download from PyPI or
  154. extract from the directories in ``extra_wheel_sources``.
  155. These must be available as wheels; Pynsist will not try to use sdists
  156. or eggs (see :ref:`faq-no-wheels`).
  157. You need to list all the packages needed to run your application, including
  158. dependencies of the packages you use directly.
  159. .. versionadded:: 1.7
  160. .. describe:: extra_wheel_sources (optional)
  161. One or more directory paths in which to find wheels, in addition to fetching
  162. from PyPI. Each package listed in ``pypi_wheels`` will be retrieved from the
  163. first source containing a
  164. compatible wheel, and all extra sources have priority over PyPI.
  165. Relative paths are from the directory containing the config file.
  166. .. versionadded:: 2.0
  167. .. describe:: local_wheels (optional)
  168. One or more paths to ``.whl`` wheel files on the local filesystem.
  169. All matching wheel files will be included in the installer.
  170. These paths can also use *glob* patterns to match multiple wheels,
  171. e.g. ``wheels/*.whl`` will include all wheels from the folder ``wheels``.
  172. Pynsist checks that each pattern matches at least one file, that only
  173. one wheel is being used for each distribution name, and that all wheels are
  174. compatible with the target Python version.
  175. Relative paths are from the directory containing the config file.
  176. .. versionadded:: 2.2
  177. .. note::
  178. The ``local_wheels`` option is useful if you're using Pynsist as a step
  179. in a larger build process: you can use another tool to prepare all your
  180. application's dependencies as wheels, and then pass them to Pynsist.
  181. For simpler build processes, ``pypi_wheels`` will search PyPI for compatible
  182. wheels, and handle downloading and caching them. Use ``extra_wheel_sources``
  183. if you need to add some wheels which aren't available on PyPI.
  184. .. describe:: packages (optional)
  185. A list of importable package and module names to include in the installer.
  186. Specify only top-level packages, i.e. without a ``.`` in the name.
  187. .. note::
  188. The ``packages`` option finds and copies installed packages from your
  189. development environment. Specifying packages in ``pypi_wheels`` instead
  190. is more reliable, and works with namespace packages.
  191. .. describe:: files (optional)
  192. Extra files or directories to be installed with your application.
  193. You can optionally add ``> destination`` after each file to install it
  194. somewhere other than the installation directory. The destination can be:
  195. * An absolute path on the target system, e.g. ``C:\\`` (but this is not
  196. usually desirable).
  197. * A path starting with ``$INSTDIR``, the specified installation directory.
  198. * A path starting with any of the `constants NSIS provides
  199. <http://nsis.sourceforge.net/Docs/Chapter4.html#4.2.3>`_, e.g. ``$SYSDIR``.
  200. The destination can also include ``${PRODUCT_NAME}``, which will be expanded
  201. to the name of your application.
  202. For instance, to put a data file in the (32 bit) common files directory:
  203. .. code-block:: ini
  204. [Include]
  205. files=mydata.dat > $COMMONFILES
  206. .. describe:: exclude (optional)
  207. Files to be excluded from your installer. This can be used to include a
  208. Python library or extra directory only partially, for example to include
  209. large monolithic python packages without their samples and test suites to
  210. achieve a smaller installer file.
  211. * The parameter is expected to contain a list of files *relative to the
  212. build directory*. Therefore, to include files from a package, you have to
  213. start your pattern with ``pkgs/<packagename>/``.
  214. * You can use `wildcard characters`_ like ``*`` or ``?``, similar to a Unix
  215. shell.
  216. * If you want to exclude whole subfolders, do *not* put a path separator
  217. (e.g. ``/``) at their end.
  218. * The exclude patterns are applied to packages, pypi wheels, and directories
  219. specified using the ``files`` option. If your ``exclude`` option directly
  220. contradicts your ``files`` or ``packages`` option, the files in question
  221. will be included (you can not exclude a full package/extra directory
  222. or a single file listed in ``files``).
  223. * Exclude patterns are applied uniformly across platforms and can use
  224. either Unix-style forward-slash (``/``), or Windows-style back-slash (``\``)
  225. path separators. Exclude patterns are normalized so that patterns
  226. written on Unix will work on Windows, and vice-versa.
  227. Example:
  228. .. code-block:: ini
  229. [Include]
  230. packages=PySide
  231. files=data_dir
  232. exclude=pkgs/PySide/examples
  233. data_dir/ignoredfile
  234. .. _build_config:
  235. Build section
  236. -------------
  237. .. describe:: directory (optional)
  238. The build directory. Defaults to ``build/nsis/``.
  239. .. describe:: installer_name (optional)
  240. The filename of the installer, relative to the build directory. The default
  241. is made from your application name and version.
  242. .. describe:: nsi_template (optional)
  243. The path of a template .nsi file to specify further details of the installer.
  244. The default template is `part of pynsist <https://github.com/takluyver/pynsist/blob/master/nsist/pyapp.nsi>`_.
  245. This is an advanced option, and if you specify a custom template, you may
  246. well have to update it to work with future releases of Pynsist.
  247. See the `NSIS Scripting Reference <http://nsis.sourceforge.net/Docs/Chapter4.html>`_
  248. for details of the NSIS language, and the Jinja2 `Template Designer Docs
  249. <http://jinja.pocoo.org/docs/dev/templates/>`_ for details of the template
  250. format. Pynsist uses templates with square brackets (``[]``) instead of
  251. Jinja's default curly braces (``{}``).
  252. .. _wildcard characters: https://docs.python.org/3/library/fnmatch.html