Skip to main content

Prequ -- Python requirement handling

Project description

Tools for Python requirement handling. Helps in keeping your requirements files complete and up-to-date.

Background

Every non-library Python project should have a requirements.txt file which lists required Python packages for the project, i.e. its dependencies. It would be easy to just list the dependencies with their minimum and maximum versions in there, but that’s not a good practice. If versions of the dependencies are not pinned to exact versions, it’s uncertain which version of the packages get installed. Even pinning the direct dependencies is not enough, since project dependencies might have their own dependencies (project’s indirect dependencies) and those should be pinned too. That’s where Prequ comes in: it makes it easy to generate the list of those pinned direct and indirect dependencies from the non-pinned requirements.

There is also a good article by Vincent Driessen which explains it more thoroughly why you should pin your packages.

Prequ is a fork of pip-tools by Vincent Driessen. Pip-tools was a fine project, but I wanted to add couple new features and make some changes to existing workflows. There were also couple bugs that I needed to be fixed sooner than later. Most of those bugs were already fixed in GitHub pull requests, but weren’t merged to pip-tools. That’s why I decided to create my own fork.

Installation

$ pip install --upgrade pip  # Prequ needs pip==8.0 or higher
$ pip install prequ

Example usage for prequ compile

Suppose you have a Flask project, and want to pin it for production. Write the following line to a file:

# requirements.in
Flask

Now, run prequ compile requirements.in:

$ prequ compile requirements.in
# This file is autogenerated by Prequ.  To update, run:
#
#   prequ compile requirements.in
#
flask==0.10.1
itsdangerous==0.24        # via flask
jinja2==2.7.3             # via flask
markupsafe==0.23          # via jinja2
werkzeug==0.10.4          # via flask

And it will produce your requirements.txt, with all the Flask dependencies (and all underlying dependencies) pinned. Put this file under version control as well.

To update all packages, periodically re-run prequ compile --upgrade.

To update a specific package to the latest or a specific version use the --upgrade-package or -P flag:

prequ compile --upgrade-package flask
  # only update the flask package
prequ compile --upgrade-package flask --upgrade-package requests
  # update both the flask and requests packages
prequ compile -P flask -P requests==2.0.0
  # update the flask package to the latest, and requests to v2.0.0

Example usage for prequ sync

Now that you have a requirements.txt, you can use prequ sync to update your virtual env to reflect exactly what’s in there. Note: this will install/upgrade/uninstall everything necessary to match the requirements.txt contents.

$ prequ sync
Uninstalling flake8-2.4.1:
  Successfully uninstalled flake8-2.4.1
Collecting click==4.1
  Downloading click-4.1-py2.py3-none-any.whl (62kB)
    100% |████████████████████████████████| 65kB 1.8MB/s
  Found existing installation: click 4.0
    Uninstalling click-4.0:
      Successfully uninstalled click-4.0
Successfully installed click-4.1

To sync multiple *.txt dependency lists, just pass them in via command line arguments e.g.:

$ prequ sync dev-requirements.txt requirements.txt

Passing in empty arguments would cause it to default to requirements.txt.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prequ-0.180.8.tar.gz (30.5 kB view hashes)

Uploaded Source

Built Distribution

prequ-0.180.8-py2.py3-none-any.whl (42.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page