2

How to pass custom key-value pairs in setup() parameters? I need them for a custom build_scripts step.

from distutils.core import setup

from somescripts import build_scripts

setup(name='somescripts',
      version=__version__,
      cmdclass= {
                 'build_scripts': build_scripts,
                 },
      custom_pairs={
          'compile_modules': True,
          'use_scons': True,
          'modules': [f for f in glob('scripts/[!_]*.spy')],
      },
)

This gives "UserWarning: Unknown distribution option" in setup.py install (which turns into error with --strict)

c:\python27\Lib\distutils\dist.py:267: UserWarning: Unknown distribution
 option: 'custom_pairs'
warnings.warn(msg)

UPDATE:

  • distutils doesn't call build_scripts at all if scripts kwarg is empty
4
  • IIRC you should use them directly as parameters in setup() call, not packed into a dict. Commented Jan 10, 2016 at 9:57
  • @Lav they will still all be Unknown distribution option Commented Jan 10, 2016 at 10:00
  • Hmm, actually where did you find these options? I don't have a lot of experience with distutils, but I've checked reference for distutils and setuptools, as well as their source codes, and can't find these options anywhere. Commented Jan 10, 2016 at 10:15
  • @Lav the question is about the need I had to pass the params, and it is not necessary that distutils supported that at the moment. Probably it still does not, so it is about hacking distutils to get the thing done. Commented Nov 6, 2018 at 8:33

1 Answer 1

1

Found the way myself.

from distutils.command.build_scripts import build_scripts as base
from distutils.core import setup

# patch distutils so that it won't skip "build_scripts"
# step if `scripts` list is empty
from distutils.dist import Distribution
def custom_has_scripts(self):
    return True
Distribution.has_scripts = custom_has_scripts

class build_scripts(base):
    def initialize_options(self):
        self.compile_modules = None
        self.use_scons = None
        self.modules = None
    def run(self):
        for module in self.modules:
            # generate scripts
            pass

setup(name='somescripts',
      version=__version__,
      cmdclass= {
                 'build_scripts': build_scripts,
                 },
      options={
          'build_scripts':{
              'compile_modules': True,
              'use_scons': True,
              'modules': [f for f in glob('scripts/[!_]*.spy')],
          },
      },
)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.