Issue 10089: Add support for arbitrary -X options
Created on 2010-10-13 19:01 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| xopts.patch | pitrou, 2010-10-13 19:01 | |||
| xopts2.patch | pitrou, 2010-10-16 18:39 | |||
| xopts3.patch | pitrou, 2010-10-20 15:53 | |||
| Messages (13) | |||
|---|---|---|---|
| msg118563 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-10-13 19:01 | |
It can be useful to enable or disable global Python features based on command-line flags. The -X is supposed to allow implementation-specific options but it is currently disabled for CPython. This patch allows to use -X for arbitrary options in CPython. These options are not validated but minimally parsed and fed into a dictionary, sys.xoptions. An example is better than a thousand words:
$ ./python -c "import sys; print(sys.xoptions)"
{}
$ ./python -Xa,b=c,d -Xe,f=g=h -c "import sys; print(sys.xoptions)"
{'a': True, 'b': 'c', 'e': True, 'd': True, 'f': 'g=h'}
This could be useful for various debug enablers, such as Victor's SIGSEGV handler, warnings about unclosed files, etc.
|
|||
| msg118579 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-10-13 20:22 | |
See issue10093 for a possible use case. |
|||
| msg118729 - (view) | Author: Éric Araujo (eric.araujo) * ![]() |
Date: 2010-10-14 22:53 | |
Seems like a good idea to me. Would other VMs have to implement sys.xoptions too? |
|||
| msg118730 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-10-14 22:55 | |
> Seems like a good idea to me. Would other VMs have to implement sys.xoptions too? I don't think we should mandate that, no. |
|||
| msg118745 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * ![]() |
Date: 2010-10-15 07:11 | |
Why wouldn't they? A standard way to extend the command line options seems useful in all environments. Now the interpretation of these options are subject to variations of course... |
|||
| msg118746 - (view) | Author: Senthil Kumaran (orsenthil) * ![]() |
Date: 2010-10-15 07:18 | |
On Wed, Oct 13, 2010 at 07:01:40PM +0000, Antoine Pitrou wrote:
> $ ./python -Xa,b=c,d -Xe,f=g=h -c "import sys; print(sys.xoptions)"
> {'a': True, 'b': 'c', 'e': True, 'd': True, 'f': 'g=h'}
Docs should be updated too. I see that the values could either be True
or a string? Would this be perceived as a limitation?
|
|||
| msg118748 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * ![]() |
Date: 2010-10-15 07:29 | |
Well, the syntax allows to pass either a string value (because it's a substring of the command line), or nothing.
When no value is passed, True seems better than None, because this allows the usage of the get() method::
x = sys.xoptions.get('a')
or::
if sys.xoptions.get('a'):
this returns None if the option was not set, True if set to a empty value, and a non-empty string if set to an actual value.
|
|||
| msg118752 - (view) | Author: Alyssa Coghlan (ncoghlan) * ![]() |
Date: 2010-10-15 09:04 | |
I suggest using sys._xoptions to make it clearer that this is for CPython specific internal implementation runtime tweaks. We're putting it in sys so *we* can get at it, not applications. (It also makes it clear that other implementations aren't obliged to implement *any* particular interface to the -X options. Requiring that would go against the whole spirit of -X) |
|||
| msg118757 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-10-15 10:22 | |
> (It also makes it clear that other implementations aren't obliged to > implement *any* particular interface to the -X options. Requiring that > would go against the whole spirit of -X) Agreed. I'll update the patch to use sys._xoptions. |
|||
| msg118879 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-10-16 18:39 | |
Here is a new patch renaming the attribute to sys._xoptions, and adding some docs. |
|||
| msg118887 - (view) | Author: Georg Brandl (georg.brandl) * ![]() |
Date: 2010-10-16 19:39 | |
I'd prefer "-X key[=val]" without the possibility to mention multiple key=val pairs, so that val can contain anything (commata in particular). Otherwise, the change looks fine to me. |
|||
| msg119218 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-10-20 15:53 | |
Here is a simpler version without comma-separated pairs. |
|||
| msg119294 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2010-10-21 13:42 | |
Committed in r85772. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:57:07 | admin | set | github: 54298 |
| 2010-10-21 13:42:42 | pitrou | set | status: open -> closed resolution: fixed messages: + msg119294 stage: patch review -> resolved |
| 2010-10-20 15:53:06 | pitrou | set | files:
+ xopts3.patch messages: + msg119218 |
| 2010-10-16 19:39:21 | georg.brandl | set | nosy:
+ georg.brandl messages: + msg118887 |
| 2010-10-16 18:39:24 | pitrou | set | files:
+ xopts2.patch messages: + msg118879 |
| 2010-10-15 10:22:00 | pitrou | set | messages: + msg118757 |
| 2010-10-15 09:04:28 | ncoghlan | set | messages: + msg118752 |
| 2010-10-15 07:29:28 | amaury.forgeotdarc | set | messages: + msg118748 |
| 2010-10-15 07:18:20 | orsenthil | set | nosy:
+ orsenthil messages: + msg118746 |
| 2010-10-15 07:11:50 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages: + msg118745 |
| 2010-10-14 22:55:01 | pitrou | set | messages: + msg118730 |
| 2010-10-14 22:53:08 | eric.araujo | set | nosy:
+ eric.araujo messages: + msg118729 |
| 2010-10-13 20:22:43 | pitrou | set | messages: + msg118579 |
| 2010-10-13 19:01:38 | pitrou | create | |
