Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add folder for python customizations: __sitecustomize__ #86820

Open
mariocj89 mannequin opened this issue Dec 16, 2020 · 5 comments
Open

Add folder for python customizations: __sitecustomize__ #86820

mariocj89 mannequin opened this issue Dec 16, 2020 · 5 comments
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@mariocj89
Copy link
Mannequin

mariocj89 mannequin commented Dec 16, 2020

BPO 42654
Nosy @jaraco, @ncoghlan, @stevendaprano, @mariocj89, @FFY00

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-12-16.09:42:43.259>
labels = ['type-feature', 'library', '3.10']
title = 'Add folder for python customizations: __sitecustomize__'
updated_at = <Date 2021-05-24.20:31:53.995>
user = 'https://github.com/mariocj89'

bugs.python.org fields:

activity = <Date 2021-05-24.20:31:53.995>
actor = 'vstinner'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-12-16.09:42:43.259>
creator = 'mariocj89'
dependencies = []
files = []
hgrepos = []
issue_num = 42654
keywords = []
message_count = 5.0
messages = ['383129', '383138', '383139', '383141', '383164']
nosy_count = 5.0
nosy_names = ['jaraco', 'ncoghlan', 'steven.daprano', 'mariocj89', 'FFY00']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue42654'
versions = ['Python 3.10']

@mariocj89
Copy link
Mannequin Author

mariocj89 mannequin commented Dec 16, 2020

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!

@mariocj89 mariocj89 mannequin added 3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Dec 16, 2020
@stevendaprano
Copy link
Member

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?

@mariocj89
Copy link
Mannequin Author

mariocj89 mannequin commented Dec 16, 2020

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.

@stevendaprano
Copy link
Member

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. bpo-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.)

@mariocj89
Copy link
Mannequin Author

mariocj89 mannequin commented Dec 16, 2020

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant