Thinking out Loud: Python packaging, build, and development
Posted by: Mark Bools on 2019-02-20 I’m a Python n00b, but an experienced software engineer and Python packaging is a rats nest. The Use Use the Use Use Use Replace On a side note; adding I ran into an issue including the following in my When I ran this using However, running it using This seems to stem from I decided to use This is very much a ‘work in progress’, but so far it is very satisfying. This is my first attempt at a substantial Python project. It’s actually a rewrite (and development off) a small service script to monitor multiple ‘weak’ WAN connections (slow unreliable ISPs) to load balance traffic from the LAN to the internet, ensuring when an ISP fails it is pulled from the gateway pool. https://gitlab.com/SaltyVagrant/wanmanager This is very much a work in progress, but here is where this post ends.requirements.txt
or setup.py
? Or one of the myriad packaging tools? It’s hard to see straight off.requirements.txt
or setup.py
really baked my noodle for a while. Finally I ended up at:
setup.py
for most purposes (I’m mainly interested in writing small utilities and command line applications).install_requires
in setup.py
to specify dependencies.pip install --user -e .
in preference to python setup.py develop
as the former handles more cases, even when specified in setup.py
(see below).pip freeze --user > requirements.txt
(not entirely sure on this one yet)python setup.py build sdist bdist_wheel
to produce wheel
for deployment.test
command in setup.py
to run the full pytest
suite.tox
to setup to run tests on oldest supported Python version and current version.Issues with
python setup.py develop
setup.py
:1
install_requires = ["PyYAML>=3.11"]
python setup.py develop
it threw all sorts of errors.pip install --user -e .
worked perfectly.setup.py develop
using eggs
whereas pip install -e
uses wheel
.Environment
concourse
CI for all my pipeline needs, so it is natural to set up build/test environments as docker
containers. Since I’m setting these up I may as well leverage them into a development environment. To this end I take the build/test image and layer on top of it a ‘developer’ image. Currently I’m using the following:Dockerfile.dev
1
2
3
4
5
6
7
8
9
10
11
12
13
FROM wanmgr:latest
MAINTAINER Mark Bools <saltyvagrant@gmail.com>
RUN apt-get update -y \
&& apt-get upgrade -y \
&& apt-get -y install git tmux vim
COPY . /app
WORKDIR /app
RUN pip install --user -e .
CMD ["tmux"]
The Project in Question