design.rst 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Design principles
  2. =================
  3. or *Why I'm Refusing to Add a Feature*
  4. There are some principles in the design of Pynsist which have led me to turn
  5. down potentially useful options. I've tried to explain them here so that I can
  6. link to this rather than summarising them each time.
  7. 1. Pynsist is largely a **simplifying wrapper** around `NSIS
  8. <http://nsis.sourceforge.net/>`__: it provides an easy way to do a subset of
  9. the things NSIS can do. All simplifying wrappers come under pressure from
  10. people who want to do something just outside what the wrapper currently
  11. covers: they'd love to use the wrapper, if it just had one more option. But
  12. if we keep adding options, eventually the simplifying wrapper becomes a
  13. convoluted layer of extra complexity over the original system.
  14. 2. I'm very keen to **keep installers as simple as possible**. There are all
  15. sorts of clever things we could do at install time. But it's much harder to
  16. write and test the NSIS install code than the Python build code, and errors
  17. when the end user installs your software are a bigger problem than errors
  18. when you build it, because you're better able to understand and fix them.
  19. So Pynsist does as much as possible at build time so that the installer can
  20. be simple.
  21. 3. Pynsist has a **limited scope**: it builds Windows installers for Python
  22. applications. Mostly GUI applications, but it does also have support for
  23. adding command-line tools. I don't plan to add support for other target
  24. platforms or languages.
  25. If you need more flexibility
  26. ----------------------------
  27. If you want to do something which Pynsist doesn't support, there are several
  28. ways it can still help you:
  29. - **Generate an nsi script**: You can run Pynsist once with the
  30. ``--no-makensis`` option. In the build directory, you'll find a file
  31. ``installer.nsi``, which is the script for your installer. You can modify
  32. this and run ``makensis installer.nsi`` yourself to build the installer.
  33. - **Write a custom template**: Pynsist uses *Jinja* templates to create the
  34. nsi script. You can write a custom template and specify it in the
  35. :ref:`build_config` in your config file. Custom templates can inherit from
  36. the templates in Pynsist and override blocks, so you have a lot of control
  37. over the installer this way.
  38. - **Cannibalise the code**: Pull out whatever pieces are useful to you from
  39. Pynsist and use them in your build scripts. There are the installer templates,
  40. code to find and download wheels from PyPI, to download Python itself, to
  41. create command-line entry points, to find ``makensis.exe`` on Windows, and so
  42. on. You can take specific bits to reuse, or copy the whole thing and apply
  43. some changes.
  44. Specific non-goals
  45. ------------------
  46. These are ideas that I've considered and decided not to do:
  47. - Concealing source code: I'm writing Free and Open Source Software (FOSS) and
  48. I want to help other people do the same. A core FOSS principle is that the
  49. user can inspect and understand the code they are running. I'm not interested
  50. in anything that makes that harder.
  51. - Detecting dependencies by finding ``import`` statements: My experience is that
  52. this doesn't work well. It misses dynamically loaded dependencies, and it
  53. can have false positives where a module is only needed in some situations.
  54. I think specifying all modules needed is clearer than specifying
  55. corrections to what a tool detects.
  56. I am interested in dynamically finding dependencies by running a program;
  57. see my prototype `kartoffel <https://pypi.org/project/kartoffel/>`_ tool if
  58. you want to investigate this.
  59. - Single-file executables: You could probably reuse a lot of Pynsist's code to
  60. make single-file executables. They would 'install' to a temporary directory
  61. and then run the application. But it's not a feature I'm planning to include.
  62. - MSI packages: They have some advantages, but they're much more complicated to
  63. make than NSIS installers. I have `an experiment with using WiX
  64. <https://github.com/takluyver/pynsist/tree/wixperiment/examples/_mu>`_ in a
  65. branch; feel free to use it as a starting point.
  66. These aren't set in stone: I've changed my mind before, and it could well
  67. happen again.