Fixing Python setup.py

I had been using setup.y to build some external modules for Python on z/OS. Unfortunately deep down in the configuration, the wrong parameters were being used, and I was unable to fix the problem.

Thanks to Steven Pitman who gave me a bypass.

By overriding the build_ext function I was able to remove the unwanted compiler options. I wanted to remove the -fno-strict-aliasing and ‘-Wa,xplink’ options.

You can do it with

if '-fno-strict-aliasing' in self.compiler.compiler_so: 
       self.compiler.compiler_so.remove('-fno-strict-aliasing') 

As shown in the code below. The extra code is in the bold font.

The code cmdclass = {‘build_ext’: BuildExt}, causes my function to be executed.

import setuptools 
from setuptools import setup, Extension 
import sysconfig 
import os 
import sysconfig 
import os 
os.environ['_C89_CCMODE'] = '1' 
from setuptools.command.build_ext import build_ext 
from setuptools import setup 
class BuildExt(build_ext): 
   def build_extensions(self): 
     print(self.compiler.compiler_so) 
     if '-fno-strict-aliasing' in self.compiler.compiler_so: 
       self.compiler.compiler_so.remove('-fno-strict-aliasing') 
     if '-Wa,xplink' in self.compiler.compiler_so: 
        self.compiler.compiler_so.remove('-Wa,xplink') 
     super().build_extensions() 
...
setup(name = 'console', 
   ...
   cmdclass = {'build_ext': BuildExt},
   ext_modules = [Extension('console.zconsole',['console.c'],
   ... 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s