[Python-Dev] PEP 370 and IronPython

Nick Coghlan ncoghlan at gmail.com
Thu Oct 8 14:22:00 CEST 2009


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

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 site module uses the information of the attribute to
> modify the path to the user site directory.

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.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-Dev mailing list