Site Unseen: hidden python customization
- Duration:
- 30 minutes
Abstract
Python offers us the ability to customize how it starts up. In some cases arbitrary python code can get executed before the first line of your module is reached. This is necessary for some of its dynamic nature, like virtualenvs but can also be harnessed to make the interpreter experience truly personal.
Description
Python does a lot of work to customize itself when starting up. It also provides hooks for even more customization from users and packages during startup. Some of these are on by default while others require enabling. Learn how to take advantage of Python's startup to craft a custom interpreter. Python has a dizzying array of environment variables, most of which are used for startup tuning. The list has grown so long that recent Python versions have split the description of these variables into their own help (--help-env). It is valuable to a Pythonista to know about all of these, but this talk will show you how to use a subset to personalize the python runtime environment to your developer needs and preferences. As powerful as this customization is, much of it is possible through arbitrary code execution or otherwise manipulating the expected behavior of lookups. Since many of these behaviors happen automatically, it is important to know how to disable them for many reasons: security, reproducibility, and speed among them.
Outline
- Intro
- The site module
- what is its purpose
- when it gets imported and how it changes python startup
- how to disable site (or just some parts)
- 6 minutes
- pth files
- format of a pth file
- how pths are found
- how they change sys.path
- examples from real, popular, packages
- 5 minutes
- sitecustomize/ usercustomize
- practical examples
- how to disable it
- 4 minutes
- PYTHONSTARTUP
- how it differs from usercustomize and when to use each
- practical examples
- 4 minutes
- PYTHONBREAKPOINT
- how it differs from sys.breakpointhook
- 2 minutes
- further isolation of startup features
- 2 minutes
- Conclusion