[PATCH 0 of 2] setup: don't build inotify extension when <sys/inotify.h> is too old

Renato Cunha renatoc at gmail.com
Mon Jun 21 14:49:36 CDT 2010


Hi!

On Mon, Jun 21, 2010 at 09:53:08AM +0200, Christian Boos wrote:
> Here's a new patch, which ignore failures to build extensions marked
> as optional (so only inotify currently), in the same way distutils
> does it in Python 3.
> 
> Here's the code for build_ext.build_extensions() in Python 2.x:
> 
>     def build_extensions(self):
>         # First, sanity-check the 'extensions' list
>         self.check_extensions_list(self.extensions)
> 
>         for ext in self.extensions:
>             self.build_extension(ext)
> 
> Here's the corresponding method in Python 3.x versions:
> 
>     def build_extensions(self):
>         # First, sanity-check the 'extensions' list
>         self.check_extensions_list(self.extensions)
> 
>         for ext in self.extensions:
>             try:
>                 self.build_extension(ext)
>             except (CCompilerError, DistutilsError, CompileError) as e:
>                 if not ext.optional:
>                     raise
>                 self.warn('building extension "%s" failed: %s' %
>                           (ext.name, e))
> 
> So I added something similar in setup.py.

I like the latter solution, I was willing to implement something similar. Good
thing you checked it out before me. :)

> @@ -209,6 +211,20 @@
>  Distribution.global_options.append(('pure', None, "use pure (slow)
> Python "
>                                      "code instead of C extensions"))
> 
> +class hgbuildext(build_ext):
> +
> +    def build_extensions(self):
> +        # First, sanity-check the 'extensions' list
> +        self.check_extensions_list(self.extensions)
> +
> +        for ext in self.extensions:
> +            try:
> +                self.build_extension(ext)
> +            except CCompilerError:
> +                if not hasattr(ext, 'optional') or not ext.optional:
> +                    raise
> +                print>>sys.stderr, "Skipping optional '%s'" % ext.name

That lone raise isn't very nice. Perhaps a
raise SystemExit("Failed to build non-optional extension: %s." % ext.nam)
would've been better...

> @@ -260,6 +277,7 @@
>      if hasfunction(cc, 'inotify_add_watch'):
>          extmodules.append(Extension('hgext.inotify.linux._inotify',
>                                       ['hgext/inotify/linux/_inotify.c']))
> +        extmodules[-1].optional = True
>          packages.extend(['hgext.inotify', 'hgext.inotify.linux'])

What about:

inotify = Extension('hgext.inotify.linux._inotify', ...)
inotify.optional = True
extmodules.append(inotify)

Don't know, but makes the thing a bit more readable.

Regards,
-- 
Renato Cunha <http://renatocunha.com>
Blog: http://valedotrovao.com
"Do, or do not. There is no 'try'".
              -- Jedi Master Yoda


More information about the Mercurial-devel mailing list