Skip to content

pip-tools-workflow #9

Closed
Closed

Description

@dfee

@jamescooke wanted to provide you with an updated copy of my makefile (for your use or others). ref

The modifications I've made allow one to compile requirements.txt files (specifically base.txt and test.txt in this case) so that they can be pip-installed from the project's root directory.

Like your structure, I have my req files in $PROJECT_ROOT/requirements/{*.in,*.txt}. However, these modifications are helpful so that I can:

  1. push my code to repo shared by a team, and
  2. use tox to install my requirements for me.
# From James Cooke's blog:
# "A successful pip-tools workflow for managing Python package requirements"
# http://jamescooke.info/a-successful-pip-tools-workflow-for-managing-python-package-requirements.html
.PHONY: all check clean

RELATIVE_PROJECT_ROOT = .. # relative path to project's root
PROJECT_ROOT = $(shell realpath $(RELATIVE_PROJECT_ROOT))
REQUIREMENTS_ROOT = $(shell realpath --relative-to $(PROJECT_ROOT) .)
objects = $(wildcard *.in)
outputs := $(objects:.in=.txt)

all: $(outputs)

%.txt: %.in
        @pushd $(PROJECT_ROOT) > /dev/null; \
        pip-compile --output-file $(REQUIREMENTS_ROOT)/$@ $(REQUIREMENTS_ROOT)/$<; \
        popd > /dev/null; \
        sed -i '' "s|file://$(PROJECT_ROOT)|.|" $@

test.txt: base.txt

check:
        @which pip-compile > /dev/null

clean: check
        - rm *.txt

Activity

  1. gsakkis commented on Sep 15, 2019

    @gsakkis

    @jamescooke @dfee I came across James' blog post which is pretty close to my desired workflow. The challenge I have at the moment is how to integrate it in a broader Makefile that also takes care of installing the (compiled via pip-compile) dependencies. I posted my question on StackOverflow, if you happen to have dealt with (or worked around) this issue it would be great to share it here and/or there.

  2. jamescooke commented on Sep 16, 2019

    @jamescooke
    Owner

    I've pinged you on the StackOverflow question 👍

  3. gsakkis commented on Sep 16, 2019

    @gsakkis

    Thanks!

  4. jimustafa commented on Jun 3, 2021

    @jimustafa

    A cookiecutter template implementing this workflow is being developed at https://github.com/jimustafa/cookiecutter-pylib-reqm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blog commentComments and feedback on articles

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions