Discovering and using setup.py options

Ryan Schmidt ryandesign at macports.org
Wed Nov 7 12:51:50 UTC 2018



On Nov 7, 2018, at 01:32, Ryan Schmidt wrote:

> On Nov 6, 2018, at 17:50, Chris Jones wrote:
> 
>> On 6 Nov 2018, at 11:05 pm, Ryan Schmidt wrote:
>> 
>>> For Python projects that build using a setup.py file, how do I discover what options are available -- what's the equivalent of "./configure --help"? I've tried "python2.7 setup.py --help" and "python2.7 setup.py build --help" which seem to provide only generic help and not help specific to this setup.py file.
>>> 
>>> Once I know what options are available, how do I provide them to setup.py? I've tried adding them to build.args, which gives me an "option not recognized" error.
>>> 
>>> I've tried a couple times in recent days, with setup.py files that, based on my reading of them, provide some custom options that I would like to use, but I can't figure out how to use them. Can anyone help?
>> 
>> Can you post a link to an example of such a file you have been looking at ?
> 
> One example is pyobjc-core.
> 
> https://bitbucket.org/ronaldoussoren/pyobjc/src/default/pyobjc-core/setup.py
> 
> It contains this code:
> 
>    user_options = [
>        ('use-system-libffi=', None, "use the system installation of libffi"),
>        ('deployment-target=', None, "deployment target to use (can also be set using ${MACOSX_DEPLOYMENT_TARGET})"),
>        ('sdk-root=', None, "Path to the SDK to use (can also be set using ${SDKROOT})"),
>    ]
> 
> I assume this means that somehow I should be able to specify the SDK. Yes, I could set the SDKROOT environment variable, but that's described as "also"; that implies there's another way, somehow related to the string "sdk-root=", which I would like to understand.
> 
> https://trac.macports.org/ticket/53173

Ok I found some insight in the pyobjc-core changelog which documented how to use this feature when it was added:

https://pythonhosted.org/pyobjc/core/changelog.html

> • The build of pyobjc-core can now be configured by editing setup.cfg (or providing arguments to the build_ext command), instead of editing the setup.py file.
> 
> Currently the following options are availabel for the build_ext command:
> 
> 	• --use-system-libffi: When this option is used the build will use /usr/lib/libffi.dylib instead of the embedded copy of libffi. The latter is the default is and is better tested.
> 	• --deployment-target=VAL: The value of MACOSX_DEPLOYMENT_TARGET to use, defaults to the deployment target used for building Python itself
> 	• --sdk-root=VAL: Path to the SDK root used to build PyObjC, or “python” to use the default SDK selected by distutils. The default is to use the most recent SDK available.


Turns out these are options for the build_ext command, not the build command. And knowing that, I can now see them described in the help:


$ python2.7 setup.py build_ext --help
Common commands: (see '--help-commands' for more)

  setup.py build      will build the package underneath 'build/'
  setup.py install    will install the package

Global options:
  --verbose (-v)  run verbosely (default)
  --quiet (-q)    run quietly (turns verbosity off)
  --dry-run (-n)  don't actually do anything
  --help (-h)     show detailed help message
  --no-user-cfg   ignore pydistutils.cfg in your home directory

Options for 'oc_build_ext' command:
  --use-system-libffi  use the system installation of libffi
  --deployment-target  deployment target to use (can also be set using
                       ${MACOSX_DEPLOYMENT_TARGET})
  --sdk-root           Path to the SDK to use (can also be set using
                       ${SDKROOT})
  --help-compiler      list available compilers

usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help


But MacPorts uses the build command, not the build_ext command. I'm guessing build_ext is one of the commands that build runs internally. So I either have to use the build_ext command directly, or I have to edit setup.cfg.

Other than by reading project-specific documentation, I'm not sure how I could have discovered that this build_ext subcommand that we don't use directly had these options available. So I'm still looking for the equivalent of "./configure --help" that shows all the available options, regardless of what subcommand they might apply to.


> Another is pyopencl.
> 
> https://github.com/inducer/pyopencl/blob/master/setup.py
> 
> It contains these lines:
> 
> 
>        StringListOption("CXXFLAGS", default_cxxflags,
>            help="Any extra C++ compiler options to include"),
>        StringListOption("LDFLAGS", default_ldflags,
>            help="Any extra linker options to include"),
> 
> I assume this means I can somehow supply CXXFLAGS and LDFLAGS, but I can't figure out how.
> 
> https://trac.macports.org/ticket/57520

Haven't figured this one out yet.


> Both of these examples include help strings. I assume there is some command I could run that would print all the available options along with their help strings. I would like to know what that command is.



More information about the macports-dev mailing list