Creating a Python Package Pypi-style
As a part of the workshop we will learn how to create an anaconda
package. For that, we need to understand the structure needed to build a python
package.
Table of contents
Structure of a mini Python package
1 intro2conda
2 |____environment.yml
3 |____README.md
4 |____setup.py
5 |____setup.cfg
6 |____src
7 |____intro2conda
8 |______init__.py
9 |____print.py
Line-by-line:
- Main directory.
- File that helps build a conda environment for the package.
- Description of the package.
- Installation script.
- Installation configuration file that the installation script looks for.
- source code directory
- package directory
- file telling python that
intro2conda/
is a module - single module
Installation
Change the directory to
cd intro2conda
# or
cd /path/to/introduction-to-conda/intro2conda
and either
```bash
python setup.py install [--editable]
or
pip install [-e] .
EDITABLE MODE!
--editable
or -e
allows us to edit the software after installation. Combined with the
%load_ext autoreload
%autoreload 2
at the start of an ipython
command line or jupyter noteboook session makes debugging and developing a breeze. Whenever the code is edited ipython
will now re-import the function or module that as been editing to update the changes.