<type>documentation</type>
<domain>edit</domain>
<id>how-analysis-works</id>
<title>How Analysis Works</title>
<date>$Date: 2007-02-09 12:04:39 -0500 (Fri, 09 Feb 2007) $</date>
<version>$Revision: 14785 $</version>
<product>all</product>

To analyze your source code, Wing uses the ``Python Executable`` and ``Python Path`` that
~~~if WING101:
you have specified using ``Configure Python`` in the ``Edit`` menu.
~~~
~~~if not WING101:
you have specified in your `Project Properties <ref:proj/project-properties>`__ and
any `main entry point <ref:debug/main-entry-point>`__.
~~~
This environment defines which modules are found by ``import`` statements and alters some
aspects of type inference, according to Python version.

~~~if WEBSITE:
**Note:** In Wing 101, which which does not have projects, the Python environment is
instead configured with ``Configure Python`` in the ``Edit`` menu.
~~~

~~~if not WING101: 
``Show Analysis Stats`` in the ``Source`` menu displays the Python environment that is
being used for source code analysis. 


Note that this environment is used to analyze *all* files in your project, even if some of
them use `Launch Configurations <ref:proj/launch-configs>`__ or `File Properties
<ref:proj/file-properties>`__ to set up a different Python environment for
themselves. This is usually OK, but in some cases it may be better to set up a separate 
project for each Python environment. 
~~~

Wing's source code analysis process can be summarized as follows:

* To resolve an ``import`` statement, Wing searches the ``Python Path`` and same directory 
  for a matching importable module.
* If the module is Python code, Wing runs static analysis on the code to extract
  information from it.
* If the module is an extension module, Wing looks for a ``*.pi`` or ``*.pyi`` interface
  description file, as described later in this chapter.
* If the module cannot be inspected, Wing tries to import it in a separate process space,
  in order to analyze its contents.
* If a debug process is active, or when working in the `Python Shell
  <ref:debug/python-shell>`__, Wing tries to read relevant type information 
  from the live runtime state associated with the source code
  
The results of this analysis are `cached on disk <ref:edit/analysis-disk-cache>`__ and
recomputed only as necessary when the Python environment or code changes.

