| Start | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Using source control metadata in setup.py
This example uses both features; to only use SCM metadata for the version, replace the call to |
||||||||||
| Purpose of setup.py The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. It's purpose is the correct installation of the software. If all you want to do is distribute a module called foo, contained in a file foo.py, then your setup script can be as simple as this: To create a source distribution for this module, you would create a setup script, setup.py, containing the above code, and run this command from a terminal: sdist will create an archive file (e.g., tarball on Unix, ZIP file on Windows) containing your setup script setup.py, and your module foo.py. The archive file will be named foo-1.0.tar.gz (or .zip), and will unpack into a directory foo-1.0. If an end-user wishes to install your foo module, all she has to do is download foo-1.0.tar.gz (or .zip), unpack it, and—from the foo-1.0 directory—run |
||||||||||
| Adding command line scripts to your python package Command line scripts inside python packages are common. You can organise your package in such a way that when a user installs the package, the script will be available on their path. If you had the You could run that script by running: However if you would like to run it like so: You can achieve this by adding When you install the greetings package now, Another possibility would be to add an entry point: This way you just have to run it like: |
||||||||||
| Adding installation options As seen in previous examples, basic use of this script is: But there is even more options, like installing the package and have the possibility to change the code and test it without having to re-install it. This is done using: If you want to perform specific actions like compiling a Sphinx documentation or building fortran code, you can create your own option like this:
After that, you will be able to call your option: Parameters
RemarksFor further information on python packaging see: Introduction (opens new window) For writing official packages there is a packaging user guide (opens new window). |
Read Article
https://develop.horje.com/learn/1434/reference