Python training UGA 2017

A training to acquire strong basis in Python to use it efficiently

Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTERRE), Christophe Picard (LJK)

Practical 2: packaging, argparse, Numpy and Matplotlib

Let's write your own package with a command line tool!

Goal

The goal of this session is produce a small package providing a command line application to show images of raccoons.

You will have to organise your code in different files in a package.

A template projet folder is provided (TP/TP2_package/mypackuga). Let's first analyze its content.

There are 1 folder (mypackuga) and 4 files:

  • README.rst

    This file is writen in the markup language "restructuredtext". It should contain a description of the package and instructions how to install it.

  • LICENSE.txt

    This file is important! Don't forget it in your project. It contains the license.

  • setup.cfg

    This file contains information on the package (its name, the version, a short description, ...)

  • setup.py

    This is the file to be executed to install the project.

The directory mypackuga is the package. It contains the code.

Installation

Install the package with:

cd TP/TP2_package/mypackuga
cat README.rst
python setup.py develop

The command line utility mypackuga-raccoon should be available. Try it!

# to get the help
mypackuga-raccoon -h
# to call the program
mypackuga-raccoon
# to see where is the corresponding file
which mypackuga-raccoon

Documentation of the package

  • File README.rst or README.md

  • Directory doc in the root directory

  • Documentation mainly written in the code (in docstrings)

  • Automatically generated with the tool Sphinx

  • Readthedocs

Analyze the content of the code

Read the content of the files. Try to understand what is written.

Modify the package.

Modify the code to use your functions (written during the previous exercices) from the command line tool. Try to plot figures. Use more than one file and import statements,