Skip to content

Commit

Permalink
Integrate pip-tools for efficient package dependency management (#1598)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alihassanc5 authored Jun 13, 2023
1 parent 4395ad4 commit 53e4c02
Show file tree
Hide file tree
Showing 9 changed files with 2,343 additions and 43 deletions.
1 change: 1 addition & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ RUN apt-get update --yes --quiet \

COPY requirements.txt requirements.dev.txt /
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir pip-tools \
&& pip install --no-cache-dir -r /requirements.dev.txt
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ up:
docker-compose up
update_elasticsearch_index:
docker-compose run django python manage.py update_index
compile-requirements:
docker-compose run --rm django /app/scripts/compile-requirements.sh
test:
docker-compose -f docker-compose.test.yml up --build -d django
docker-compose -f docker-compose.test.yml exec -T django python manage.py collectstatic --noinput
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ Page caching is provided by Wagtail Cache and is deactivated by default. To star
## Migrating content from IoGT v1
Follow instructions [here](iogt_content_migration/README.md)

## Add/Update Package
Follow instructions [here][10]


[1]: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment
[2]: https://www.unicef.org/innovation/IoGT
Expand All @@ -195,3 +198,4 @@ Follow instructions [here](iogt_content_migration/README.md)
[7]: ./docs/cache.md
[8]: ./docs/troubleshooting.md
[9]: ./selenium_tests/README.md
[10]: ./docs/dependency-management.md
37 changes: 37 additions & 0 deletions docs/dependency-management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Introduce pip-tools

## What is it?
Pip-tools is a command-line toolset for managing dependencies in Python projects.
It streamlines the process of handling project dependencies by providing essential functionalities.

## Why do we use it?

### Dependency Management
Pip-tools helps manage a project's dependencies by resolving and pinning specific versions.
It ensures that everyone working on the project uses the same versions of dependencies, promoting consistency and reproducibility.

### Simplified Workflow
Pip-tools simplifies the workflow of managing dependencies by keeping the requirements.in file separate from the requirements.txt file.
The requirements.in file contains high-level dependencies, while the requirements.txt file contains the pinned versions. This separation enables easy updating and maintenance of dependencies.

## How do we use it?

### For Virtual Environment:

#### Install or Upgrade pip:
```pip install --upgrade pip```

#### Install pip-tools:
```pip install pip-tools```

#### Generate Pinned Versions:
Add or update the package and its version specifier according to your needs in <requirements_file>.in file.

```pip-compile --generate-hashes --resolver=backtracking -o <requirements_file>.txt <requirements_file>.in```

### For Docker
Add or update the package and its version specifier according to your needs in <requirements_file>.in file.

```
make compile-requirements
```
10 changes: 10 additions & 0 deletions requirements.dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-r requirements.txt
beautifulsoup4
coverage
django-test-plus>=1.4.0
factory-boy==3.2.*
Faker
pytest
pytest-django
selenium==4.9.1
wagtail-factories==4.0.*
1,286 changes: 1,276 additions & 10 deletions requirements.dev.txt

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cairosvg==2.7.0
django-allauth~=0.44
django-comments-xtd==2.9.*
django-compressor==2.4.*
django-debug-toolbar==3.2.1
django-extensions==3.1.*
django-filter==2.4.0
django-google-analytics-app==5.0.5
django-health-check==3.16.5
django-redis~=5.2.0
django-sass-processor==1.0.*
django-translation-manager~=1.3.0
django-webpush==0.3.4
django==3.2.*
djangorestframework-simplejwt==5.0.0
djangorestframework~=3.13.1
drf-yasg~=1.21.3
elasticsearch~=7.16
libsass==0.21.*
lxml==4.8.*
Markdown==3.3.7
psycopg2==2.8.*
redis~=3.0
tqdm==4.62.*
wagtail-cache~=1.2.1
wagtail-localize==1.3.3
wagtail-markdown==0.7.0
wagtail==2.15.*
wagtailmedia==0.10.*
wagtailmenus==3.1.3
wagtailsvg==0.0.14
whitenoise==5.2.*
https://github.com/IDEMSInternational/wagtail-transfer/archive/408edb5d432ac72dc2727a1847e0f294b8d6efa6.zip#egg=wagtail-transfer
1,003 changes: 970 additions & 33 deletions requirements.txt

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions scripts/compile-requirements.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

REQ_FILES=(
"/app/requirements"
"/app/requirements.dev"
)

for f in "${REQ_FILES[@]}"; do
pip-compile --generate-hashes --resolver=backtracking -o ${f}.txt ${f}.in || exit 1;
done

0 comments on commit 53e4c02

Please sign in to comment.