[Python-Dev] PEP 370 and IronPython

Christian Heimes lists at cheimes.de
Fri Oct 9 13:16:37 CEST 2009

Nick Coghlan wrote:
> Christian Heimes wrote:
>> The solution requires a new attribute in the sys module that contains
>> the name of the implementation. As an alternative we could use the first
>> field of sys.subversion but I prefer an explicit attribute. I'm
>> proposing "sys.name" with a value of "CPython", "IronPython", "Jython"
>> or "PyPy".
> My Google skills almost failed me, but searching for "sys.vm" found me
> what I was after: http://bugs.python.org/issue4242 (a discussion
> relating to a similar need in the context of flagging implementation
> specific tests).

Thanks, I knew about the discussion but I didn't know that somebody has
already suggested a sys.vm attribute.

> As mentioned in that discussion, as of Python 2.6, you can do the following:
>>>> import platform
>>>> platform.python_implementation()
> 'CPython'
> (Although according to the function docstring, PyPy is currently missing
> from the list of known implementations)
> Importing yet-another-module for use in site.py doesn't sound like a
> great idea, so it may make sense to migrate that information into the
> sys module is this approach is taken. "sys.name" is a little generic
> though - something more explicit like "sys.vm" would be better.

The platform modules uses additional modules like the re module. On my
system "import platform" loads 7 additional module. The platform modul
also uses multiple function calls and regular expression to detect the
vm. I'm not going to blame the author of the function for the way the
feature is implemented. It's the best way and I'd probably done it the
same way, too. But it's an unnecessary slow down of every interpreter
startup. 'sys.vm' it is.

> Implementation specific user directories sound like a good idea indeed.
> An alternative to a lookup table approach might be to be a little more
> direct and just retrieve the final part of the user specific directory
> name directly from a new function in the sys module. Then different VM
> authors can choose any directory name they want without CPython's
> site.py needing to know anything else about them.

I like your idea. It might be a better idea to turn sys.vm into a struct
like sys.float_info. The struct can contains a set of required
attributes like an id, a capitalized name, the platform (C, .NET, Java)
and the suffix for the user site directory.

>>> sys.vm
sys.vm(id='cpython', name='CPython', platform='C',
usersitesuffix='python26') # on win32: Python2.6

>>> sys.vm
sys.vm(id='ironpython', name='IronPython', platform='.NET',
usersitesuffix='ironpython26) # on win32: IronPython2.6


More information about the Python-Dev mailing list