1

Is it possible to use dynamic configuration in a setup.py?

I have a python app which is a collection of scripts to make requests to a backend api. I would like to dynamically customise the scripts which are installed, possibly by passing a flag to the pip install command.

An example setup.py

from setuptools import setup, find_packages
setup(
  name='my-app',
  version='0.0.1',
  packages=find_packages(),
  scripts=['bin/do_stuff',
           'bin/do_other_stuff'
  ],
)

I would like to dynamically modify the contents of 'scripts', to add additional paths, based on an install flag.

Is this possible?

1 Answer 1

1

pip allows to pass non-standard parameters to setup.py via --install-option but you have to remove the param from sys.argv before calling setup(). So you best be is to pass additional info via environment variables:

MY_EXTRA_INFO=add_script pip install

Get the var in setup.py:

if 'MY_EXTRA_INFO' in os.environ:
    add_scripts = ['bin/add_script']
else:
    add_scripts = []

setup(
  scripts=['bin/do_stuff',
           'bin/do_other_stuff'
  ] + add_scripts,
)
Sign up to request clarification or add additional context in comments.

2 Comments

Great, thanks - and how can I pass the condition to pip install
I extended the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.