Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why run setup.py, can I just embed the code?

Tags:

python

I am writing a CLI python application that has dependencies on a few libraries (Paramiko etc.). If I download their source and just place them under my main application source, I can import them and everything works just fine. Why would I ever need to run their setup.py installers or deal with python package managers?

I understand that when deploying server side applications it is OK for an admin to run easy_install/pip commands etc to install the prerequsites, but for a script like CLI apps that have to be distributed as a self-contained apps that only depend on a python binary, what is the recommented approach?

like image 734
Ivan Avatar asked Jan 19 '26 20:01

Ivan


1 Answers

Several reasons:

  • Not all packages are pure-python packages. It's easy to include C-extensions in your package and have setup.py automate the compilation process.

  • Automated dependency management; dependencies are declared and installed for you by the installer tools (pip, easy_install, zc.buildout). Dependencies can be declared dynamically too (try to import json, if that fails, declare a dependency on simplejson, etc.).

  • Custom resource installation setups. The installation process is highly configurable and dynamic. The same goes for dependency detection; the cx_Oracle has to jump through quite some hoops to make installation straightforward with all the various platforms and quirks of the Oracle library distribution options it needs to support, for example.

Why would you still want to do this for CLI scripts? That depends on how crucial the CLI is to you; will you be maintaining this over the coming years? Then I'd still use a setup.py, because it documents what the dependencies are, including minimal version needs. You can add tests (python setup.py test), and deploy to new locations or upgrade dependencies with ease.

like image 105
Martijn Pieters Avatar answered Jan 22 '26 10:01

Martijn Pieters