srcanamdw/codescanner/pyinstaller/doc/source/Manual.rst
author noe\swadi
Thu, 18 Feb 2010 12:29:02 +0530
changeset 1 22878952f6e2
permissions -rw-r--r--
Committing the CodeScanner Core tool This component has been moved from the StaticAnaApps package. BUG : 5889 (http://developer.symbian.org/webbugs/show_bug.cgi?id=5889).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     1
==================
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     2
PyInstaller Manual
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     3
==================
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     4
:Author: William Caban (based on Gordon McMillan's manual)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     5
:Contact: william@hpcf.upr.edu
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     6
:Revision: $Rev: 257 $
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     7
:Source URL: $HeadURL: http://svn.pyinstaller.python-hosting.com/trunk/doc/source/Manual.rst $
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     8
:Copyright: This document has been placed in the public domain.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     9
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    10
.. contents::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    11
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    12
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    13
Getting Started
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    14
+++++++++++++++
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    15
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    16
Installing PyInstaller
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    17
----------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    18
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    19
First, unpack the archive on you path of choice. Installer is **not** a Python
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    20
package, so it doesn't need to go in site-packages, or have a .pth file. For
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    21
the purpose of this documentation we will assume |install_path|. You will be
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    22
using a couple of scripts in the |install_path| directory, and these will find
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    23
everything they need from their own location. For convenience, keep the paths
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    24
to these scripts short (don't install in a deeply nested subdirectory).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    25
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    26
|PyInstaller| is dependant to the version of python you configure it for. In
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    27
other words, you will need a separate copy of |PyInstaller| for each Python
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    28
version you wish to work with *or* you'll need to rerun ``Configure.py`` every
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    29
time you switch the Python version).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    30
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    31
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    32
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    33
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    34
Building the runtime executables
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    35
--------------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    36
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    37
*Note:* Windows users can skip this step, because all of Python is contained in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    38
pythonXX.dll, and |PyInstaller| will use your pythonXX.dll.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    39
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    40
On Linux the first thing to do is build the runtime executables.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    41
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    42
Change to the |install_path| ``source/linux`` subdirectory. Run ``Make.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    43
[-n|-e]`` and then make. This will produce ``support/loader/run`` and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    44
``support/loader/run_d``, which are the bootloaders.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    45
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    46
.. sidebar:: Bootloader
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    47
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    48
   The bootloader (also known as *stub* in literature) is the small program
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    49
   which starts up your packaged program. Usually, the archive containing the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    50
   bytecoded modules of your program is simply attended to it. See
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    51
   `Self-extracting executables`_ for more details on the process.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    52
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    53
*Note:* If you have multiple versions of Python, the Python you use to run
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    54
``Make.py`` is the one whose configuration is used.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    55
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    56
The ``-n`` and ``-e`` options set a non-elf or elf flag in your ``config.dat``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    57
As of |InitialVersion|, the executable will try both strategies, and this flag
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    58
just sets how you want your executables built. In the elf strategy, the archive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    59
is concatenated to the executable. In the non-elf strategy, the executable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    60
expects an archive with the same name as itself in the executable's directory.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    61
Note that the executable chases down symbolic links before determining it's name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    62
and directory, so putting the archive in the same directory as the symbolic link
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    63
will not work.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    64
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    65
Windows distributions come with several executables in the ``support/loader``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    66
directory: ``run_*.exe`` (bootloader for regular programs), and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    67
``inprocsrvr_*.dll`` (bootloader for in-process COM servers). To rebuild this,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    68
you need to install Scons_, and then just run ``scons`` from the |install_path|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    69
directory.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    70
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    71
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    72
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    73
Configuring your PyInstaller setup
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    74
----------------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    75
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    76
In the |install_path| directory, run ``Configure.py``. This saves some
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    77
information into ``config.dat`` that would otherwise be recomputed every time.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    78
It can be rerun at any time if your configuration changes. It must be run before
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    79
trying to build anything.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    80
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    81
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    82
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    83
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    84
Create a spec file for your project
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    85
-----------------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    86
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    87
[For Windows COM server support, see section `Windows COM Server Support`_]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    88
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    89
The root directory has a script Makespec.py for this purpose::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    90
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    91
       python Makespec.py [opts] <scriptname> [<scriptname> ...]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    92
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    93
Where allowed OPTIONS are:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    94
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    95
-F, --onefile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    96
    produce a single file deployment (see below).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    97
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    98
-D, --onedir
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    99
    produce a single directory deployment (default).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   100
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   101
-K, --tk
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   102
    include TCL/TK in the deployment.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   103
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   104
-a, --ascii
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   105
    do not include encodings. The default (on Python versions with unicode
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   106
    support) is now to include all encodings.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   107
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   108
-d, --debug
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   109
    use debug (verbose) versions of the executables.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   110
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   111
-w, --windowed, --noconsole
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   112
    Use the Windows subsystem executable, which does not open
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   113
    the console when the program is launched. **(Windows only)**
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   114
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   115
-c, --nowindowed, --console
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   116
    Use the console subsystem executable. This is the default. **(Windows only)**
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   117
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   118
-s, --strip
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   119
    the executable and all shared libraries will be run through strip. Note
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   120
    that cygwin's strip tends to render normal Win32 dlls unusable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   121
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   122
-X, --upx
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   123
    if you have UPX installed (detected by Configure), this will use it to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   124
    compress your executable (and, on Windows, your dlls). See note below.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   125
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   126
-o DIR, --out=DIR
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   127
    create the spec file in *directory*. If not specified, and the current
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   128
    directory is Installer's root directory, an output subdirectory will be
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   129
    created. Otherwise the current directory is used.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   130
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   131
-p DIR, --paths=DIR
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   132
    set base path for import (like using PYTHONPATH). Multiple directories are
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   133
    allowed, separating them with the path separator (';' under Windows, ':'
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   134
    under Linux), or using this option multiple times.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   135
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   136
--icon=<FILE.ICO>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   137
    add *file.ico* to the executable's resources. **(Windows only)**
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   138
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   139
--icon=<FILE.EXE,N>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   140
    add the *n*-th incon in *file.exe* to the executable's resources. **(Windows
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   141
    only)**
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   142
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   143
-v FILE, --version=FILE
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   144
    add verfile as a version resource to the executable. **(Windows only)**
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   145
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   146
-n NAME, --name=NAME
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   147
    optional *name* to assign to the project (from which the spec file name is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   148
    generated). If omitted, the basename of the (first) script is used.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   149
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   150
[For building with optimization on (like ``Python -O``), see section
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   151
`Building Optimized`_]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   152
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   153
For simple projects, the generated spec file will probably be sufficient. For
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   154
more complex projects, it should be regarded as a template. The spec file is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   155
actually Python code, and modifying it should be ease. See `Spec Files`_ for
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   156
details.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   157
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   158
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   159
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   160
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   161
Build your project
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   162
------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   163
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   164
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   165
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   166
      python Build.py specfile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   167
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   168
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   169
A ``buildproject`` subdirectory will be created in the specfile's directory. This
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   170
is a private workspace so that ``Build.py`` can act like a makefile. Any named
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   171
targets will appear in the specfile's directory. For ``--onedir``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   172
configurations, it will create also ``distproject``, which is the directory you're
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   173
interested in. For a ``--onefile``, the executable will be in the specfile's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   174
directory.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   175
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   176
In most cases, this will be all you have to do. If not, see `When things go
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   177
wrong`_ and be sure to read the introduction to `Spec Files`_.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   178
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   179
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   180
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   181
Windows COM Server support
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   182
--------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   183
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   184
For Windows COM support execute::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   185
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   186
       python MakeCOMServer.py [OPTION] script...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   187
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   188
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   189
This will generate a new script ``drivescript.py`` and a spec file for the script.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   190
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   191
These options are allowed:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   192
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   193
--debug
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   194
    Use the verbose version of the executable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   195
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   196
--verbose
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   197
    Register the COM server(s) with the quiet flag off.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   198
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   199
--ascii
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   200
    do not include encodings (this is passed through to Makespec).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   201
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   202
--out <dir>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   203
    Generate the driver script and spec file in dir.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   204
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   205
Now `Build your project`_ on the generated spec file.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   206
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   207
If you have the win32dbg package installed, you can use it with the generated
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   208
COM server. In the driver script, set ``debug=1`` in the registration line.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   209
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   210
**Warnings**: the inprocess COM server support will not work when the client
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   211
process already has Python loaded. It would be rather tricky to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   212
non-obtrusively hook into an already running Python, but the show-stopper is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   213
that the Python/C API won't let us find out which interpreter instance I should
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   214
hook into. (If this is important to you, you might experiment with using
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   215
apartment threading, which seems the best possibility to get this to work). To
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   216
use a "frozen" COM server from a Python process, you'll have to load it as an
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   217
exe::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   218
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   219
      o = win32com.client.Dispatch(progid,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   220
                       clsctx=pythoncom.CLSCTX_LOCAL_SERVER)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   221
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   222
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   223
MakeCOMServer also assumes that your top level code (registration etc.) is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   224
"normal". If it's not, you will have to edit the generated script.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   225
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   226
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   227
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   228
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   229
Building Optimized
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   230
------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   231
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   232
There are two facets to running optimized: gathering ``.pyo``'s, and setting the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   233
``Py_OptimizeFlag``. Installer will gather ``.pyo``'s if it is run optimized::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   234
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   235
       python -O Build.py ...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   236
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   237
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   238
The ``Py_OptimizeFlag`` will be set if you use a ``('O','','OPTION')`` in one of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   239
the ``TOCs`` building the ``EXE``::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   240
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   241
      exe = EXE(pyz,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   242
                a.scripts + [('O','','OPTION')],
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   243
                ...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   244
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   245
See `Spec Files`_ for details.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   246
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   247
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   248
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   249
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   250
A Note on using UPX
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   251
-------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   252
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   253
On both Windows and Linux, UPX can give truly startling compression - the days
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   254
of fitting something useful on a diskette are not gone forever! Installer has
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   255
been tested with many UPX versions without problems. Just get it and install it
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   256
on your PATH, then rerun configure.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   257
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   258
For Windows, there is a problem of compatibility between UPX and executables
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   259
generated by Microsoft Visual Studio .NET 2003 (or the equivalent free
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   260
toolkit available for download). This is especially worrisome for users of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   261
Python 2.4+, where most extensions (and Python itself) are compiled with that
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   262
compiler. This issue has been fixed in later beta versions of UPX, so you
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   263
will need at least UPX 1.92 beta. `Configure.py`_ will check this for you
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   264
and complain if you have an older version of UPX and you are using Python 2.4.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   265
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   266
.. sidebar:: UPX and Unix
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   267
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   268
    Under UNIX, old versions of UPX were not able to expand and execute the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   269
    executable in memory, and they were extracting it into a temporary file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   270
    in the filesystem, before spawning it. This is no longer valid under Linux,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   271
    but the information in this paragraph still needs to be updated.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   272
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   273
.. _`Configure.py`: `Configuring your PyInstaller setup`_
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   274
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   275
For Linux, a bit more discussion is in order. First, UPX is only useful on
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   276
executables, not shared libs. Installer accounts for that, but to get the full
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   277
benefit, you might rebuild Python with more things statically linked.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   278
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   279
More importantly, when ``run`` finds that its ``sys.argv[0]`` does not contain a path,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   280
it will use ``/proc/pid/exe`` to find itself (if it can). This happens, for
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   281
example, when executed by Apache. If it has been upx-ed, this symbolic link
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   282
points to the tempfile created by the upx stub and |PyInstaller| will fail (please
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   283
see the UPX docs for more information). So for now, at least, you can't use upx
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   284
for CGI's executed by Apache. Otherwise, you can ignore the warnings in the UPX
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   285
docs, since what PyInstaller opens is the executable Installer created, not the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   286
temporary upx-created executable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   287
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   288
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   289
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   290
A Note on ``--onefile``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   291
-----------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   292
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   293
A ``--onefile`` works by packing all the shared libs / dlls into the archive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   294
attached to the bootloader executable (or next to the executable in a non-elf
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   295
configuration). When first started, it finds that it needs to extract these
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   296
files before it can run "for real". That's because locating and loading a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   297
shared lib or linked-in dll is a system level action, not user-level. With
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   298
|PyInstallerVersion| it always uses a temporary directory (``_MEIpid``) in the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   299
user's temp directory. It then executes itself again, setting things up so
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   300
the system will be able to load the shared libs / dlls. When executing is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   301
complete, it recursively removes the entire directory it created.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   302
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   303
This has a number of implications:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   304
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   305
* You can run multiple copies - they won't collide.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   306
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   307
* Running multiple copies will be rather expensive to the system (nothing is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   308
  shared).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   309
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   310
* If you're using the cheat of adding user data as ``'BINARY'``, it will be in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   311
  ``os.environ['_MEIPASS2']``, not in the executable's directory.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   312
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   313
* On Windows, using Task Manager to kill the parent process will leave the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   314
  directory behind.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   315
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   316
* On \*nix, a kill -9 (or crash) will leave the directory behind.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   317
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   318
* Otherwise, on both platforms, the directory will be recursively deleted.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   319
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   320
* So any files you might create in ``os.environ['_MEIPASS2']`` will be deleted.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   321
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   322
* The executable can be in a protected or read-only directory.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   323
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   324
* If for some reason, the ``_MEIpid`` directory already exists, the executable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   325
  will fail. It is created mode 0700, so only the one user can modify it
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   326
  (on \*nix, of course).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   327
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   328
While we are not a security expert, we believe the scheme is good enough for
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   329
most of the users.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   330
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   331
**Notes for \*nix users**: Take notice that if the executable does a setuid root,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   332
a determined hacker could possibly (given enough tries) introduce a malicious
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   333
lookalike of one of the shared libraries during the hole between when the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   334
library is extracted and when it gets loaded by the execvp'd process. So maybe
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   335
you shouldn't do setuid root programs using ``--onefile``. **In fact, we do not
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   336
recomend the use of --onefile on setuid programs.**
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   337
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   338
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   339
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   340
A Note on .egg files and setuptools
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   341
-----------------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   342
`setuptools`_ is a distutils extensions which provide many benefits, including
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   343
the ability to distribute the extension as ``egg`` files. Together with the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   344
nifty `easy_install`_ (a tool which automatically locates, downloads and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   345
installs Python extensions), ``egg`` files are becoming more and more
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   346
widespread as a way for distributing Python extensions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   347
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   348
``egg`` files are actually ZIP files under the hood, and they rely on the fact
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   349
that Python 2.4 is able to transparently import modules stored within ZIP
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   350
files. PyInstaller is currently *not* able to import and extract modules
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   351
within ZIP files, so code which uses extensions packaged as ``egg`` files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   352
cannot be packaged with PyInstaller.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   353
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   354
The workaround is pretty easy: you can use ``easy_install -Z`` at installation
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   355
time to ask ``easy_install`` to always decompress egg files. This will allow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   356
PyInstaller to see the files and make the package correctly. If you have already
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   357
installed the modules, you can simply decompress them within a directory with
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   358
the same name of the ``egg`` file (including also the extension).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   359
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   360
Support for ``egg`` files is planned for a future release of PyInstaller.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   361
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   362
.. _`setuptools`: http://peak.telecommunity.com/DevCenter/setuptools
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   363
.. _`easy_install`: http://peak.telecommunity.com/DevCenter/EasyInstall
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   364
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   365
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   366
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   367
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   368
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   369
PyInstaller Utilities
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   370
+++++++++++++++++++++
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   371
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   372
ArchiveViewer
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   373
-------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   374
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   375
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   376
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   377
      python ArchiveViewer.py <archivefile>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   378
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   379
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   380
ArchiveViewer lets you examine the contents of any archive build with
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   381
|PyInstaller| or executable (PYZ, PKG or exe). Invoke it with the target as the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   382
first arg (It has been set up as a Send-To so it shows on the context menu in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   383
Explorer). The archive can be navigated using these commands:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   384
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   385
O <nm>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   386
    Open the embedded archive <nm> (will prompt if omitted).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   387
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   388
U
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   389
    Go up one level (go back to viewing the embedding archive).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   390
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   391
X <nm>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   392
    Extract nm (will prompt if omitted). Prompts for output filename. If none
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   393
    given, extracted to stdout.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   394
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   395
Q
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   396
    Quit.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   397
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   398
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   399
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   400
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   401
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   402
bindepend
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   403
---------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   404
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   405
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   406
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   407
    python bindepend.py <executable_or_dynamic_library>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   408
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   409
bindepend will analyze the executable you pass to it, and write to stdout all
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   410
its binary dependencies. This is handy to find out which DLLs are required by
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   411
an executable or another DLL. This module is used by |PyInstaller| itself to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   412
follow the chain of dependencies of binary extensions and make sure that all
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   413
of them get included in the final package.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   414
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   415
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   416
GrabVersion (Windows)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   417
---------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   418
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   419
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   420
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   421
      python GrabVersion.py <executable_with_version_resource>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   422
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   423
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   424
GrabVersion outputs text which can be eval'ed by ``versionInfo.py`` to reproduce
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   425
a version resource. Invoke it with the full path name of a Windows executable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   426
(with a version resource) as the first argument. If you cut & paste (or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   427
redirect to a file), you can then edit the version information. The edited
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   428
text file can be used in a ``version = myversion.txt`` option on any executable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   429
in an |PyInstaller| spec file.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   430
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   431
This was done in this way because version resources are rather strange beasts,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   432
and fully understanding them is probably impossible. Some elements are
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   433
optional, others required, but you could spend unbounded amounts of time
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   434
figuring this out, because it's not well documented. When you view the version
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   435
tab on a properties dialog, there's no straightforward relationship between
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   436
how the data is displayed and the structure of the resource itself. So the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   437
easiest thing to do is find an executable that displays the kind of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   438
information you want, grab it's resource and edit it. Certainly easier than
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   439
the Version resource wizard in VC++.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   440
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   441
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   442
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   443
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   444
Analyzing Dependencies
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   445
----------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   446
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   447
You can interactively track down dependencies, including getting
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   448
cross-references by using ``mf.py``, documented in section `mf.py: A modulefinder
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   449
Replacement`_
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   450
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   451
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   452
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   453
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   454
Spec Files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   455
++++++++++
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   456
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   457
Introduction
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   458
------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   459
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   460
Spec files are in Python syntax. They are evaluated by Build.py. A simplistic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   461
spec file might look like this::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   462
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   463
      a = Analysis(['myscript.py'])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   464
      pyz = PYZ(a.pure)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   465
      exe = EXE(pyz, a.scripts, a.binaries, name="myapp.exe")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   466
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   467
This creates a single file deployment with all binaries (extension modules and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   468
their dependencies) packed into the executable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   469
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   470
A simplistic single directory deployment might look like this::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   471
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   472
      a = Analysis(['myscript.py'])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   473
      pyz = PYZ(a.pure)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   474
      exe = EXE(a.scripts, pyz, name="myapp.exe", exclude_binaries=1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   475
      dist = COLLECT(exe, a.binaries, name="dist")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   476
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   477
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   478
Note that neither of these examples are realistic. Use ``Makespec.py`` (documented
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   479
in section `Create a spec file for your project`_) to create your specfile,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   480
and tweak it (if necessary) from there.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   481
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   482
All of the classes you see above are subclasses of ``Build.Target``. A Target acts
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   483
like a rule in a makefile. It knows enough to cache its last inputs and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   484
outputs. If its inputs haven't changed, it can assume its outputs wouldn't
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   485
change on recomputation. So a spec file acts much like a makefile, only
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   486
rebuilding as much as needs rebuilding. This means, for example, that if you
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   487
change an ``EXE`` from ``debug=1`` to ``debug=0``, the rebuild will be nearly
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   488
instantaneous.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   489
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   490
The high level view is that an ``Analysis`` takes a list of scripts as input,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   491
and generates three "outputs", held in attributes named ``scripts``, ``pure``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   492
and ``binaries``. A ``PYZ`` (a ``.pyz`` archive) is built from the modules in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   493
pure. The ``EXE`` is built from the ``PYZ``, the scripts and, in the case of a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   494
single-file deployment, the binaries. In a single-directory deployment, a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   495
directory is built containing a slim executable and the binaries.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   496
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   497
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   498
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   499
TOC Class (Table of Contents)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   500
-----------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   501
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   502
Before you can do much with a spec file, you need to understand the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   503
``TOC`` (Table Of Contents) class.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   504
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   505
A ``TOC`` appears to be a list of tuples of the form (name, path, typecode).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   506
In fact, it's an ordered set, not a list. A TOC contains no duplicates, where
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   507
uniqueness is based on name only. Furthermore, within this constraint, a TOC
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   508
preserves order.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   509
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   510
Besides the normal list methods and operations, TOC supports taking differences
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   511
and intersections (and note that adding or extending is really equivalent to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   512
union). Furthermore, the operations can take a real list of tuples on the right
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   513
hand side. This makes excluding modules quite easy. For a pure Python module::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   514
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   515
      pyz = PYZ(a.pure - [('badmodule', '', '')])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   516
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   517
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   518
or for an extension module in a single-directory deployment::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   519
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   520
      dist = COLLECT(..., a.binaries - [('badmodule', '', '')], ...)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   521
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   522
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   523
or for a single-file deployment::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   524
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   525
      exe = EXE(..., a.binaries - [('badmodule', '', '')], ...)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   526
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   527
To add files to a TOC, you need to know about the typecodes (or the step using
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   528
the TOC won't know what to do with the entry).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   529
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   530
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   531
| **typecode** 	| **description**					| **name**		| **path**			|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   532
+===============+=======================================================+=======================+===============================+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   533
| 'EXTENSION' 	| An extension module.					| Python internal name.	| Full path name in build.	|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   534
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   535
| 'PYSOURCE'	| A script.						| Python internal name.	| Full path name in build.	|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   536
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   537
| 'PYMODULE'	| A pure Python module (including __init__ modules).	| Python internal name.	| Full path name in build.	|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   538
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   539
| 'PYZ'		| A .pyz archive (archive_rt.ZlibArchive).		| Runtime name.		| Full path name in build.	|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   540
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   541
| 'PKG'		| A pkg archive (carchive4.CArchive).			| Runtime name. 	| Full path name in build.	|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   542
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   543
| 'BINARY' 	| A shared library. 					| Runtime name. 	| Full path name in build.	|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   544
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   545
| 'DATA' 	| Aribitrary files. 					| Runtime name. 	| Full path name in build.	|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   546
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   547
| 'OPTION' 	| A runtime runtime option (frozen into the executable).| The option.		| Unused.			|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   548
+---------------+-------------------------------------------------------+-----------------------+-------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   549
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   550
You can force the include of any file in much the same way you do excludes::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   551
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   552
      collect = COLLECT(a.binaries +
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   553
                [('readme', '/my/project/readme', 'DATA')], ...)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   554
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   555
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   556
or even::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   557
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   558
      collect = COLLECT(a.binaries,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   559
                [('readme', '/my/project/readme', 'DATA')], ...)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   560
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   561
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   562
(that is, you can use a list of tuples in place of a ``TOC`` in most cases).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   563
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   564
There's not much reason to use this technique for ``PYSOURCE``, since an ``Analysis``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   565
takes a list of scripts as input. For ``PYMODULEs`` and ``EXTENSIONs``, the hook
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   566
mechanism discussed here is better because you won't have to remember how you
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   567
got it working next time.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   568
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   569
This technique is most useful for data files (see the ``Tree`` class below for a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   570
way to build a ``TOC`` from a directory tree), and for runtime options. The options
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   571
the run executables understand are:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   572
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   573
+---------------+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   574
| **Option**	| **Description**	| **Example**			| **Notes**												|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   575
+===============+=======================+===============================+=======================================================================================================+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   576
| v 		| Verbose imports	| ('v', '', 'OPTION')		| Same as Python -v ... 										|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   577
+---------------+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   578
| u		| Unbuffered stdio	| ('u', '', 'OPTION')		| Same as Python -u ... 										|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   579
+---------------+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   580
| W spec	| Warning option	| ('W ignore', '', 'OPTION')	| Python 2.1+ only. 											|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   581
+---------------+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   582
| s		| Use site.py		| ('s', '', 'OPTION')		| The opposite of Python's -S flag. Note that site.py must be in the executable's directory to be used. |
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   583
+---------------+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   584
| f		| Force execvp		| ('f', '', 'OPTION')		| Linux/unix only. Ensures that LD_LIBRARY_PATH is set properly.					|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   585
+---------------+-----------------------+-------------------------------+-------------------------------------------------------------------------------------------------------+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   586
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   587
Advanced users should note that by using set differences and intersections, it
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   588
becomes possible to factor out common modules, and deploy a project containing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   589
multiple executables with minimal redundancy. You'll need some top level code
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   590
in each executable to mount the common ``PYZ``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   591
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   592
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   593
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   594
Target Subclasses
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   595
-----------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   596
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   597
Analysis
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   598
********
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   599
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   600
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   601
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   602
      Analysis(scripts, pathex=None, hookspath=None, excludes=None)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   603
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   604
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   605
``scripts``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   606
    a list of scripts specified as file names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   607
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   608
``pathex``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   609
    an optional list of paths to be searched before sys.path.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   610
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   611
``hookspath``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   612
    an optional list of paths used to extend the hooks package.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   613
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   614
``excludes``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   615
    an optional list of module or package names (their Python names, not path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   616
    names) that will be ignored (as though they were not found).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   617
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   618
An Analysis has three outputs, all ``TOCs`` accessed as attributes of the ``Analysis``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   619
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   620
``scripts``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   621
    The scripts you gave Analysis as input, with any runtime hook scripts
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   622
    prepended.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   623
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   624
``pure``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   625
    The pure Python modules.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   626
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   627
``binaries``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   628
    The extension modules and their dependencies. The secondary dependencies are
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   629
    filtered. On Windows, a long list of MS dlls are excluded. On Linux/Unix,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   630
    any shared lib in ``/lib`` or ``/usr/lib`` is excluded.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   631
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   632
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   633
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   634
PYZ
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   635
***
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   636
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   637
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   638
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   639
      PYZ(toc, name=None, level=9)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   640
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   641
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   642
``toc``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   643
    a ``TOC``, normally an ``Analysis.pure``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   644
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   645
``name``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   646
    A filename for the ``.pyz``. Normally not needed, as the generated name will do fine.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   647
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   648
``level``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   649
    The Zlib compression level to use. If 0, the zlib module is not required.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   650
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   651
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   652
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   653
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   654
PKG
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   655
***
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   656
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   657
Generally, you will not need to create your own ``PKGs``, as the ``EXE`` will do it for
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   658
you. This is one way to include read-only data in a single-file deployment,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   659
however. A single-file deployment including TK support will use this technique.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   660
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   661
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   662
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   663
      PKG(toc, name=None, cdict=None, exclude_binaries=0)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   664
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   665
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   666
``toc``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   667
    a ``TOC``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   668
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   669
``name``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   670
    a filename for the ``PKG`` (optional).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   671
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   672
``cdict``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   673
    a dictionary that specifies compression by typecode. For example, ``PYZ`` is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   674
    left uncompressed so that it can be accessed inside the ``PKG``. The default
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   675
    uses sensible values. If zlib is not available, no compression is used.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   676
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   677
``exclude_binaries``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   678
    If 1, ``EXTENSIONs`` and ``BINARYs`` will be left out of the ``PKG``, and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   679
    forwarded to its container (usually a ``COLLECT``).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   680
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   681
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   682
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   683
EXE
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   684
***
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   685
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   686
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   687
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   688
      EXE(*args, **kws)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   689
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   690
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   691
``args``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   692
    One or more arguments which are either ``TOCs`` or ``Targets``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   693
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   694
``kws``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   695
    Possible keyword arguments:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   696
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   697
    ``console``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   698
        Always 1 on Linux/unix. On Windows, governs whether to use the console
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   699
        executable, or the Windows subsystem executable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   700
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   701
    ``debug``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   702
        Setting to 1 gives you progress messages from the executable (for a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   703
        ``console=0``, these will be annoying MessageBoxes).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   704
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   705
    ``name``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   706
        The filename for the executable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   707
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   708
    ``exclude_binaries``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   709
        Forwarded to the ``PKG`` the ``EXE`` builds.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   710
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   711
    ``icon``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   712
        Windows NT family only. ``icon='myicon.ico'`` to use an icon file, or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   713
        ``icon='notepad.exe,0'`` to grab an icon resource.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   714
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   715
    ``version``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   716
        Windows NT family only. ``version='myversion.txt'``. Use ``GrabVersion.py`` to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   717
        steal a version resource from an executable, and then edit the ouput to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   718
        create your own. (The syntax of version resources is so arcane that I
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   719
        wouldn't attempt to write one from scratch.)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   720
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   721
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   722
There are actually two ``EXE`` classes - one for ELF platforms (where the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   723
bootloader, that is the ``run`` executable, and the ``PKG`` are concatenated),
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   724
and one for non-ELF platforms (where the run executable is simply renamed, and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   725
expects a ``exename.pkg`` in the same directory). Which class becomes available
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   726
as ``EXE`` is determined by a flag in ``config.dat``. This flag is set to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   727
non-ELF when using ``Make.py -n``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   728
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   729
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   730
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   731
DLL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   732
***
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   733
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   734
On Windows, this provides support for doing in-process COM servers. It is not
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   735
generalized. However, embedders can follow the same model to build a special
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   736
purpose DLL so the Python support in their app is hidden. You will need to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   737
write your own dll, but thanks to Allan Green for refactoring the C code and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   738
making that a managable task.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   739
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   740
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   741
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   742
COLLECT
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   743
*******
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   744
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   745
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   746
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   747
      COLLECT(*args, **kws)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   748
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   749
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   750
``args``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   751
    One or more arguments which are either ``TOCs`` or ``Targets``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   752
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   753
``kws``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   754
    Possible keyword arguments:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   755
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   756
    ``name``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   757
        The name of the directory to be built.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   758
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   759
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   760
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   761
Tree
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   762
****
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   763
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   764
::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   765
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   766
      Tree(root, prefix=None, excludes=None)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   767
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   768
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   769
``root``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   770
    The root of the tree (on the build system).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   771
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   772
``prefix``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   773
    Optional prefix to the names on the target system.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   774
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   775
``excludes``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   776
    A list of names to exclude. Two forms are allowed:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   777
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   778
    ``name``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   779
        files with this basename will be excluded (do not include the path).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   780
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   781
    ``*.ext``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   782
        any file with the given extension will be excluded.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   783
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   784
Since a ``Tree`` is a ``TOC``, you can also use the exclude technique described above
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   785
in the section on ``TOCs``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   786
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   787
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   788
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   789
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   790
When Things Go Wrong
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   791
++++++++++++++++++++
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   792
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   793
Finding out What Went Wrong
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   794
---------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   795
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   796
Buildtime Warnings
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   797
******************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   798
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   799
When an ``Analysis`` step runs, it produces a warnings file (named ``warnproject.txt``)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   800
in the spec file's directory. Generally, most of these warnings are harmless.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   801
For example, ``os.py`` (which is cross-platform) works by figuring out what
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   802
platform it is on, then importing (and rebinding names from) the appropriate
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   803
platform-specific module. So analyzing ``os.py`` will produce a set of warnings
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   804
like::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   805
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   806
      W: no module named dos (conditional import by os)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   807
      W: no module named ce (conditional import by os)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   808
      W: no module named os2 (conditional import by os)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   809
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   810
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   811
Note that the analysis has detected that the import is within a conditional
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   812
block (an if statement). The analysis also detects if an import within a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   813
function or class, (delayed) or at the top level. A top-level, non-conditional
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   814
import failure is really a hard error. There's at least a reasonable chance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   815
that conditional and / or delayed import will be handled gracefully at runtime.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   816
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   817
Ignorable warnings may also be produced when a class or function is declared in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   818
a package (an ``__init__.py`` module), and the import specifies
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   819
``package.name``. In this case, the analysis can't tell if name is supposed to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   820
refer to a submodule of package.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   821
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   822
Warnings are also produced when an ``__import__``, ``exec`` or ``eval`` statement is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   823
encountered. The ``__import__`` warnings should almost certainly be investigated.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   824
Both ``exec`` and ``eval`` can be used to implement import hacks, but usually their use
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   825
is more benign.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   826
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   827
Any problem detected here can be handled by hooking the analysis of the module.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   828
See `Listing Hidden Imports`_ below for how to do it.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   829
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   830
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   831
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   832
Getting Debug Messages
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   833
**********************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   834
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   835
Setting ``debug=1`` on an ``EXE`` will cause the executable to put out progress
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   836
messages (for console apps, these go to stdout; for Windows apps, these show as
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   837
MessageBoxes). This can be useful if you are doing complex packaging, or your
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   838
app doesn't seem to be starting, or just to learn how the runtime works.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   839
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   840
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   841
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   842
Getting Python's Verbose Imports
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   843
********************************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   844
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   845
You can also pass a ``-v`` (verbose imports) flag to the embedded Python. This can
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   846
be extremely useful. I usually try it even on apparently working apps, just to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   847
make sure that I'm always getting my copies of the modules and no import has
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   848
leaked out to the installed Python.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   849
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   850
You set this (like the other runtime options) by feeding a phone ``TOC`` entry to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   851
the ``EXE``. The easiest way to do this is to change the ``EXE`` from::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   852
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   853
       EXE(..., anal.scripts, ....)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   854
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   855
to::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   856
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   857
       EXE(..., anal.scripts + [('v', '', 'OPTION')], ...)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   858
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   859
These messages will always go to ``stdout``, so you won't see them on Windows if
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   860
``console=0``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   861
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   862
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   863
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   864
Helping Installer Find Modules
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   865
------------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   866
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   867
Extending the Path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   868
******************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   869
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   870
When the analysis phase cannot find needed modules, it may be that the code is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   871
manipulating ``sys.path``. The easiest thing to do in this case is tell ``Analysis``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   872
about the new directory through the second arg to the constructor::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   873
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   874
       anal = Analysis(['somedir/myscript.py'],
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   875
                       ['path/to/thisdir', 'path/to/thatdir'])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   876
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   877
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   878
In this case, the ``Analysis`` will have a search path::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   879
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   880
       ['somedir', 'path/to/thisdir', 'path/to/thatdir'] + sys.path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   881
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   882
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   883
You can do the same when running ``Makespec.py``::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   884
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   885
       Makespec.py --paths=path/to/thisdir;path/to/thatdir ...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   886
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   887
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   888
(on \*nix, use ``:`` as the path separator).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   889
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   890
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   891
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   892
Listing Hidden Imports
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   893
**********************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   894
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   895
Hidden imports are fairly common. These can occur when the code is using
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   896
``__import__`` (or, perhaps ``exec`` or ``eval``), in which case you will see a warning in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   897
the ``warnproject.txt`` file. They can also occur when an extension module uses the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   898
Python/C API to do an import, in which case Analysis can't detect anything. You
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   899
can verify that hidden import is the problem by using Python's verbose imports
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   900
flag. If the import messages say "module not found", but the ``warnproject.txt``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   901
file has no "no module named..." message for the same module, then the problem
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   902
is a hidden import.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   903
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   904
.. sidebar:: Standard hidden imports are already included!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   905
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   906
    If you are getting worried while reading this paragraph, do not worry:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   907
    having hidden imports is the exception, not the norm! And anyway,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   908
    PyInstaller already ships with a large set of hooks that take care of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   909
    hidden imports for the most common packages out there. For instance,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   910
    PIL_, PyWin32_, PyQt_ are already taken care of.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   911
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   912
Hidden imports are handled by hooking the module (the one doing the hidden
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   913
imports) at ``Analysis`` time. Do this by creating a file named ``hook-module.py``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   914
(where module is the fully-qualified Python name, eg, ``hook-xml.dom.py``), and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   915
placing it in the ``hooks`` package under |PyInstaller|'s root directory,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   916
(alternatively, you can save it elsewhere, and then use the ``hookspath`` arg to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   917
``Analysis`` so your private hooks directory will be searched). Normally, it will
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   918
have only one line::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   919
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   920
      hiddenimports = ['module1', 'module2']
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   921
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   922
When the ``Analysis`` finds this file, it will proceed exactly as though the module
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   923
explicitly imported ``module1`` and ``module2``. (Full details on the analysis-time
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   924
hook mechanism is in the `Hooks`_ section).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   925
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   926
If you successfully hook a publicly distributed module in this way, please send
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   927
us the hook so we can make it available to others.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   928
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   929
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   930
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   931
Extending a Package's ``__path__``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   932
**********************************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   933
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   934
Python allows a package to extend the search path used to find modules and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   935
sub-packages through the ``__path__`` mechanism. Normally, a package's ``__path__`` has
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   936
only one entry - the directory in which the ``__init__.py`` was found. But
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   937
``__init__.py`` is free to extend its ``__path__`` to include other directories. For
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   938
example, the ``win32com.shell.shell`` module actually resolves to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   939
``win32com/win32comext/shell/shell.pyd``. This is because ``win32com/__init__.py``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   940
appends ``../win32comext`` to its ``__path__``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   941
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   942
Because the ``__init__.py`` is not actually run during an analysis, we use the same
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   943
hook mechanism we use for hidden imports. A static list of names won't do,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   944
however, because the new entry on ``__path__`` may well require computation. So
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   945
``hook-module.py`` should define a method ``hook(mod)``. The mod argument is an
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   946
instance of ``mf.Module`` which has (more or less) the same attributes as a real
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   947
module object. The hook function should return a ``mf.Module`` instance - perhaps
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   948
a brand new one, but more likely the same one used as an arg, but mutated.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   949
See `mf.py: A Modulefinder Replacement`_ for details, and `hooks\/hook-win32com.py`_
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   950
for an example.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   951
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   952
Note that manipulations of ``__path__`` hooked in this way apply to the analysis,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   953
and only the analysis. That is, at runtime ``win32com.shell`` is resolved the same
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   954
way as ``win32com.anythingelse``, and ``win32com.__path__`` knows nothing of ``../win32comext``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   955
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   956
Once in awhile, that's not enough.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   957
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   958
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   959
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   960
Changing Runtime Behavior
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   961
*************************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   962
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   963
More bizarre situations can be accomodated with runtime hooks. These are small
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   964
scripts that manipulate the environment before your main script runs,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   965
effectively providing additional top-level code to your script.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   966
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   967
At the tail end of an analysis, the module list is examined for matches in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   968
``rthooks.dat``, which is the string representation of a Python dictionary. The
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   969
key is the module name, and the value is a list of hook-script pathnames.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   970
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   971
So putting an entry::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   972
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   973
       'somemodule': ['path/to/somescript.py'],
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   974
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   975
into ``rthooks.dat`` is almost the same thing as doing this::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   976
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   977
       anal = Analysis(['path/to/somescript.py', 'main.py'], ...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   978
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   979
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   980
except that in using the hook, ``path/to/somescript.py`` will not be analyzed,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   981
(that's not a feature - we just haven't found a sane way fit the recursion into
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   982
my persistence scheme).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   983
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   984
Hooks done in this way, while they need to be careful of what they import, are
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   985
free to do almost anything. One provided hook sets things up so that win32com
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   986
can generate modules at runtime (to disk), and the generated modules can be
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   987
found in the win32com package.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   988
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   989
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   990
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   991
Adapting to being "frozen"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   992
**************************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   993
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   994
In most sophisticated apps, it becomes necessary to figure out (at runtime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   995
whether you're running "live" or "frozen". For example, you might have a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   996
configuration file that (running "live") you locate based on a module's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   997
``__file__`` attribute. That won't work once the code is packaged up. You'll
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   998
probably want to look for it based on ``sys.executable`` instead.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   999
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1000
The bootloaders set ``sys.frozen=1`` (and, for in-process COM servers, the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1001
embedding DLL sets ``sys.frozen='dll'``).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1002
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1003
For really advanced users, you can access the ``iu.ImportManager`` as
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1004
``sys.importManager``. See `iu.py`_ for how you might make use of this fact.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1005
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1006
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1007
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1008
Accessing Data Files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1009
********************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1010
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1011
In a ``--onedir`` distribution, this is easy: pass a list of your data files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1012
(in ``TOC`` format) to the ``COLLECT``, and they will show up in the distribution
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1013
directory tree. The name in the ``(name, path, 'DATA')`` tuple can be a relative
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1014
path name. Then, at runtime, you can use code like this to find the file::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1015
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1016
       os.path.join(os.path.dirname(sys.executable), relativename))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1017
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1018
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1019
In a ``--onefile``, it's a bit trickier. You can cheat, and add the files to the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1020
``EXE`` as ``BINARY``. They will then be extracted at runtime into the work directory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1021
by the C code (which does not create directories, so the name must be a plain
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1022
name), and cleaned up on exit. The work directory is best found by
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1023
``os.environ['_MEIPASS2']``. Be awawre, though, that if you use ``--strip`` or ``--upx``,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1024
strange things may happen to your data - ``BINARY`` is really for shared
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1025
libs / dlls.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1026
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1027
If you add them as ``'DATA'`` to the ``EXE``, then it's up to you to extract them. Use
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1028
code like this::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1029
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1030
       import sys, carchive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1031
       this = carchive.CArchive(sys.executable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1032
       data = this.extract('mystuff')[1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1033
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1034
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1035
to get the contents as a binary string. See `support\/unpackTK.py`_ for an advanced
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1036
example (the TCL and TK lib files are in a PKG which is opened in place, and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1037
then extracted to the filesystem).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1038
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1039
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1040
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1041
Miscellaneous
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1042
+++++++++++++
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1043
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1044
Pmw -- Python Mega Widgets
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1045
--------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1046
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1047
`Pmw`_ comes with a script named ``bundlepmw`` in the bin directory. If you follow the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1048
instructions in that script, you'll end up with a module named ``Pmw.py``. Ensure
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1049
that Builder finds that module and not the development package.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1050
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1051
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1052
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1053
Win9xpopen
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1054
----------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1055
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1056
If you're using popen on Windows and want the code to work on Win9x, you'll
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1057
need to distribute ``win9xpopen.exe`` with your app. On older Pythons with
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1058
Win32all, this would apply to Win32pipe and ``win32popenWin9x.exe``. (On yet older
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1059
Pythons, no form of popen worked on Win9x).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1060
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1061
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1062
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1063
Self-extracting executables
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1064
---------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1065
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1066
The ELF executable format (Windows, Linux and some others) allows arbitrary
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1067
data to be concatenated to the end of the executable without disturbing its
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1068
functionality. For this reason, a ``CArchive``'s Table of Contents is at the end of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1069
the archive. The executable can open itself as a binary file name, seek to the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1070
end and 'open' the ``CArchive`` (see figure 3).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1071
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1072
On other platforms, the archive and the executable are separate, but the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1073
archive is named ``executable.pkg``, and expected to be in the same directory.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1074
Other than that, the process is the same.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1075
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1076
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1077
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1078
One Pass Execution
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1079
******************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1080
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1081
In a single directory deployment (``--onedir``, which is the default), all of the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1082
binaries are already in the file system. In that case, the embedding app:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1083
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1084
* opens the archive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1085
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1086
* starts Python (on Windows, this is done with dynamic loading so one embedding
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1087
  app binary can be used with any Python version)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1088
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1089
* imports all the modules which are at the top level of the archive (basically,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1090
  bootstraps the import hooks)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1091
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1092
* mounts the ``ZlibArchive(s)`` in the outer archive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1093
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1094
* runs all the scripts which are at the top level of the archive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1095
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1096
* finalizes Python
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1097
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1098
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1099
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1100
Two Pass Execution
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1101
******************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1102
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1103
There are a couple situations which require two passes:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1104
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1105
* a ``--onefile`` deployment (on Windows, the files can't be cleaned up afterwards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1106
  because Python does not call ``FreeLibrary``; on other platforms, Python won't
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1107
  find them if they're extracted in the same process that uses them)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1108
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1109
* ``LD_LIBRARY_PATH`` needs to be set to find the binaries (not extension modules,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1110
  but modules the extensions are linked to).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1111
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1112
The first pass:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1113
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1114
* opens the archive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1115
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1116
* extracts all the binaries in the archive (in |PyInstallerVersion|, this is always to a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1117
  temporary directory).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1118
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1119
* sets a magic environment variable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1120
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1121
* sets ``LD_LIBRARY_PATH`` (non-Windows)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1122
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1123
* executes itself as a child process (letting the child use his stdin, stdout
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1124
  and stderr)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1125
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1126
* waits for the child to exit (on \*nix, the child actually replaces the parent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1127
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1128
* cleans up the extracted binaries (so on \*nix, this is done by the child)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1129
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1130
The child process executes as in `One Pass Execution`_ above (the magic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1131
environment variable is what tells it that this is pass two).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1132
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1133
|SE_exeImage| figure 3 - Self Extracting Executable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1134
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1135
There are, of course, quite a few differences between the Windows and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1136
Unix/Linux versions. The major one is that because all of Python on Windows is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1137
in ``pythonXX.dll``, and dynamic loading is so simple-minded, that one binary can
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1138
be use with any version of Python. There's much in common, though, and that C
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1139
code can be found in `source/common/launch.c`_.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1140
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1141
The Unix/Linux build process (which you need to run just once for any version
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1142
of Python) makes use of the config information in your install (if you
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1143
installed from RPM, you need the Python-development RPM). It also overrides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1144
``getpath.c`` since we don't want it hunting around the filesystem to build
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1145
``sys.path``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1146
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1147
In both cases, while one |PyInstaller| download can be used with any Python
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1148
version, you need to have separate installations for each Python version.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1149
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1150
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1151
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1152
PyInstaller Archives
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1153
++++++++++++++++++++
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1154
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1155
Archives Introduction
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1156
---------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1157
You know what an archive is: a ``.tar`` file, a ``.jar`` file, a ``.zip`` file. Two kinds
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1158
of archives are used here. One is equivalent to a Java ``.jar`` file - it allows
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1159
Python modules to be stored efficiently and, (with some import hooks) imported
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1160
directly. This is a ``ZlibArchive``. The other (a ``CArchive``) is equivalent to a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1161
``.zip`` file - a general way of packing up (and optionally compressing) arbitrary
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1162
blobs of data. It gets its name from the fact that it can be manipulated easily
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1163
from C, as well as from Python. Both of these derive from a common base class,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1164
making it fairly easy to create new kinds of archives.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1165
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1166
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1167
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1168
``ZlibArchive``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1169
---------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1170
A ``ZlibArchive`` contains compressed ``.pyc`` (or ``.pyo``) files. The Table of Contents
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1171
is a marshalled dictionary, with the key (the module's name as given in an
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1172
``import`` statement) associated with a seek position and length. Because it is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1173
all marshalled Python, ``ZlibArchives`` are completely cross-platform.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1174
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1175
A ``ZlibArchive`` hooks in with `iu.py`_ so that, with a little setup, the archived
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1176
modules can be imported transparently. Even with compression at level 9, this
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1177
works out to being faster than the normal import. Instead of searching
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1178
``sys.path``, there's a lookup in the dictionary. There's no ``stat``-ing of the ``.py``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1179
and ``.pyc`` and no file opens (the file is already open). There's just a seek, a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1180
read and a decompress. A traceback will point to the source file the archive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1181
entry was created from (the ``__file__`` attribute from the time the ``.pyc`` was
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1182
compiled). On a user's box with no source installed, this is not terribly
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1183
useful, but if they send you the traceback, at least you can make sense of it.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1184
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1185
|ZlibArchiveImage|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1186
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1187
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1188
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1189
``CArchive``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1190
------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1191
A ``CArchive`` contains whatever you want to stuff into it. It's very much like a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1192
``.zip`` file. They are easy to create in Python and unpack from C code. ``CArchives``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1193
can be appended to other files (like ELF and COFF executables, for example).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1194
To allow this, they are opened from the end, so the ``TOC`` for a ``CArchive`` is at
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1195
the back, followed only by a cookie that tells you where the ``TOC`` starts and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1196
where the archive itself starts.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1197
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1198
``CArchives`` can also be embedded within other ``CArchives``. The inner archive can be
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1199
opened in place (without extraction).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1200
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1201
Each ``TOC`` entry is variable length. The first field in the entry tells you the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1202
length of the entry. The last field is the name of the corresponding packed
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1203
file. The name is null terminated. Compression is optional by member.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1204
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1205
There is also a type code associated with each entry. If you're using a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1206
``CArchive`` as a ``.zip`` file, you don't need to worry about this. The type codes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1207
are used by the self-extracting executables.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1208
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1209
|CArchiveImage|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1210
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1211
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1212
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1213
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1214
License
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1215
+++++++
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1216
PyInstaller is mainly distributed  under the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1217
`GPL License <http://pyinstaller.hpcf.upr.edu/pyinstaller/browser/trunk/doc/LICENSE.GPL?rev=latest>`_
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1218
but it has an exception such that you can use it to compile commercial products.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1219
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1220
In a nutshell, the license is GPL for the source code with the exception that:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1221
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1222
 #. You may use PyInstaller to compile commercial applications out of your
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1223
    source code.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1224
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1225
 #. The resulting binaries generated by PyInstaller from your source code can be
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1226
    shipped with whatever license you want.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1227
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1228
 #. You may modify PyInstaller for your own needs but *these* changes to the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1229
    PyInstaller source code falls under the terms of the GPL license. In other
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1230
    words, any modifications to will *have* to be distributed under GPL.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1231
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1232
For updated information or clarification see our
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1233
`FAQ <http://pyinstaller.hpcf.upr.edu/pyinstaller/wiki/FAQ>`_ at `PyInstaller`_
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1234
home page: http://pyinstaller.hpcf.upr.edu
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1235
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1236
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1237
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1238
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1239
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1240
Appendix
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1241
++++++++
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1242
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1243
.. sidebar:: You can stop reading here...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1244
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1245
    ... if you are not interested in technical details. This appendix contains
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1246
    insights of the internal workings of |PyInstaller|, and you do not need this
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1247
    information unless you plan to work on |PyInstaller| itself.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1248
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1249
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1250
``mf.py``: A Modulefinder Replacement
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1251
-------------------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1252
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1253
Module ``mf`` is modelled after ``iu``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1254
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1255
It also uses ``ImportDirectors`` and ``Owners`` to partition the import name space.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1256
Except for the fact that these return ``Module`` instances instead of real module
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1257
objects, they are identical.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1258
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1259
Instead of an ``ImportManager``, ``mf`` has an ``ImportTracker`` managing things.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1260
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1261
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1262
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1263
ImportTracker
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1264
*************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1265
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1266
``ImportTracker`` can be called in two ways: ``analyze_one(name, importername=None)``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1267
or ``analyze_r(name, importername=None)``. The second method does what modulefinder
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1268
does - it recursively finds all the module names that importing name would
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1269
cause to appear in ``sys.modules``. The first method is non-recursive. This is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1270
useful, because it is the only way of answering the question "Who imports
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1271
name?" But since it is somewhat unrealistic (very few real imports do not
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1272
involve recursion), it deserves some explanation.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1273
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1274
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1275
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1276
``analyze_one()``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1277
*****************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1278
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1279
When a name is imported, there are structural and dynamic effects. The dynamic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1280
effects are due to the execution of the top-level code in the module (or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1281
modules) that get imported. The structural effects have to do with whether the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1282
import is relative or absolute, and whether the name is a dotted name (if there
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1283
are N dots in the name, then N+1 modules will be imported even without any code
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1284
running).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1285
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1286
The analyze_one method determines the structural effects, and defers the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1287
dynamic effects. For example, ``analyze_one("B.C", "A")`` could return ``["B", "B.C"]``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1288
or ``["A.B", "A.B.C"]`` depending on whether the import turns out to be relative or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1289
absolute. In addition, ImportTracker's modules dict will have Module instances
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1290
for them.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1291
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1292
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1293
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1294
Module Classes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1295
**************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1296
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1297
There are Module subclasses for builtins, extensions, packages and (normal)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1298
modules. Besides the normal module object attributes, they have an attribute
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1299
imports. For packages and normal modules, imports is a list populated by
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1300
scanning the code object (and therefor, the names in this list may be relative
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1301
or absolute names - we don't know until they have been analyzed).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1302
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1303
The highly astute will notice that there is a hole in ``analyze_one()`` here. The
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1304
first thing that happens when ``B.C`` is being imported is that ``B`` is imported and
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1305
it's top-level code executed. That top-level code can do various things so that
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1306
when the import of ``B.C`` finally occurs, something completely different happens
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1307
(from what a structural analysis would predict). But mf can handle this through
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1308
it's hooks mechanism.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1309
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1310
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1311
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1312
code scanning
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1313
*************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1314
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1315
Like modulefinder, ``mf`` scans the byte code of a module, looking for imports. In
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1316
addition, ``mf`` will pick out a module's ``__all__`` attribute, if it is built as a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1317
list of constant names. This means that if a package declares an ``__all__`` list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1318
as a list of names, ImportTracker will track those names if asked to analyze
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1319
``package.*``. The code scan also notes the occurance of ``__import__``, ``exec`` and ``eval``,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1320
and can issue warnings when they're found.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1321
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1322
The code scanning also keeps track (as well as it can) of the context of an
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1323
import. It recognizes when imports are found at the top-level, and when they
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1324
are found inside definitions (deferred imports). Within that, it also tracks
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1325
whether the import is inside a condition (conditional imports).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1326
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1327
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1328
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1329
Hooks
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1330
*****
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1331
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1332
In modulefinder, scanning the code takes the place of executing the code
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1333
object. ``mf`` goes further and allows a module to be hooked (after it has been
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1334
scanned, but before analyze_one is done with it). A hook is a module named
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1335
``hook-fullyqualifiedname`` in the ``hooks`` package. These modules should have one or
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1336
more of the following three global names defined:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1337
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1338
``hiddenimports``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1339
    a list of modules names (relative or absolute) that the module imports in some untrackable way.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1340
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1341
``attrs``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1342
    a list of ``(name, value)`` pairs (where value is normally meaningless).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1343
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1344
``hook(mod)``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1345
    a function taking a ``Module`` instance and returning a ``Module`` instance (so it can modify or replace).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1346
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1347
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1348
The first hook (``hiddenimports``) extends the list created by scanning the code.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1349
``ExtensionModules``, of course, don't get scanned, so this is the only way of
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1350
recording any imports they do.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1351
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1352
The second hook (``attrs``) exists mainly so that ImportTracker won't issue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1353
spurious warnings when the rightmost node in a dotted name turns out to be an
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1354
attribute in a package module, instead of a missing submodule.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1355
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1356
The callable hook exists for things like dynamic modification of a package's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1357
``__path__`` or perverse situations, like ``xml.__init__`` replacing itself in
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1358
``sys.modules`` with ``_xmlplus.__init__``. (It takes nine hook modules to properly
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1359
trace through PyXML-using code, and I can't believe that it's any easier for
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1360
the poor programmer using that package). The ``hook(mod)`` (if it exists) is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1361
called before looking at the others - that way it can, for example, test
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1362
``sys.version`` and adjust what's in ``hiddenimports``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1363
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1364
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1365
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1366
Warnings
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1367
********
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1368
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1369
``ImportTracker`` has a ``getwarnings()`` method that returns all the warnings
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1370
accumulated by the instance, and by the ``Module`` instances in its modules dict.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1371
Generally, it is ``ImportTracker`` who will accumulate the warnings generated
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1372
during the structural phase, and ``Modules`` that will get the warnings generated
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1373
during the code scan.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1374
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1375
Note that by using a hook module, you can silence some particularly tiresome
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1376
warnings, but not all of them.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1377
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1378
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1379
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1380
Cross Reference
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1381
***************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1382
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1383
Once a full analysis (that is, an ``analyze_r`` call) has been done, you can get a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1384
cross reference by using ``getxref()``. This returns a list of tuples. Each tuple
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1385
is ``(modulename, importers)``, where importers is a list of the (fully qualified)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1386
names of the modules importing ``modulename``. Both the returned list and the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1387
importers list are sorted.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1388
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1389
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1390
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1391
Usage
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1392
*****
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1393
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1394
A simple example follows:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1395
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1396
      >>> import mf
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1397
      >>> a = mf.ImportTracker()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1398
      >>> a.analyze_r("os")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1399
      ['os', 'sys', 'posixpath', 'nt', 'stat', 'string', 'strop',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1400
      're', 'pcre', 'ntpath', 'dospath', 'macpath', 'win32api',
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1401
      'UserDict', 'copy', 'types', 'repr', 'tempfile']
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1402
      >>> a.analyze_one("os")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1403
      ['os']
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1404
      >>> a.modules['string'].imports
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1405
      [('strop', 0, 0), ('strop.*', 0, 0), ('re', 1, 1)]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1406
      >>>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1407
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1408
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1409
The tuples in the imports list are (name, delayed, conditional).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1410
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1411
      >>> for w in a.modules['string'].warnings: print w
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1412
      ...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1413
      W: delayed  eval hack detected at line 359
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1414
      W: delayed  eval hack detected at line 389
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1415
      W: delayed  eval hack detected at line 418
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1416
      >>> for w in a.getwarnings(): print w
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1417
      ...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1418
      W: no module named pwd (delayed, conditional import by posixpath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1419
      W: no module named dos (conditional import by os)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1420
      W: no module named os2 (conditional import by os)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1421
      W: no module named posix (conditional import by os)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1422
      W: no module named mac (conditional import by os)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1423
      W: no module named MACFS (delayed, conditional import by tempfile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1424
      W: no module named macfs (delayed, conditional import by tempfile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1425
      W: top-level conditional exec statment detected at line 47
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1426
         - os (C:\Program Files\Python\Lib\os.py)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1427
      W: delayed  eval hack detected at line 359
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1428
         - string (C:\Program Files\Python\Lib\string.py)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1429
      W: delayed  eval hack detected at line 389
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1430
         - string (C:\Program Files\Python\Lib\string.py)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1431
      W: delayed  eval hack detected at line 418
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1432
         - string (C:\Program Files\Python\Lib\string.py)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1433
      >>>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1434
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1435
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1436
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1437
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1438
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1439
.. _iu.py:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1440
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1441
``iu.py``: An *imputil* Replacement
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1442
-----------------------------------
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1443
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1444
Module ``iu`` grows out of the pioneering work that Greg Stein did with ``imputil``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1445
(actually, it includes some verbatim ``imputil`` code, but since Greg didn't
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1446
copyright it, we won't mention it). Both modules can take over Python's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1447
builtin import and ease writing of at least certain kinds of import hooks.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1448
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1449
``iu`` differs from ``imputil``:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1450
* faster
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1451
* better emulation of builtin import
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1452
* more managable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1453
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1454
There is an ``ImportManager`` which provides the replacement for builtin import
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1455
and hides all the semantic complexities of a Python import request from it's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1456
delegates.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1457
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1458
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1459
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1460
``ImportManager``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1461
*****************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1462
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1463
``ImportManager`` formalizes the concept of a metapath. This concept implicitly
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1464
exists in native Python in that builtins and frozen modules are searched
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1465
before ``sys.path``, (on Windows there's also a search of the registry while on
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1466
Mac, resources may be searched). This metapath is a list populated with
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1467
``ImportDirector`` instances. There are ``ImportDirector`` subclasses for builtins,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1468
frozen modules, (on Windows) modules found through the registry and a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1469
``PathImportDirector`` for handling ``sys.path``. For a top-level import (that is, not
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1470
an import of a module in a package), ``ImportManager`` tries each director on it's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1471
metapath until one succeeds.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1472
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1473
``ImportManager`` hides the semantic complexity of an import from the directors.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1474
It's up to the ``ImportManager`` to decide if an import is relative or absolute;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1475
to see if the module has already been imported; to keep ``sys.modules`` up to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1476
date; to handle the fromlist and return the correct module object.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1477
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1478
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1479
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1480
``ImportDirector``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1481
******************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1482
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1483
An ``ImportDirector`` just needs to respond to ``getmod(name)`` by returning a module
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1484
object or ``None``. As you will see, an ``ImportDirector`` can consider name to be
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1485
atomic - it has no need to examine name to see if it is dotted.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1486
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1487
To see how this works, we need to examine the ``PathImportDirector``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1488
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1489
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1490
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1491
``PathImportDirector``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1492
**********************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1493
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1494
The ``PathImportDirector`` subclass manages a list of names - most notably,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1495
``sys.path``. To do so, it maintains a shadowpath - a dictionary mapping the names
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1496
on its pathlist (eg, ``sys.path``) to their associated ``Owners``. (It could do this
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1497
directly, but the assumption that sys.path is occupied solely by strings seems
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1498
ineradicable.) ``Owners`` of the appropriate kind are created as needed (if all
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1499
your imports are satisfied by the first two elements of ``sys.path``, the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1500
``PathImportDirector``'s shadowpath will only have two entries).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1501
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1502
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1503
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1504
``Owner``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1505
*********
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1506
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1507
An ``Owner`` is much like an ``ImportDirector`` but manages a much more concrete piece
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1508
of turf. For example, a ``DirOwner`` manages one directory. Since there are no
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1509
other officially recognized filesystem-like namespaces for importing, that's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1510
all that's included in iu, but it's easy to imagine ``Owners`` for zip files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1511
(and I have one for my own ``.pyz`` archive format) or even URLs.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1512
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1513
As with ``ImportDirectors``, an ``Owner`` just needs to respond to ``getmod(name)`` by
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1514
returning a module object or ``None``, and it can consider name to be atomic.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1515
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1516
So structurally, we have a tree, rooted at the ``ImportManager``. At the next
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1517
level, we have a set of ``ImportDirectors``. At least one of those directors, the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1518
``PathImportDirector`` in charge of ``sys.path``, has another level beneath it,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1519
consisting of ``Owners``. This much of the tree covers the entire top-level import
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1520
namespace.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1521
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1522
The rest of the import namespace is covered by treelets, each rooted in a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1523
package module (an ``__init__.py``).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1524
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1525
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1526
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1527
Packages
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1528
********
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1529
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1530
To make this work, ``Owners`` need to recognize when a module is a package. For a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1531
``DirOwner``, this means that name is a subdirectory which contains an ``__init__.py``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1532
The ``__init__`` module is loaded and its ``__path__`` is initialized with the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1533
subdirectory. Then, a ``PathImportDirector`` is created to manage this ``__path__``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1534
Finally the new ``PathImportDirector``'s ``getmod`` is assigned to the package's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1535
``__importsub__`` function.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1536
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1537
When a module within the package is imported, the request is routed (by the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1538
``ImportManager``) diretly to the package's ``__importsub__``. In a hierarchical
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1539
namespace (like a filesystem), this means that ``__importsub__`` (which is really
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1540
the bound getmod method of a ``PathImportDirector`` instance) needs only the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1541
module name, not the package name or the fully qualified name. And that's
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1542
exactly what it gets. (In a flat namespace - like most archives - it is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1543
perfectly easy to route the request back up the package tree to the archive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1544
``Owner``, qualifying the name at each step.)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1545
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1546
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1547
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1548
Possibilities
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1549
*************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1550
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1551
Let's say we want to import from zip files. So, we subclass ``Owner``. The
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1552
``__init__`` method should take a filename, and raise a ``ValueError`` if the file is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1553
not an acceptable ``.zip`` file, (when a new name is encountered on ``sys.path`` or a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1554
package's ``__path__``, registered Owners are tried until one accepts the name).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1555
The ``getmod`` method would check the zip file's contents and return ``None`` if the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1556
name is not found. Otherwise, it would extract the marshalled code object from
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1557
the zip, create a new module object and perform a bit of initialization (12
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1558
lines of code all told for my own archive format, including initializing a pack
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1559
age with it's ``__subimporter__``).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1560
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1561
Once the new ``Owner`` class is registered with ``iu``, you can put a zip file on
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1562
``sys.path``. A package could even put a zip file on its ``__path__``.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1563
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1564
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1565
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1566
Compatibility
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1567
*************
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1568
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1569
This code has been tested with the PyXML, mxBase and Win32 packages, covering
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1570
over a dozen import hacks from manipulations of ``__path__`` to replacing a module
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1571
in ``sys.modules`` with a different one. Emulation of Python's native import is
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1572
nearly exact, including the names recorded in ``sys.modules`` and module attributes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1573
(packages imported through ``iu`` have an extra attribute - ``__importsub__``).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1574
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1575
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1576
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1577
Performance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1578
***********
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1579
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1580
In most cases, ``iu`` is slower than builtin import (by 15 to 20%) but faster than
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1581
``imputil`` (by 15 to 20%). By inserting archives at the front of ``sys.path``
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1582
containing the standard lib and the package being tested, this can be reduced
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1583
to 5 to 10% slower (or, on my 1.52 box, 10% faster!) than builtin import. A bit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1584
more can be shaved off by manipulating the ``ImportManager``'s metapath.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1585
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1586
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1587
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1588
Limitations
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1589
***********
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1590
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1591
This module makes no attempt to facilitate policy import hacks. It is easy to
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1592
implement certain kinds of policies within a particular domain, but
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1593
fundamentally iu works by dividing up the import namespace into independent
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1594
domains.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1595
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1596
Quite simply, I think cross-domain import hacks are a very bad idea. As author
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1597
of the original package on which |PyInstaller| is based, McMillan worked with
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1598
import hacks for many years. Many of them are highly fragile; they often rely
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1599
on undocumented (maybe even accidental) features of implementation.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1600
A cross-domain import hack is not likely to work with PyXML, for example.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1601
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1602
That rant aside, you can modify ``ImportManger`` to implement different policies.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1603
For example, a version that implements three import primitives: absolute
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1604
import, relative import and recursive-relative import. No idea what the Python
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1605
syntax for those should be, but ``__aimport__``, ``__rimport__`` and ``__rrimport__`` were
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1606
easy to implement.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1607
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1608
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1609
Usage
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1610
*****
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1611
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1612
Here's a simple example of using ``iu`` as a builtin import replacement.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1613
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1614
      >>> import iu
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1615
      >>> iu.ImportManager().install()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1616
      >>>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1617
      >>> import DateTime
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1618
      >>> DateTime.__importsub__
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1619
      <method PathImportDirector.getmod
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1620
        of PathImportDirector instance at 825900>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1621
      >>>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1622
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1623
|GOBACK|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1624
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1625
.. _PyInstaller: http://pyinstaller.hpcf.upr.edu/pyinstaller
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1626
.. _Roadmap: http://pyinstaller.hpcf.upr.edu/pyinstaller/roadmap
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1627
.. _`Submit a Bug`: http://pyinstaller.hpcf.upr.edu/pyinstaller/newticket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1628
.. _Scons: http://www.scons.org
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1629
.. _hooks\/hook-win32com.py: http://pyinstaller.hpcf.upr.edu/pyinstaller/browser/trunk/hooks/hook-win32com.py?rev=latest
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1630
.. _support\/unpackTK.py: http://pyinstaller.hpcf.upr.edu/pyinstaller/browser/trunk/support/unpackTK.py?rev=latest
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1631
.. _source/common/launch.c: http://pyinstaller.hpcf.upr.edu/pyinstaller/browser/trunk/source/common/launch.c?rev=latest
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1632
.. _Pmw: http://pmw.sourceforge.net/
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1633
.. _PIL: http://www.pythonware.com/products/pil/
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1634
.. _PyQt: http://www.riverbankcomputing.co.uk/pyqt/index.php
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1635
.. _PyWin32: http://starship.python.net/crew/mhammond/win32/
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1636
.. |ZlibArchiveImage| image:: images/ZlibArchive.png
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1637
.. |CArchiveImage| image:: images/CArchive.png
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1638
.. |SE_exeImage| image:: images/SE_exe.png
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1639
.. |PyInstaller| replace:: PyInstaller
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1640
.. |PyInstallerVersion| replace:: PyInstaller v1.0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1641
.. |InitialVersion| replace:: v1.0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1642
.. |install_path| replace:: /your/path/to/pyinstaller/
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1643
.. |GOBACK| replace:: `Back to Top`_
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1644
.. _`Back to Top`: `PyInstaller Manual`_