2

I'm currently writing a python program and I want to distribute it to some en users (and developers). I would like to reduce the number of necessary steps to run the program to a minimum.

My use case is relatively simple. I'd like the process/tool/whatever to:

A) Download the list of packages required for the application to work.

B) Run a list of python scripts, sequentially (e.g create database and then run migrations).

I understand that distlib does some of this already. However I find the documentation kind of confusing, there seems to be an API to install scripts, but not one to execute them automatically.

Ideally I would specify a list of scripts, and a list of dependencies and have the program install them automatically.

Demian
  • 372
  • 1
  • 2
  • 9
  • 1
    You may want to read: http://stackoverflow.com/questions/17806485/execute-a-python-script-post-install-using-distutils-setuptools , https://github.com/lupien/pyHegel/blob/master/setup.py – fedepad Feb 12 '17 at 01:20

2 Answers2

1

Maybe the best way to tackle this would be to use make with a Makefile (https://www.gnu.org/software/make/).

Distlib, via the setup.py file, would help you make it more readable by giving names to some python scripts. And you could make use of make target/dependencies system to execute tasks sequentially.

If you want to stick to python, you could also use Luigi (https://luigi.readthedocs.io/en/stable/) but it seems like overkill here.

Zaccharie Ramzi
  • 2,106
  • 1
  • 18
  • 37
0

Ok, so I ended writing my own thing, based on how I wanted the interface to look. The code that installs the application looks like this:

from installtools import setup

scripts = ['create_database.py', 'run_migrations.py']

setup("Shelob", "requirements.txt", scripts)

The full script can be found here: https://gist.github.com/fdemian/808c2b95b4521cd87268235e133c563f

Since PIP doesn't have a public API(and isn't likely to have one in the near future) the script uses the subprocess API to call:

pip install -r [requirements_file_path]

After that, it calls the specified python scripts, one by one. While it is probably not a very robust, as a stopgap solution it seems to do the trick.

Demian
  • 372
  • 1
  • 2
  • 9