Platform-specific compile flags in setup.py?

  • Thread starter Nikita the Spider
  • Start date
N

Nikita the Spider

Hi all,
I'm a newbie when it comes to distributing C-based Python modules. I'm
just now sharing my first with the rest of the world (it's actually V.
Marangozov's shared memory module for IPC) and I've learned that the
module needs a different set of compile flags for Linux than for my Mac.
My question is this: is there a convention or standard that says where
platform-specific compile flags should reside? I could put them in
setup.py, OTOH I know that within the .C file I can add something like
this:
#ifdef __FreeBSD__
#include <machine/param.h> /* for system definition of PAGE_SIZE */
#endif

That works, but for maximum Python programmer-friendliness I should
perhaps put the complexity in setup.py rather than in a .C file.

Opinions appreciated.

PS - The module in question is here; Linux users must remove the tuple
"('HAVE_UNION_SEMUN', None)" from setup.py:
http://NikitaTheSpider.com/python/shm/
 
A

Alex Martelli

Nikita the Spider said:
Hi all,
I'm a newbie when it comes to distributing C-based Python modules. I'm
just now sharing my first with the rest of the world (it's actually V.
Marangozov's shared memory module for IPC) and I've learned that the
module needs a different set of compile flags for Linux than for my Mac.
My question is this: is there a convention or standard that says where
platform-specific compile flags should reside? I could put them in
setup.py,

If you need, specifically, *compile-flags*, then setup.py is a good
place for them (also linker-flags &c).

OTOH I know that within the .C file I can add something like
this:
#ifdef __FreeBSD__
#include <machine/param.h> /* for system definition of PAGE_SIZE */
#endif

This is NOT a "compile-flag" -- it's a reasonable C technique, though.

That works, but for maximum Python programmer-friendliness I should
perhaps put the complexity in setup.py rather than in a .C file.

Opinions appreciated.

My opinion: flags in setup.py, conditional includes (&c) in the .c or .h
file.

If you can do something either way: if you know platform X will ALWAYS
want that something, "hard-code" it in the .c or .h; if you want to make
it easier to change for Python programmers, then put it in the setup.py.


Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top