Skip to content

Commit

Permalink
Backend upgrade.
Browse files Browse the repository at this point in the history
Issue #220
  • Loading branch information
Wim-De-Clercq authored and Tim Van Campenhout committed Nov 25, 2024
1 parent a32faae commit 9cd5dfe
Show file tree
Hide file tree
Showing 30 changed files with 806 additions and 638 deletions.
3 changes: 0 additions & 3 deletions .coveragerc

This file was deleted.

12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
application_import_names = crabpy_pyramid,tests
import-order-style = pycharm

extend-exclude =
.pytest_cache
filename =
./tests/**.py
./crabpy_pyramid/**.py
max-line-length = 80
extend-select = B950
extend-ignore = E203,E501,E701
3 changes: 3 additions & 0 deletions .github/pr-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
feature: ['feature/*', 'feat/*']
fix: ['bugfix/*', 'fix/*']
test: test/*
45 changes: 45 additions & 0 deletions .github/workflows/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: crabpy_pyramid tests

on:
push:
paths:
- crabpy_pyramid/**
- tests/**
- .github/workflows/backend.yaml
- pyproject.toml
- requirements*.txt

env:
CRABPY_INTEGRATION_TESTS: "true"

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install python requirements
run: |
pip install pip-tools
pip-sync requirements-dev.txt
pip install -e .
- name: Python tests
run: |
flake8
coverage run --source=crabpy_pyramid -m pytest tests
- name: Coveralls
uses: coverallsapp/github-action@v2
22 changes: 22 additions & 0 deletions .github/workflows/pr-labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: PR Labeler
on:
pull_request:
types: [opened]
branches:
- 'develop'
- 'epic'

permissions:
contents: read

jobs:
pr-labeler:
permissions:
contents: read # for TimonVS/pr-labeler-action to read config file
pull-requests: write # for TimonVS/pr-labeler-action to add labels in PR
runs-on: ubuntu-latest
steps:
- uses: TimonVS/pr-labeler-action@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/pr-labeler.yml
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# crabpy_pyramid

Bindings for the crabpy library and the pyramid framework

[![pypi](https://badge.fury.io/py/crabpy_pyramid.png)](http://badge.fury.io/py/crabpy_pyramid)
[![docs](https://readthedocs.org/projects/crabpy-pyramid/badge/?version=latest)](https://readthedocs.org/projects/crabpy-pyramid/?badge=latest)
[![CI](https://github.com/OnroerendErfgoed/crabpy_pyramid/actions/workflows/backend.yaml/badge.svg)](https://github.com/OnroerendErfgoed/crabpy_pyramid/actions/workflows/backend.yaml)
[![coverage](https://coveralls.io/repos/OnroerendErfgoed/crabpy_pyramid/badge.png?branch=master)](https://coveralls.io/r/OnroerendErfgoed/crabpy_pyramid?branch=master)
[![pypi](https://badge.fury.io/py/crabpy_pyramid.png)](http://badge.fury.io/py/crabpy_pyramid)


# Development
## Building the docs

More information about this library can be found in `docs`. The docs can be
built using `Sphinx <http://sphinx-doc.org>`_.

Please make sure you have installed Sphinx in the same environment where
crabpy\_pyramid is present.

```sh
pip install sphinx sphinxcontrib-httpdomain
pip install -e .
cd docs
make html
```

## Build wheel or sdist

```sh
pip install hatch
hatch build
hatch build -t wheel
hatch build -t sdist
```


## Work with pip-compile / pip-sync

full docs: https://pip-tools.readthedocs.io/en/latest/

To start, first install pip-tools:
```sh
pip install pip-tools
```

### uv (optional)

You can also use `uv` and for the remainder of the readme replace `pip`, `pip-compile` or
`pip-sync` by `uv pip`, `uv pip compile` and `uv pip sync`.

`uv` is a very fast replacement for pip-toools. It's optional, but can save a lot of time.
```sh
pip install uv
```

### Install requirements: pip-sync

Note, `pip-sync` also uninstalls everything from the virtualenv which does not belong
there according to the requirements file. This includes the project itself. You will
have to install `crabpy_pyramid` again after `pip-sync`.
Since the requirements file of pip-sync is still a normal requirements file you can also
use `pip install -r` to install all libraries defined in it. This will not cleanup your
virtualenv and uninstall other libraries.

The compiled requirements files are made in a 3.11 environment.
```sh
pip-sync requirements-dev.txt
pip install -e .
```
`requirements-dev.txt` contains all libraries uncluding those for testing and development.

`requirements.txt` contains only the necessary libraries for running the library.

### Update requirements: pip-compile

```sh
echo -e "\nStarting"
PIP_COMPILE_ARGS="-q --strip-extras --no-header --resolver=backtracking --no-emit-options pyproject.toml"
pip-compile $PIP_COMPILE_ARGS -o requirements.txt;
echo "requirements.txt done"
pip-compile $PIP_COMPILE_ARGS --extra dev -o requirements-dev.txt;
echo "requirements-dev.txt done"
echo "Finished"
```
33 changes: 0 additions & 33 deletions README.rst

This file was deleted.

93 changes: 40 additions & 53 deletions crabpy_pyramid/renderers/capakey.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
.. versionadded:: 0.1.0
"""
from crabpy.gateway import capakey

from pyramid.renderers import JSON


json_list_renderer = JSON()
json_item_renderer = JSON()

Expand All @@ -17,33 +17,23 @@ def list_gemeente_adapter(obj, request):
Adapter for rendering a list of
:class: `crabpy.gateway.capakey.Gemeente` to json.
"""
return {
'id': obj.id,
'naam': obj.naam
}
return {"id": obj.id, "naam": obj.naam}


def list_afdeling_adapter(obj, request):
"""
Adapter for rendering a list of
:class: `crabpy.gateway.capakey.Afdeling` to json.
"""
return {
'id': obj.id,
'naam': obj.naam,
'gemeente': obj.gemeente
}
return {"id": obj.id, "naam": obj.naam, "gemeente": obj.gemeente}


def list_sectie_adapter(obj, request):
"""
Adapter for rendering a list of
:class: `crabpy.gateway.capakey.Sectie` to json.
"""
return {
'id': obj.id,
'afdeling': obj.afdeling
}
return {"id": obj.id, "afdeling": obj.afdeling}


def list_perceel_adapter(obj, request):
Expand All @@ -52,10 +42,10 @@ def list_perceel_adapter(obj, request):
:class: `crabpy.gateway.capakey.Perceel` to json.
"""
return {
'id': obj.id,
'sectie': obj.sectie,
'capakey': obj.capakey,
'percid': obj.percid
"id": obj.id,
"sectie": obj.sectie,
"capakey": obj.capakey,
"percid": obj.percid,
}


Expand All @@ -71,10 +61,10 @@ def item_gemeente_adapter(obj, request):
:class: `crabpy.gateway.capakey.Gemeente` to json.
"""
return {
'id': obj.id,
'naam': obj.naam,
'centroid': obj.centroid,
'bounding_box': obj.bounding_box
"id": obj.id,
"naam": obj.naam,
"centroid": obj.centroid,
"bounding_box": obj.bounding_box,
}


Expand All @@ -84,14 +74,11 @@ def item_afdeling_adapter(obj, request):
:class: `crabpy.gateway.capakey.Afdeling` to json.
"""
return {
'id': obj.id,
'naam': obj.naam,
'gemeente': {
'id': obj.gemeente.id,
'naam': obj.gemeente.naam
},
'centroid': obj.centroid,
'bounding_box': obj.bounding_box
"id": obj.id,
"naam": obj.naam,
"gemeente": {"id": obj.gemeente.id, "naam": obj.gemeente.naam},
"centroid": obj.centroid,
"bounding_box": obj.bounding_box,
}


Expand All @@ -101,17 +88,17 @@ def item_sectie_adapter(obj, request):
:class: `crabpy.gateway.capakey.Sectie` to json.
"""
return {
'id': obj.id,
'afdeling': {
'id': obj.afdeling.id,
'naam': obj.afdeling.naam,
'gemeente': {
'id': obj.afdeling.gemeente.id,
'naam': obj.afdeling.gemeente.naam
"id": obj.id,
"afdeling": {
"id": obj.afdeling.id,
"naam": obj.afdeling.naam,
"gemeente": {
"id": obj.afdeling.gemeente.id,
"naam": obj.afdeling.gemeente.naam,
},
},
'centroid': obj.centroid,
'bounding_box': obj.bounding_box
"centroid": obj.centroid,
"bounding_box": obj.bounding_box,
}


Expand All @@ -121,23 +108,23 @@ def item_perceel_adapter(obj, request):
:class: `crabpy.gateway.capakey.Perceel` to json.
"""
return {
'id': obj.id,
'sectie': {
'id': obj.sectie.id,
'afdeling': {
'id': obj.sectie.afdeling.id,
'naam': obj.sectie.afdeling.naam,
'gemeente': {
'id': obj.sectie.afdeling.gemeente.id,
'naam': obj.sectie.afdeling.gemeente.naam
"id": obj.id,
"sectie": {
"id": obj.sectie.id,
"afdeling": {
"id": obj.sectie.afdeling.id,
"naam": obj.sectie.afdeling.naam,
"gemeente": {
"id": obj.sectie.afdeling.gemeente.id,
"naam": obj.sectie.afdeling.gemeente.naam,
},
},
},
'capakey': obj.capakey,
'percid': obj.percid,
'centroid': obj.centroid,
'bounding_box': obj.bounding_box,
'shape': obj.shape
"capakey": obj.capakey,
"percid": obj.percid,
"centroid": obj.centroid,
"bounding_box": obj.bounding_box,
"shape": obj.shape,
}


Expand Down
Loading

0 comments on commit 9cd5dfe

Please sign in to comment.