[Python-Dev] Platform extension for distutils on other interpreters than CPython

Tarek Ziadé ziade.tarek at gmail.com
Tue Feb 23 21:10:01 CET 2010


On Tue, Feb 23, 2010 at 2:44 PM, Maciej Fijalkowski <fijall at gmail.com> wrote:
> On Tue, Feb 23, 2010 at 2:27 PM, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
>> On Tue, Feb 23, 2010 at 2:10 PM, Tarek Ziadé <ziade.tarek at gmail.com> wrote:
>>> On Tue, Feb 23, 2010 at 1:50 PM, Maciej Fijalkowski <fijall at gmail.com> wrote:
>>>> Hello.
>>>>
>>>> I would like to have a feature on platform module (or sys or
>>>> somewhere) that can tell distutils or distutils2 that this platform
>>>> (be it PyPy or Jython) is not able to compile any C module. The
>>>> purpose of this is to make distutils bail out in more reasonable
>>>> manner than a compilation error in case this module is not going to
>>>> work on anything but CPython.
>>>>
>>>> What do you think?
>>>
>>> +1
>>>
>>> I think we could have a global variable in sys, called "dont_compile",
>>> distutils would look at
>>> before it tris to compile stuff, exactly like how it does for pyc file
>>> (sys.dont_write_bytecode)
>>
>> Or... wait : we already know if we are using CPython, or Jython
>> reading sys.platform.
>>
>> So I could simply not trigger the compilation in case sys.platform is
>> one of the CPythons
>> and keep in distutils side a list of the platform names, Extension is
>> incompatible with.
>>
>> That makes me wonder : why don't we have a sys.implementation variable ?
>> (cython/jython/pypi), since we can have several values for cython in
>> sys.platform
>>
>>
>> Tarek
>>
>
> That's pypy. pypi is something else. sys.platform is not any good,
> since for example PyPy, and possibly any other python implementation
> that is not CPython, but it's not tied to any particular platform
> (like parrot) would say "linux2" or "win32".
>
> sys.implementation sounds good, but it'll also require a list in
> stdlib what's fine and what's not fine and a flag sounds like
> something that everyone can set, not asking to be listed in stdlib.
>
> How about sys.implementation.supports_extensions?

I think its the other way around:

You are making the assumption that, sys knows about distutils extensions.
and there's no indication about the kind of extension here (C, etc..).

In distutils, the Extension class works with a compiler class
(ccompiler, mingwcompiler, etc)
And in theory, people could add a new compiler that works under PyPy or Jython.

So I think it's up to the Compiler class (through the Extension
instance) to decide if the environment is suitable.

For instance in the CCompiler class I can write things like:

if sys.implementation != 'cython':
    warning.warn('Sorry I cannot compile this under %s' % sys.implementation)

Tarek

-- 
Tarek Ziadé | http://ziade.org


More information about the Python-Dev mailing list