# Is there a duck-typing way to know we can't compile extensions?

Issue #80 resolved
Zooko O'Whielacronx created an issue

Is there a duck-typing way to know we can't compile extensions?

Yes! You try to build the extension and if it fails then you automatically fall back to using your pure-Python alternative. This way install will also succeed on a system without a C compiler, for example.

The example code that I crib from whenever I'm going to use this hack is simplejson:

http://simplejson.googlecode.com/svn/trunk/setup.py

Comments (17)

  1. Ned Batchelder repo owner

    I'm experimenting with this code:

    try:
        setup(**setup_args)
    except:
        del setup_args['ext_modules']
        setup(**setup_args)
    

    It works, but might be a bit over-zealous in catching exceptions. The simplejson code catches BuildFailed, but I find on Windows that when I can't install the extension, it fails with ValueError:

    ...
      File "c:\python26\Lib\distutils\msvc9compiler.py", line 458, in compile
        self.initialize()
      File "c:\python26\Lib\distutils\msvc9compiler.py", line 368, in initialize
        vc_env = query_vcvarsall(VERSION, plat_spec)
      File "c:\python26\Lib\distutils\msvc9compiler.py", line 284, in query_vcvarsall
        raise ValueError(str(list(result.keys())))
    ValueError: [u'path']
    
  2. Ned Batchelder repo owner

    Oops, sorry, just read further into the simplejson code, it throws its own BuildFailed error. I'll look into using its technique.

  3. Domen Kožar

    I'm afraid zc.buildout doesn't pass "install" to setup.py, taking the route sqlalchemy does would stop such issues.

  4. Ned Batchelder repo owner

    Domen, thanks for the extra information. I'm afraid I've never used zc.buildout, can you provide very detailed instructions on how to reproduce this? You mention zc.buildout doesn't pass "install" to setup.py, how can that be right? Maybe I don't understand what this is all meant to accomplish. I don't see how the sqlalchemy code gets around not having a verb passed to it.

  5. Ned Batchelder repo owner

    I would accept a pull request, provided I could understand it, and it supported Py2.3 - Py3.3, and worked on Windows, Linux, and Mac. This part of the setup.py doesn't have automated tests, but some guidance on how to make sure it keeps working would be good too.

  6. Ned Batchelder repo owner
    • changed status to open

    Hmm, I have a complaint that 3.5.3 fails where 3.5.2 worked. Maybe simplejson's way is the way to go.

  7. Log in to comment