Skip to content

Commit

Permalink
make app installable + reorganize code + update requirements (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored Mar 23, 2024
1 parent 8658ad1 commit 596f38b
Show file tree
Hide file tree
Showing 54 changed files with 119 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# MAIN SETTINGS FOR THE DOCKER COMPOSE STACK

# Change which dockerfiles to include. In production, make sure to only include docker-compose.yml
COMPOSE_FILE=docker-compose.yml:docker-compose.tests.yml:docker-compose.dev.yml
COMPOSE_FILE=tests/docker-compose.yml:tests/docker-compose.dev.yml

# Change this to the host name on which the stack is installed
OGCAPIF_HOST=0.0.0.0
Expand Down
26 changes: 9 additions & 17 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
- name: Create env
run: cp .env.example .env

- name: Load .env file
uses: xom9ikk/dotenv@v2

- uses: actions/setup-python@v5
with:
python-version: '3.10'
Expand All @@ -53,21 +50,16 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Django image
uses: docker/build-push-action@v5
with:
context: .
provenance: false
file: docker/django/Dockerfile
pull: true
cache-from: type=registry,ref=opengisch/django-oapif:latest
tags: opengisch/django-oapif:latest

- name: Download fixtures
run: ./scripts/download-fixtures.sh
run: scripts/download-fixtures.sh

- name: Start Django
run: ./scripts/restart.sh
run: |
docker compose up --build -d
docker compose exec django python manage.py migrate
- name: Load .env file
uses: xom9ikk/dotenv@v2

- name: Run Benchmark
run: ./tests/benchmark/time.sh ${{ inputs.size }}
Expand All @@ -78,8 +70,8 @@ jobs:
- uses: actions/upload-artifact@v4
with:
path: |
tests/benchmark/results/benchmark.dat
tests/benchmark/results/*.png
tests/benchmark/output/benchmark.dat
tests/benchmark/output/*.png
if-no-files-found: error

- name: Failure logs
Expand Down
34 changes: 6 additions & 28 deletions .github/workflows/conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,11 @@ jobs:
- name: Create env
run: cp .env.example .env

- name: Load .env file
uses: xom9ikk/dotenv@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
if: github.repository == 'opengisch/django-ogcapif'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Django image
uses: docker/build-push-action@v5
with:
context: .
provenance: false
file: docker/django/Dockerfile
push: ${{ github.repository == 'opengisch/django-ogcapif' }}
pull: true
cache-from: type=registry,ref=opengisch/django-oapif:latest
cache-to: type=registry,ref=opengisch/django-oapif:latest,mode=max
tags: opengisch/django-oapif:latest

- name: Do quickstart
run: |
# copy default conf
cp .env.example .env
# start the stack
docker compose --profile testing_conformance up --build -d
Expand All @@ -62,6 +37,9 @@ jobs:
docker compose exec django python manage.py populate_users
docker compose exec django python manage.py populate_data
- name: Load .env file
uses: xom9ikk/dotenv@v2

- name: Healthcheck
run: wget http://${OGCAPIF_HOST}:${DJANGO_DEV_PORT}/oapif/collections/tests.point_2056_10fields/items

Expand All @@ -73,7 +51,7 @@ jobs:
with:
name: emailable-report
path: |
./test_outputs/**/emailable-report.html
./tests/output/**/emailable-report.html
- name: Install requirements
run: pip install lxml
Expand All @@ -82,7 +60,7 @@ jobs:
id: baseline
run: |
EXIT_CODE=0
python tests/conformance/parse_report.py test_outputs/emailable-report.html tests/conformance/conformance-baseline.json || EXIT_CODE=$?
python tests/conformance/parse_report.py tests/output/emailable-report.html tests/conformance/conformance-baseline.json || EXIT_CODE=$?
echo "EXIT_CODE=${EXIT_CODE}" >> $GITHUB_OUTPUT
- name: Commit baseline if improved >> checkout
Expand Down Expand Up @@ -123,7 +101,7 @@ jobs:

- name: Recheck baseline
run: |
python tests/conformance/parse_report.py test_outputs/emailable-report.html tests/conformance/conformance-baseline.json
python tests/conformance/parse_report.py tests/output/emailable-report.html tests/conformance/conformance-baseline.json
- name: Failure logs
if: failure()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
- name: Failure logs
if: failure()
run: docker-compose logs django
run: docker-compose logs django_oapif_tests
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ jobs:
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: twine upload ./django-ogcapif/dist/* --verbose
run: twine upload ./django_oapif_tests-ogcapif/dist/* --verbose
29 changes: 1 addition & 28 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,46 +25,19 @@ jobs:
- name: Create env
run: cp .env.example .env

- name: Load .env file
uses: xom9ikk/dotenv@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
if: github.repository == 'opengisch/django-ogcapif'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Django image
uses: docker/build-push-action@v5
with:
context: .
provenance: false
file: docker/django/Dockerfile
push: ${{ github.repository == 'opengisch/django-ogcapif' }}
pull: true
cache-from: type=registry,ref=opengisch/django-oapif:latest
cache-to: type=registry,ref=opengisch/django-oapif:latest,mode=max
tags: opengisch/django-oapif:latest

- name: Setup Compose
run: |
# copy default conf
cp .env.example .env
# start the stack
docker compose --profile testing_integration up --build -d
# migrate database
docker compose exec django python manage.py migrate --no-input
docker compose exec django python manage.py populate_users
docker compose exec django python manage.py populate_data
- name: Run unit tests
run: docker compose exec django python manage.py test tests
run: docker compose exec django python manage.py test

- name: Run integration tests
run: docker compose run integration_tests
Expand Down
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ __pycache__
build
dist
*.egg-info
src/django_oapif/__version__.py
django_oapif/core/__version__.py

tests/benchmark/results
tests/benchmark/output
tests/output

src/tests/fixtures/polygon_2056.json.gz
src/tests/fixtures/polygon_2056_local_geom.json.gz
tests/django_oapif_tests/tests/fixtures/polygon_2056.json.gz
tests/django_oapif_tests/tests/fixtures/polygon_2056_local_geom.json.gz

data
static
media
test_outputs
.vscode/
.python-version
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exclude: ^src/tests/migrations/
exclude: ^core/tests/migrations/

repos:
# Fix end of files
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ This project is [hosted on PyPI](https://pypi.org/project/django-ogcapif/). You

```bash
# Install with your favorite package manager
pip3 install --user django-ogcapif
pip3 install --user https://github.com/opengisch/django-ogcapif
# Edit your Django project's settings.py accordingly:
settings.py
-----------
Expand All @@ -76,7 +76,8 @@ models.py
---------
from rest_framework import permissions
from django.contrib.gis.db import models
from django_oapif.decorators import register_oapif_viewset
from django_oapif import register_oapif_viewset


@register_oapif_viewset(
custom_viewset_attrs={
Expand Down Expand Up @@ -104,4 +105,4 @@ You can run the OGC API conformance test suite like this:
docker compose run conformance_test
```

Results will be stored to `test_outputs\emailable-report.html
Results will be stored to `tests/output/emailable-report.html
3 changes: 2 additions & 1 deletion src/django_oapif/README.md → django_oapif/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ urlpatterns += [
# models.py

from django.contrib.gis.db import models
from django_oapif.decorators import register
from django_oapif import register


@register()
class TestingDecorator(models.Model):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/django_oapif/pagination.py → django_oapif/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class OapifPagination(pagination.LimitOffsetPagination):
"""OAPIF-compatible django rest paginator"""
"""OAPIF-compatible django_oapif_tests rest paginator"""

default_limit = 1000

Expand Down Expand Up @@ -52,7 +52,7 @@ def get_schema_operation_parameters(self, view):


class HighPerfPagination(pagination.LimitOffsetPagination):
"""OAPIF-compatible django rest paginator, tailored for the high performance version where data is pre-concatenated json"""
"""OAPIF-compatible django_oapif_tests rest paginator, tailored for the high performance version where data is pre-concatenated json"""

def get_paginated_response(self, data):
# FIXME: this probably is a bug, since `data` is a string, it is not the number of features
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 0 additions & 21 deletions docker-compose.tests.yml

This file was deleted.

3 changes: 0 additions & 3 deletions docker/caddy/Dockerfile

This file was deleted.

29 changes: 0 additions & 29 deletions docker/django/Dockerfile

This file was deleted.

11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]==7.*"]
requires = ["setuptools>=45", "setuptools-git-versioning<2"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -24,9 +24,12 @@ homepage = "https://github.com/opengisch/django-ogcapif"
repository = "https://github.com/opengisch/django-ogcapif"
tracker = "https://github.com/opengisch/django-ogcapif/issues"

[tool.setuptools_scm]
version_scheme = "post-release"
root = ".."
[tool.setuptools]
packages = ["django_oapif"]

[tool.setuptools-git-versioning]
enabled = true
version_callback = "0.0.0.dev"

[tool.setuptools.dynamic]
readme = {file = ["README.md"], content-type = "text/markdown"}
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pre-commit
debugpy
django-debug-toolbar
django-computedfields
flameprof
gprof2dot
8 changes: 3 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
django>=4
django-computedfields
django>=4,<5
psycopg2-binary
transifex-client
djangorestframework
git+https://github.com/3nids/django-rest-framework-gis@93d9718d123c2158f4d1c5f6cf461ba8f6cf89e7
djangorestframework==3.14.0
djangorestframework-gis@git+https://github.com/openwisp/django-rest-framework-gis@4f244d5d8a7ad5b453fd04f64150818d15123e01
pyyaml
uritemplate
pyproj
6 changes: 3 additions & 3 deletions scripts/download-fixtures.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -e

mkdir -p src/tests/fixtures
mkdir -p ./tests/django_oapif_tests/tests/fixtures

# download fixtures
curl -L -o ./src/tests/fixtures/polygon_2056.json.gz 'https://drive.google.com/uc?export=download&id=1UuGoK_9Y99jiTvQd4juxu85eVZhvlAvy'
curl -L -o ./src/tests/fixtures/polygon_2056_local_geom.json.gz 'https://drive.google.com/uc?export=download&id=18PGtiptcJiRtLnVq7N64EVQLagse0bu0'
curl -L -o ./tests/django_oapif_tests/tests/fixtures/polygon_2056.json.gz 'https://drive.google.com/uc?export=download&id=1UuGoK_9Y99jiTvQd4juxu85eVZhvlAvy'
curl -L -o ./tests/django_oapif_tests/tests/fixtures/polygon_2056_local_geom.json.gz 'https://drive.google.com/uc?export=download&id=18PGtiptcJiRtLnVq7N64EVQLagse0bu0'
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/benchmark/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import plotly.graph_objects as go
from plotly.subplots import make_subplots

output_path = "tests/benchmark/results"
output_path = "tests/benchmark/output"


def tr(layer: str) -> str:
Expand Down
Loading

0 comments on commit 596f38b

Please sign in to comment.