2

I have the project with such structure:

Project/
    Project/
        __init__.py
        config.py
    setup.py
    .gitignore

config.py contains two variables (LOGIN, PASS) and is added to .gitignore.

I would like to add custom action to setup.py then run python setup.py install than triggered creating config.py with some inputs("Please write your login/pass") prior to installation of package.

How to do it right?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
tibhar940
  • 33
  • 7

1 Answers1

0

It is not a good idea to do any customization at install time. It is good practice to do customization at run time, usually at the start of the first run.

At the start of your program, you should check if login and pass are somehow available. If login and pass are not available, then ask the user to enter them and save the values in a file. Usually such files should be saved in user configuration directory. Typically you would use the platformdirs library to get the right location for such a file.

Something like that:

import pathlib

import platformdirs

user_config_dir = platformdirs.user_config_dir('MyApp', 'tibhar940')
user_config_path = pathlib.Path(user_config_dir, 'config.cfg')

if user_config_path.is_file():
    # read
else:
    # prompt the user and save in file

Related:

sinoroc
  • 18,409
  • 2
  • 39
  • 70