Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2017 - Fabio Fleitas - Python Package Management with pip-tools

Db2ee812bdc6fd057f8f4209c08b6f63?s=47 PyBay
August 13, 2017

2017 - Fabio Fleitas - Python Package Management with pip-tools

How to use pip-tools (https://github.com/jazzband/pip-tools) to better manage Python requirement files.

Db2ee812bdc6fd057f8f4209c08b6f63?s=128

PyBay

August 13, 2017
Tweet

More Decks by PyBay

Other Decks in Programming

Transcript

  1. PYTHON PACKAGE MANAGEMENT WITH PIP-TOOLS Fabio Fleitas @ Tesorio August

    13, 2017 https://www.tesorio.com/careers
  2. HOW PYTHON PACKAGE MANAGEMENT IS DONE TODAY

  3. TOOLS OF THE TRADE pip virtualenv requirements.txt

  4. PIN THE TOP-LEVEL DEPENDENCIES # requirements.txt django==1.8.18 djangorestframework==3.5.3 django-extensions==1.7.5 requests==2.18.3

  5. $ pip install -r requirements.txt

  6. ISSUE WITH THAT APPROACH IS THAT IT CAN BE NON-DETERMINISTIC

    This is because you did not pin sub-dependencies
  7. MOST COMMON SOLUTION FOR DETERMINISTIC BUILDS $ pip freeze >

    requirements.txt
  8. # requirements.txt certifi==2017.7.27.1 chardet==3.0.4 Django==1.8.18 django-extensions==1.7.5 djangorestframework==3.5.3 idna==2.5 requests==2.18.3 six==1.10.0

    urllib3==1.22
  9. ISSUE WITH THAT APPROACH IS THAT YOU NOW HAVE TOP-

    LEVEL DEPENDENCIES MIXED WITH SUB-DEPENDENCIES This will make you life much harder to deal with upgrades/removals of dependencies
  10. THE SOLUTION: PIP-TOOLS $ pip install pip-tools

  11. pip-tools = pip-compile + pip-sync

  12. CREATE A REQUIREMENTS.IN Only include top-level dependencies # requirements.in django==1.8.18

    djangorestframework==3.5.3 django-extensions==1.7.5 requests==2.18.3
  13. $ pip-compile requirements.in

  14. # # This file is autogenerated by pip-compile # To

    update, run: # # pip-compile --output-file requirements.txt requirements.in # certifi==2017.7.27.1 # via requests chardet==3.0.4 # via requests django-extensions==1.7.5 django==1.8.18 djangorestframework==3.5.3 idna==2.5 # via requests requests==2.18.3 six==1.10.0 # via django-extensions urllib3==1.22 # via requests
  15. PIP-SYNC pip-sync ensures that your virtualenv is synced with your

    requirements.txt and removes everything else. This is important so you don't accidentally have other packages in your virtualenv that may have forgotten to be uninstalled.
  16. $ pip-sync requirements.txt

  17. None
  18. WE'RE HIRING https://www.tesorio.com/careers