Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python setup.py: ask for configuration data during setup

I package my Python application with PIP, providing a setup.py. During installation, I want to ask the user for several values (user name, other configuration values), these values are then saved inside the application configfile stored inside the user directory.

Is there a special PIP/distutils-way to ask for these configuration values during setup? Or should I just use input to ask the user, like this:

#!/usr/bin/env python

from distutils.core import setup

cfg['name'] = input("Please your username:")
cfg.save()

setup(name='appname',
      version='1.0',
      description='App Description',
      author='Author',
      author_email='[email protected]',
      packages=['mypackage'],
     )

Or should I leave out asking for these values, and instead let the user configure the application on the first start?

I know that all of these ways are possible, but are there any conventions or best practices for that? Or do you know of a popular Python project doing similar stuff which is a good example?

like image 731
Wolkenarchitekt Avatar asked Feb 10 '12 13:02

Wolkenarchitekt


People also ask

What should setup py contain?

The setup.py file may be the most significant file that should be placed at the root of the Python project directory. It primarily serves two purposes: It includes choices and metadata about the program, such as the package name, version, author, license, minimal dependencies, entry points, data files, and so on.

Should I use requirements TXT or setup py?

The short answer is that requirements. txt is for listing package requirements only. setup.py on the other hand is more like an installation script. If you don't plan on installing the python code, typically you would only need requirements.

How do I set Python version in setup py?

from setuptools import setup [...] setup(name="my_package_name", python_requires='>3.5. 2', [...] Note that this requires setuptools>=24.2.


1 Answers

setup.py provides you very primitive interface to install python packages. You can use a config file or create some GUI installer for your application.

Another way is to build OS depended packages (deb, rpm, msi for Windows) for your application.

like image 99
Ivan Kolodyazhny Avatar answered Sep 22 '22 23:09

Ivan Kolodyazhny