classification
Title: Add folder for python customizations: __sitecustomize__
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: FFY00, jaraco, mariocj89, ncoghlan, steven.daprano
Priority: normal Keywords:

Created on 2020-12-16 09:42 by mariocj89, last changed 2021-05-24 20:31 by vstinner.

Messages (5)
msg383129 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2020-12-16 09:42
Following the conversations in https://bugs.python.org/issue33944, wanted to discuss the support for a __sitecustomize__ folder that will hold python scripts to be executed at startup. Similar to `sitecustomize.py` but allowing different stakeholders of a Python installation to add themselves.

This is basically a "supported way" of the current abuse of pth files to add startup code.

How will this be useful?
- Support administrators to add multiple "sitecustomize.py" files. As an example, today we are basically appending to sitecustomize when we need some additional behaviour.
- Support for library owners that need some startup customization like betterexceptions.
- Tools that include an interpreter like virtualenv or things like PyOxidizer by allowing them to customize the interpreter they expose to users.

It basically offers a better alternative to the currently abused feature of code execution in pth.

I this is something that is wanted in CPython, from the thread in https://bugs.python.org/issue33944 I see some open questions though:

- Look for `__sitecustomize__` only in site paths or in PYTHONPATH?
I'm honestly fine either way, but sightly incline more to @jaraco proposal to make this basically be a namespace package walking all its instances.

- Should we have a custom way to disable this? Or are we happy with just  `-S`. I think the `-S` is fine, it offers a similar behaviour to sitecustomize.

If you want to see "how it feels", see https://github.com/mariocj89/cpython/tree/pu/__sitecustomize__ (It's not finished).

If it seems interesting I would love to put a PR through. With this, we might be able to eventually remove code execution in pth files!
msg383138 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-12-16 10:18
Shouldn't this be discussed on Python-Ideas? I'm pretty sure this is a big enough change that it will need a PEP.

If you need code run on startup, can't you just put it in the PYTHONSTARTUP file?
msg383139 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2020-12-16 10:22
> Shouldn't this be discussed on Python-Ideas? I'm pretty sure this is a big enough change that it will need a PEP.

Indeed, I wanted to see if there was interest in the feature. That is probably a better place to start.

> If you need code run on startup, can't you just put it in the PYTHONSTARTUP file?

My understanding is that PYTHONSTARTUP is only for interactive executions. Additionally, it suffers from the same issue as sitecustomize. It is a single file that won't be a real substitute for code execution in pth files.
msg383141 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-12-16 10:30
> Additionally, it suffers from the same issue as 
> sitecustomize. It is a single file that won't be a real substitute for 
> code execution in pth files.

I thought that the consensus in b.p.o. #33944 is that code execution in 
pth files is an anti-feature that must be removed, not something to 
merely move into a new file type or location.

(I may be wrong, I'll admit I haven't read the entire thread in 33944.)
msg383164 - (view) Author: Mario Corchero (mariocj89) * (Python triager) Date: 2020-12-16 12:59
Thread open in Python ideas: https://discuss.python.org/t/add-folder-for-python-customizations-sitecustomize/6190/5
History
Date User Action Args
2021-05-24 20:31:53vstinnersetnosy: - vstinner
2021-05-24 18:34:07FFY00setnosy: + FFY00
2020-12-16 12:59:41mariocj89setmessages: + msg383164
2020-12-16 10:30:33steven.dapranosetmessages: + msg383141
2020-12-16 10:22:24mariocj89setmessages: + msg383139
2020-12-16 10:18:44steven.dapranosetnosy: + steven.daprano
messages: + msg383138
2020-12-16 09:44:04vstinnersetnosy: + vstinner
2020-12-16 09:43:32mariocj89settype: enhancement
2020-12-16 09:42:43mariocj89create