2. Building Highly Complex Systems
Many pieces acting as one
Image by Alan_D from Crawley, United Kingdom - Nissan GTR Cutaway, CC BY 2.0, https://commons.wikimedia.org/w/index.php?curid=18072247
3. Building Open Source Business Systems
Using what you can find to build what you need
Image byy Mick from England (Go Kart Buggy) [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons
4. Python Tools
Core tools for dependency management in
Python
Image by Alexander Baxevanis (Flickr: Cooper's tools) [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons
7. Setuptools – Project Dependency Tool
Defines package information: name, version, authors, etc.
Defines package and test dependency requirements for project source
Should define as wide a range as possible for dependency versions
Builds distributions
Publishes distributions to PyPI
Defines scripts to install as binaries
Provides runtime support for C modules
Can be used for test bootstrapping
11. PIP Requirements File
Overview
Contains information for repeatable
installs
Can include command line options
Can use a constraints file for multi-project
dependency version overrides. Helpful for
using patched forks
Can be built with the freeze command
Example
--index-url=https://my-pypi.example.com
pycrypto==2.6.1
requests==2.10.0
six==1.10.0
12. PIP Freeze
$ pip freeze > requirements.txt
cat requirements.txt
launchkey-python==1.3.0
pycrypto==2.6.1
requests==2.10.0
six==1.10.0
Use the PIP freeze command to
generate a requirements file
based on the currently installed
versions.
13. Virtual
Environments
Different parts for different projects
Image by EncMstr (Own work) [GFDL (http://www.gnu.org/copyleft/fdl.html) or CC BY-SA 4.0-3.0-2.5-2.0-1.0 (http://creativecommons.org/licenses/by-sa/4.0-3.0-2.5-2.0-1.0)], via Wikimedia Commons
14. Virtualenv
Can be installed via PIP
Allows you to switch between “virtual” environments
Virtual environments are full copies with symbolically linked, or optionally copied,
python binaries including pip.
Private set of environment variables
Private set of installed packages
Can be told which Python executable to use
Environments can be easily activated and deactivated
Deleting created directory remove virtual environments
15. Usage
$ which python
/usr/local/bin/python
$ virtualenv --prompt "(sdk) ” .venv
…
Installing setuptools, pip, wheel...done.
$ source .venv/bin/activate
(sdk) $ which python
/.venv/bin/python
(sdk) $ deactivate
$ which python
/usr/local/bin/python
Simple example for creating,
activating, and deactivating
virtual environments with
Virtualenv
16. Virtualenvwrapper
Can be installed via PIP
Adds additional functionality to Virtualenv
Uses named rather than location based environments
Places reusable environments in user directory
Auto-complete for enabling and removing environments
Defaults prompt prefix to environment name
If directory is same name as project. Enable with directory location
17. Usage
$ which python
/usr/local/bin/python
$ mkvirtualenv example
…
Installing setuptools, pip, wheel...done.
(example) $ which python
~/.virtualenvs/example/bin/python
(sdk) $ deactivate
$ which python
/usr/local/bin/python
Simple example for creating,
activating, and deactivating
virtual environments
18. Pyenv
Manage any number of Python executable versions
Great for open source projects that need to run on multiple versions
Has Virtualenv support via an add-on to support mixing Python executable
versions and virtual environments in a manner similar to rbenv.
On Mac, make sure XCode and Command Line Developer Tools are up to date.
19. Usage
$ which python3
$ pyenv install 3.5.2
Downloading Python-3.5.2.tgz...
->
https://www.python.org/ftp/python/3.5.2/Python-
3.5.2.tgz
Installing Python-3.5.2...
Installed Python-3.5.2 to ~/.pyenv/versions/3.5.2
$ pyenv global 3.5.2
$ python3 --version
Python 3.5.2
Simple example for installing and
using a Python version
Modern applications are much like this Nissan GTR. Users of your application see a pleasantly crafter user interface. The myriad of dependent systems are hidden away. These systems interact via well defined interfaces and can be swapped out for a newer version of the part as it comes along and the user wouldn’t know the difference. In many vehicles, entire subsystems are built by entirely different companies and available either as stock or aftermarket upgrades. Your application is no different.
Go karts are very similar to a GT-R. They are four wheeled rear wheel drive automobiles. They don’t have as many features as GT-R but they both do basically the same thing: go, stop, and turn. The biggest difference between them is the amount of design and engineering time put into them. For the car alone, it takes two to four years of design. Remember that that includes mostly ready made parts. The amount of time and engineering it takes for those is astronomical as well. They make up for the time in those parts by using them on multiple products.
What most of us build are much less complex and we don’t build most of the pieces. We start with a framework and cobble together bits and pieces to build a functional application as quickly and efficiently as possible.
Environments refer to python interpreter and a set of installed modules and extensions.
Much like a factory, without environment tools, you would need reset the line by uninstalling current modules and extensions and installing the ones you need. By default, each Python executable has only one environment. You can make pseudo-environments by altering paths and setting environment variables but there is a better way. You can get project specific virtual environments with a few simple tools.