瀏覽代碼

Start documenting API

Thomas Kluyver 11 年之前
父節點
當前提交
86793f73f8
共有 6 個文件被更改,包括 81 次插入0 次删除
  1. 8 0
      doc/api/index.rst
  2. 24 0
      doc/api/main.rst
  3. 12 0
      doc/api/nsiswriter.rst
  4. 2 0
      doc/cfgfile.rst
  5. 1 0
      doc/index.rst
  6. 34 0
      nsist/__init__.py

+ 8 - 0
doc/api/index.rst

@@ -0,0 +1,8 @@
+Python API
+==========
+
+.. toctree::
+   :maxdepth: 2
+
+   main
+   nsiswriter

+ 24 - 0
doc/api/main.rst

@@ -0,0 +1,24 @@
+Building installers
+===================
+
+.. module:: nsist
+
+.. autoclass:: InstallerBuilder
+   
+   .. automethod:: run
+
+   .. automethod:: fetch_python
+
+   .. automethod:: fetch_pylauncher
+
+   .. automethod:: write_script
+
+   .. automethod:: prepare_shortcuts
+
+   .. automethod:: prepare_packages
+
+   .. automethod:: copy_extra_files
+   
+   .. automethod:: write_nsi
+
+   .. automethod:: run_nsis

+ 12 - 0
doc/api/nsiswriter.rst

@@ -0,0 +1,12 @@
+Writing NSIS files
+==================
+
+.. module:: nsist.nsiswriter
+
+.. autoclass:: NSISFileWriter
+
+   .. automethod:: __init__
+
+   .. automethod:: write
+
+   .. automethod:: write_definitions

+ 2 - 0
doc/cfgfile.rst

@@ -65,6 +65,8 @@ Application section
    a console for the process. If ``false``, or not specified, they will use the
    a console for the process. If ``false``, or not specified, they will use the
    ``pyw`` launcher, which doesn't create a console.
    ``pyw`` launcher, which doesn't create a console.
 
 
+.. _shortcut_config:
+
 Shortcut sections
 Shortcut sections
 -----------------
 -----------------
 
 

+ 1 - 0
doc/index.rst

@@ -51,6 +51,7 @@ Contents
    cfgfile
    cfgfile
    faq
    faq
    releasenotes
    releasenotes
+   api/index
 
 
 See also the `examples folder <https://github.com/takluyver/pynsist/tree/master/examples>`_
 See also the `examples folder <https://github.com/takluyver/pynsist/tree/master/examples>`_
 in the repository.
 in the repository.

+ 34 - 0
nsist/__init__.py

@@ -39,6 +39,21 @@ else:
     DEFAULT_BITNESS = 32
     DEFAULT_BITNESS = 32
 
 
 class InstallerBuilder(object):
 class InstallerBuilder(object):
+    """Controls building an installer.
+    
+    :param str appname: Application name
+    :param str version: Application version
+    :param list shortcuts: List of dictionaries, with keys matching
+            :ref:`shortcut_config` in the config file
+    :param str icon: Path to an icon for the application
+    :param list packages: List of strings for importable packages to include
+    :param list extra_files: List of 2-tuples (file, destination) of files to include
+    :param str py_version: Full version of Python to bundle
+    :param int py_bitness: Bitness of bundled Python (32 or 64)
+    :param str build_dir: Directory to run the build in
+    :param str installer_name: Filename of the installer to produce
+    :param str nsi_template: Path to a template NSI file to use
+    """
     def __init__(self, appname, version, shortcuts, icon=DEFAULT_ICON, 
     def __init__(self, appname, version, shortcuts, icon=DEFAULT_ICON, 
                 packages=None, extra_files=None, py_version=DEFAULT_PY_VERSION,
                 packages=None, extra_files=None, py_version=DEFAULT_PY_VERSION,
                 py_bitness=DEFAULT_BITNESS, build_dir=DEFAULT_BUILD_DIR,
                 py_bitness=DEFAULT_BITNESS, build_dir=DEFAULT_BUILD_DIR,
@@ -132,6 +147,14 @@ from {module} import {func}
                                                 module=module, func=func))
                                                 module=module, func=func))
 
 
     def prepare_shortcuts(self):
     def prepare_shortcuts(self):
+        """Prepare shortcut files in the build directory.
+        
+        If entry_point is specified, write the script. If script is specified,
+        copy to the build directory. Prepare target and parameters for these
+        shortcuts.
+        
+        Also copies shortcut icons
+        """
         files = set()
         files = set()
         for scname, sc in self.shortcuts.items():
         for scname, sc in self.shortcuts.items():
             if not sc.get('target'):
             if not sc.get('target'):
@@ -153,6 +176,12 @@ from {module} import {func}
         self.install_files.extend([(f, '$INSTDIR') for f in files])
         self.install_files.extend([(f, '$INSTDIR') for f in files])
     
     
     def prepare_packages(self):
     def prepare_packages(self):
+        """Move requested packages into the build directory.
+        
+        If a pynsist_pkgs directory exists, it is copied into the build
+        directory as pkgs/ . Any packages not already there are found on
+        sys.path and copied in.
+        """
         logger.info("Copying packages into build directory...")
         logger.info("Copying packages into build directory...")
         build_pkg_dir = pjoin(self.build_dir, 'pkgs')
         build_pkg_dir = pjoin(self.build_dir, 'pkgs')
         if os.path.isdir(build_pkg_dir):
         if os.path.isdir(build_pkg_dir):
@@ -187,6 +216,11 @@ from {module} import {func}
                 self.install_files.append((basename, destination))
                 self.install_files.append((basename, destination))
     
     
     def write_nsi(self):
     def write_nsi(self):
+        """Write the NSI file to define the NSIS installer.
+        
+        Most of the details of this are in the template and the
+        :class:`nsist.nsiswriter.NSISFileWriter` class.
+        """
         nsis_writer = NSISFileWriter(self.nsi_template, installerbuilder=self,
         nsis_writer = NSISFileWriter(self.nsi_template, installerbuilder=self,
             definitions = {'PRODUCT_NAME': self.appname,
             definitions = {'PRODUCT_NAME': self.appname,
                            'PRODUCT_VERSION': self.version,
                            'PRODUCT_VERSION': self.version,