A talk to be given at the Django and Python meetup on 1 Sep 2016
Python is inherently modular, i.e. even basic data types can be considered as objects. Modules extend this idea to allow a program to be thought of as a hierarchy of objects. From a software design point of view, entire Python programs can be turned into modules and be used as such, in whole or in part.
This talk will cover some basics about Python modules as well as the lessons learned from developing Shepherd, a modular tool for controlling a stable of hosts listed in an Ansible inventory file.
A basic knowledge of Python programming would be helpful in understanding this talk, but is not essential.
After viewing this talk, people should expect to be able to design (or rewrite!) their programs and libraries in a highly modular fashion, thereby making documentation, debugging and maintenance easier.
- Introduction
- Background
- Python version disclaimer
- Overview
- Features
- import blah
- from fun import Ren, Stimpy
- Module Semantics
- Implicit namespaces
- sys.path
- $PYTHONPATH
- name
from __future__ import absolute_import
1.from . import helper
1.from .xyz import helper as xyz_helper
- Packages
- Submodules
- init.py
- main.py
- Module contents
- all
- path
- The dir() Function
- Packaging
- Handles Dependencies and Versioning
- https://packaging.python.org/
- Projects
1. Create with help of
setuptools
1. Install locally usingpip
- PyPI is the online archive, formerly known as cheeseshop
- Source Distributions
1. Create using
setuptools
1. Install locally or elsewhere usingpip
1. Publish to PyPI usingtwine
(notsetuptools
) - Package files -- .whl
1. Create using
bdist_wheel
1. Publish to PyPI usingtwine
- Implications
- Microservices
- Gotchas
- Error in import doesn't stop namespace creation
Alastair is a Software Engineer and system administrator by trade. He has a BSc in Computer Science from Curtin University.
His computer-related interests lie in various areas within his trade; suffice to say that he is a "geek of many colours". :) Alastair is a die-hard FOSS user and Linux fan.
He is also a freelancer with his own business. Warpspace IT is a consultancy with a fairly broad focus on the technical side of IT.
TBA