Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into improvement/2056_in…
Browse files Browse the repository at this point in the history
…itialize_things_once
  • Loading branch information
vvmruder committed Dec 11, 2024
2 parents 70fa4f2 + 176b4b3 commit c820dc1
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 75 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ jobs:

lint:
name: Check style (lint)
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install libpq-dev
Expand All @@ -16,9 +16,9 @@ jobs:

gitattributes:
name: Check style (git-attributes)
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install libpq-dev
Expand All @@ -27,7 +27,7 @@ jobs:

test-py:
name: Test Python
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
services:
# Label used to access the service container
postgres:
Expand All @@ -52,7 +52,7 @@ jobs:
- '3.11'
- '3.12'
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up Python v${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand All @@ -76,9 +76,9 @@ jobs:

test-fed-data:
name: Check federal data definitions
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install xsltproc
Expand All @@ -93,24 +93,24 @@ jobs:
doc:
name: Make and deploy documentation
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Make documentation
run: |
sudo rm /etc/apt/sources.list.d/*.list
sudo apt update
sudo apt-get install libpq-dev
make doc-html
- name: Deploy 🚀
uses: JamesIves/[email protected].3
uses: JamesIves/[email protected].8
with:
branch: gh-pages # The branch the action should deploy to.
folder: doc/build/html # The folder the action should deploy.

build-and-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
needs: [lint, gitattributes]
steps:
- uses: actions/checkout@master
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/daily_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ on:
jobs:
test-fed-data:
name: Check federal data definitions
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install xsltproc
Expand All @@ -22,7 +22,7 @@ jobs:
test-py:
name: Test Python
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
services:
# Label used to access the service container
postgres:
Expand All @@ -47,7 +47,7 @@ jobs:
- python3.11
- python3.12
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- run: sudo rm /etc/apt/sources.list.d/*.list
- run: sudo apt update
- run: sudo apt-get install libpq-dev
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Notes:
------
- This python package specifies the version numbers only of directly imported python packages. This approach may result in a build failure of older versions of the project if incompatibilities arise between imported packages over time. The build process of the master branch is regularly tested in an automatic process.

2.5.4
-----
- New parameter default_toc_length to define a default table of content pages number (#2042)
- Add timeout in address source (#2043)
- Optimize legend entries retrieval (#2050)
- Library upgrades (waitress, sqlalchemy, psycopg2, urllib3)

2.5.3
-----
- Provide a general WMS verify certificate option
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12.5-bullseye
FROM python:3.13.0-bullseye

ENV DEBIAN_FRONTEND=noninteractive

Expand Down
15 changes: 10 additions & 5 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ Changes/Hints for migration
This chapter will give you hints on how to handle version migration, in particular regarding what you may need
to adapt in your project configuration, database etc. when upgrading to a new version.

Version 2.6.0
Version 2.5.4
-------------
* New parameter 'expected_toc_length' allows to define a default table of content pages number avoiding a second
call for the pdf extract in most cases. This value may be be set if most of the PDF extracts have the same number
of TOC pages. It complements the 'compute_toc_pages' parameter. If the latter is set to true 'expected_toc_length'
is ignored.
Feature and maintenance release:

* New parameter 'expected_toc_length' allows to define a default table of content pages number avoiding a
second call for the pdf extract in most cases. This value may be be set if most of the PDF extracts have
the same number of TOC pages. It complements the 'compute_toc_pages' parameter. If the latter is set to true,
'expected_toc_length' is ignored.
* Add timeout in address source (#2043)
* Optimize legend entries retrieval (#2050)
* Library upgrades (waitress, sqlalchemy, psycopg2, urllib3)

Version 2.5.3
-------------
Expand Down
24 changes: 12 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyramid_oereb"
version = "2.5.3"
version = "2.5.4"
description = "pyramid_oereb, extension for pyramid web frame work to provide a basic server part for the oereb project"

classifiers=[
Expand Down Expand Up @@ -35,18 +35,18 @@ Changelog = "https://github.com/openoereb/pyramid_oereb/blob/master/CHANGES.rst"
[project.optional-dependencies]
# Dependencies listed in "recommend" must be included in "no-version" without explicit version number
recommend = [
"pypdf==4.3.1",
"pypdf==5.1.0",
"filetype==1.2.0",
"geoalchemy2==0.15.2",
"pyramid==2.0.2",
"pyramid-debugtoolbar==4.12.1",
"qrcode==7.4.2",
"qrcode==8.0",
"image==1.5.33",
"shapely==2.0.6",
"SQLAlchemy==2.0.32",
"SQLAlchemy==2.0.36",
"pyaml-env==1.2.1",
"urllib3==2.2.2",
"waitress==3.0.0",
"urllib3==2.2.3",
"waitress==3.0.1",
"pyreproj==3.0.0",
"mako-render==0.1.0",
"requests==2.32.3",
Expand Down Expand Up @@ -75,21 +75,21 @@ no-version = [
testing = [
"jsonschema==4.23.0",
"lxml==5.3.0",
"pytest==8.3.2",
"pytest-cov==5.0.0",
"pytest==8.3.3",
"pytest-cov==6.0.0",
"pytest-ordering==0.6",
"requests-mock==1.12.1",
"responses==0.25.3",
"webtest==3.0.0",
"pillow==10.4.0"]
"webtest==3.0.1",
"pillow==11.0.0"]
dev = [
"flake8==7.1.1",
"Flake8-pyproject==1.2.3",
"pyflakes==3.2.0",
"pycodestyle==2.12.1",
"Sphinx==7.4.7",
"sphinx_rtd_theme==2.0.0",
"psycopg2==2.9.9",
"sphinx_rtd_theme==3.0.1",
"psycopg2==2.9.10",
"mccabe==0.7.0",
"c2c.template==2.4.2",
"yappi"]
Expand Down
58 changes: 38 additions & 20 deletions pyramid_oereb/contrib/data_sources/interlis_2_3/sources/plr.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,20 +470,33 @@ def collect_related_geometries_by_real_estate(self, session, real_estate):
.selectinload(self.models.MultilingualUri.localised_uri)
).all()

def collect_legend_entries_by_bbox(self, session, bbox, law_status):
def get_legend_entries_from_db(self, session, legend_entry_ids):
"""
Retrieves the legend entries for a list of t_id-values.
Args:
session (sqlalchemy.orm.Session): The requested clean session instance ready for use
legend_entry_ids (list): list of the egend entry ids
Returns:
list: the query result represented as a list.
"""
return session.query(self.legend_entry_model).filter(
self.legend_entry_model.t_id.in_(legend_entry_ids)).all()

def collect_legend_entries_by_bbox(self, session, bbox):
"""
Extracts all legend entries in the topic which have spatial relation with the passed bounding box of
visible extent.
Args:
session (sqlalchemy.orm.Session): The requested clean session instance ready for use
bbox (shapely.geometry.base.BaseGeometry): The bbox to search the records.
law_status (str): String of the law status for which the legend entries should be queried.
Returns:
list: The result of the related geometries unique by the public law restriction id and law status
"""
distinct_legend_entry_ids = []
# Select the legend entries of all plr within bbox
geometries = session.query(self._model_).filter(
or_(
self._model_.point.ST_Intersects(from_shape(bbox, srid=Config.get('srid'))),
Expand All @@ -493,13 +506,29 @@ def collect_legend_entries_by_bbox(self, session, bbox, law_status):
selectinload(self.models.Geometry.public_law_restriction)
).all()

# Compile a list of unique legend entry ids for each law status
legend_entry_ids = dict()
for geometry in geometries:
if geometry.public_law_restriction.legend_entry_id not in distinct_legend_entry_ids\
and geometry.public_law_restriction.law_status == law_status:
distinct_legend_entry_ids.append(geometry.public_law_restriction.legend_entry_id)
if geometry.public_law_restriction.law_status not in legend_entry_ids:
legend_entry_ids[geometry.public_law_restriction.law_status] = {
geometry.public_law_restriction.legend_entry_id
}
else:
legend_entry_ids[geometry.public_law_restriction.law_status].add(
geometry.public_law_restriction.legend_entry_id
)

return session.query(self.legend_entry_model).filter(
self.legend_entry_model.t_id.in_((distinct_legend_entry_ids))).all()
# Retrieve legend entries
legend_entries_from_db = []
for law_status in legend_entry_ids:
legend_entries_from_db.append(
[
self.get_legend_entries_from_db(session, list(legend_entry_ids[law_status])),
law_status
]
)

return legend_entries_from_db

def read(self, params, real_estate, bbox):
"""
Expand Down Expand Up @@ -537,20 +566,9 @@ def read(self, params, real_estate, bbox):
else:
# We found spatially related elements. This means we need to extract the actual plr
# information related to the found geometries.
law_status_of_geometry = []
# get distinct values of law_status for all geometries found
for geometry in geometry_results:
if (geometry.public_law_restriction.law_status not in law_status_of_geometry):
law_status_of_geometry.append(geometry.public_law_restriction.law_status)

legend_entries_from_db = []
# get legend_entries per law_status
for law_status in law_status_of_geometry:
legend_entry_with_law_status = [
self.collect_legend_entries_by_bbox(session, bbox, law_status),
law_status
]
legend_entries_from_db.append(legend_entry_with_law_status)
legend_entries_from_db = self.collect_legend_entries_by_bbox(session, bbox)

self.records = []
for geometry_result in geometry_results:
Expand Down
Loading

0 comments on commit c820dc1

Please sign in to comment.