11.3. Embedded Python Interpreter¶
11.3.1. Version¶
The embedded Python3 interpreter is a vanilla version of CPython, the
official 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)]'
11.3.2. Modifications¶
There are some modifications made by Keypirinha that impact the default behavior of Python. All of these modifications are documented in this section.
11.3.2.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.
11.3.2.2. os.environ¶
In short: Keypirinha automatically updates the content of the
os.environ map every time an environment variable has been modified.
Context: Keypirinha has been designed to dynamically adapt as much as possible to any modification made to its running context. That includes the environment variables.
Problem: In the CPython implementation, 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
consequence, a plugin that receives the EVENTS message (see
keypirinha.Plugin.on_events()) and wants to get the up-to-date value of
an environment variable would not be able to do so easily with the default
implementation.
Solution: When Keypirinha catches a system notification indicating a
modification to the environment, it updates the environment block associated to
the current process, then finally refreshes the os.environ map. This
mechanism is totally transparent to the plugins and updated environment values
can be just read the standard way: either by accessing the os.environ
map or by calling os.getenv().