13.3. Embedded Python Interpreter

13.3.1. Version

The embedded Python3 interpreter is a vanilla version of CPython (the official Python distribution). The Python environment you get in Keypirinha is pretty similar to the original one except that some modules have been removed from the standard library: distutils, ensurepip, idlelib, lib2to3 and tkinter.

The exact version number of the application and the interpreter can be read at the beginning of the log in the Console. Or by typing the following commands in the Console window:

>>> import sys
>>> sys.version
'3.5.0 (default, Oct 18 2015, 16:49:14) [MSC v.1800 64 bit (AMD64)]'

13.3.2. Non-Debug

When started, Keypirinha initializes the embedded Python interpreter and enables its optimize flag. This is equivalent to running the standard Python command with the -O option.

As a result, the __debug__ constant is false and assert statements are not executed.

13.3.3. Modifications

There are some modifications made by Keypirinha that impact the default behavior of Python. All of these modifications are documented in this section.

13.3.3.1. exit() and quit()

In its vanilla version, Python offers numerous ways to exit a program. Keypirinha on the other hand is not meant to be shutdown by its plugins and would crash in that case so traps have been installed to avoid that.

As a result, if a plugin calls one of the exit or quit standard functions like sys.exit() or _thread.exit(), directly or indirectly, a NotImplementedError exception is raised instead of the program being shutdown.

As a side note, may the plugin developer absolutely wishes to crash the application anyway, Python and Keypirinha both offer numerous ways to do that too.

13.3.3.2. os.environ

In the Python implementation that Keypirinha embeds, the os.environ map is created at import time and never updated. The os.getenv() function does not help here because it is just a wrapper around os.environ.get().

As a result, a Keypirinha plugin would not be able to read up-to-date environment variables except by requesting the Windows API which is quite tedious in this case.

Keypirinha solves this issue by automatically updating os.environ every time an environment variable has been modified so the plugins always get up-to-date values.