...

/

Managing Dependencies

Managing Dependencies

Learn how to best manage dependencies in Python softwares, and what considerations to take into account regarding them.

The software is delivered to production by following a development pipeline. This starts in a first environment, then the tests run on it (integration, acceptance, and so on), and then through continuous integration and continuous deployment, it moves through the different stages of the pipeline (for example, if we have a beta testing environment, or preproduction before it ultimately reaches production).

Docker is great at ensuring the exact same image is moved along the pipeline, but there's no guarantee that if we run the same version of the code (the same git commit, let's say) again through the pipeline, we'll get the same results. That work is on us, and it's what we're exploring in this lesson.

Adding dependencies in setup.py

Let's say the setup.py file of our web package looks like this:

Press + to interact
from setuptools import find_packages, setup
with open("README.rst", "r") as longdesc:
long_description = longdesc.read()
install_requires = ["sanic>=20,<21"]
setup(
name="web",
description="Library with helpers for the web-related functionality",
long_description=long_description,
author="Dev team",
version="0.1.0",
packages=find_packages(where="src/"),
package_dir={"": "src"},
install_requires=install_requires,
)

In this case, there's only one dependency (declared in the install_requires parameter), and it's controlling a version interval. This is usually a good practice: we want to at least work with a specific version of a package, but we are also interested in not going beyond the next major version (as major versions can carry backward-incompatible ...