Skip to content

Commit

Permalink
build(backend): upgrade Python --> v3.11 & update backend dependencies (
Browse files Browse the repository at this point in the history
#1671)

* build: update references python 3.10 --> 3.11

* build: upgrade to python v3.11, including all dependencies updated

* build: add Xfrozen_modules=off to debug dockerfile (python 3.11 specific)

* fix(backend): ensure all geojson properties are string values

* fix(backend): top level bbox in geojson as defined in spec

* fix(frontend): use top level bbox in geojsons

* build: relock backend dependencies after rebase

* build: upgrade to latest python package versions

* build: fix invalid API_PREFIX default after fastapi upgrade

* refactor: enforce Feature return type for outline_geojson

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* build: use py11 for ruff lint/fix

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
spwoodcock and pre-commit-ci[bot] authored Jul 21, 2024
1 parent 96c4c95 commit bde9f07
Show file tree
Hide file tree
Showing 11 changed files with 1,024 additions and 1,079 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ FMTM_DOMAIN=${FMTM_DOMAIN:-"fmtm.localhost"}
FMTM_DEV_PORT=${FMTM_DEV_PORT:-7050}
CERT_EMAIL=${CERT_EMAIL}
# Use API_PREFIX if running behind a proxy subpath (e.g. /api)
API_PREFIX=${API_PREFIX:-/}
API_PREFIX=${API_PREFIX}

### OSM ###
OSM_CLIENT_ID=${OSM_CLIENT_ID}
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ services:
- ./src/backend/pyproject.toml:/opt/pyproject.toml:ro
- ./src/backend/app:/opt/app
- ./src/backend/tests:/opt/tests:ro
# - ../osm-fieldwork/osm_fieldwork:/home/appuser/.local/lib/python3.10/site-packages/osm_fieldwork:ro
# - ../osm-rawdata/osm_rawdata:/home/appuser/.local/lib/python3.10/site-packages/osm_rawdata:ro
# - ../fmtm-splitter/fmtm_splitter:/home/appuser/.local/lib/python3.10/site-packages/fmtm_splitter:ro
# - ../osm-fieldwork/osm_fieldwork:/home/appuser/.local/lib/python3.11/site-packages/osm_fieldwork:ro
# - ../osm-rawdata/osm_rawdata:/home/appuser/.local/lib/python3.11/site-packages/osm_rawdata:ro
# - ../fmtm-splitter/fmtm_splitter:/home/appuser/.local/lib/python3.11/site-packages/fmtm_splitter:ro
depends_on:
fmtm-db:
condition: service_healthy
Expand Down
4 changes: 2 additions & 2 deletions docs/dev/Backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ just migrate

```json
{
"python.analysis.extraPaths": ["src/backend/__pypackages__/3.10/lib/"]
"python.analysis.extraPaths": ["src/backend/__pypackages__/3.11/lib/"]
}
```

Expand Down Expand Up @@ -205,7 +205,7 @@ Creating a new release during development may not always be feasible.
- Uncomment the line in docker-compose.yml

```yaml
- ../osm-fieldwork/osm_fieldwork:/home/appuser/.local/lib/python3.10/site-packages/osm_fieldwork
- ../osm-fieldwork/osm_fieldwork:/home/appuser/.local/lib/python3.11/site-packages/osm_fieldwork
```

- Run the docker container with your local version of osm-fieldwork.
Expand Down
6 changes: 3 additions & 3 deletions src/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with FMTM. If not, see <https:#www.gnu.org/licenses/>.
#
ARG PYTHON_IMG_TAG=3.10
ARG PYTHON_IMG_TAG=3.11
ARG MINIO_TAG=${MINIO_TAG:-RELEASE.2024-06-06T09-36-42Z}
FROM docker.io/minio/minio:${MINIO_TAG} as minio

Expand Down Expand Up @@ -166,8 +166,8 @@ RUN pip install --user --upgrade --no-warn-script-location \
-r /opt/python/requirements-debug.txt \
-r /opt/python/requirements-ci.txt \
&& rm -r /opt/python
CMD ["python", "-m", "debugpy", "--listen", "0.0.0.0:5678", \
"-m", "uvicorn", "app.main:api", \
CMD ["python", "-Xfrozen_modules=off", "-m", "debugpy", \
"--listen", "0.0.0.0:5678", "-m", "uvicorn", "app.main:api", \
"--host", "0.0.0.0", "--port", "8000", "--workers", "1", \
"--reload", "--log-level", "critical", "--no-access-log"]

Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def assemble_cors_origins(
default_origins += val
return default_origins

API_PREFIX: str = "/"
API_PREFIX: str = ""

FMTM_DB_HOST: Optional[str] = "fmtm-db"
FMTM_DB_USER: Optional[str] = "fmtm"
Expand Down
12 changes: 6 additions & 6 deletions src/backend/app/db/postgis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async def flatgeobuf_to_featcol(
SELECT jsonb_build_object(
'type', 'Feature',
'geometry', ST_AsGeoJSON(ST_GeometryN(fgb_data.geom, 1))::jsonb,
'id', fgb_data.osm_id,
'id', fgb_data.osm_id::VARCHAR,
'properties', jsonb_build_object(
'osm_id', fgb_data.osm_id,
'tags', fgb_data.tags,
Expand Down Expand Up @@ -312,7 +312,7 @@ async def split_geojson_by_task_areas(
jsonb_build_object(
'type', 'Feature',
'geometry', ST_AsGeoJSON(temp_features.geometry)::jsonb,
'id', temp_features.id,
'id', temp_features.id::VARCHAR,
'properties', temp_features.properties
) AS feature
FROM (
Expand Down Expand Up @@ -376,21 +376,21 @@ def add_required_geojson_properties(
# Check for id type embedded in properties
if osm_id := properties.get("osm_id"):
# osm_id property exists, set top level id
feature["id"] = osm_id
feature["id"] = f"{osm_id}"
else:
if prop_id := properties.get("id"):
# id is nested in properties, use that
feature["id"] = prop_id
feature["id"] = f"{prop_id}"
properties["osm_id"] = prop_id
elif fid := properties.get("fid"):
# The default from QGIS
feature["id"] = fid
feature["id"] = f"{fid}"
properties["osm_id"] = fid
else:
# Random id
# NOTE 32-bit int is max supported by standard postgres Integer
random_id = getrandbits(30)
feature["id"] = random_id
feature["id"] = f"{random_id}"
properties["osm_id"] = random_id

# Other required fields
Expand Down
Loading

0 comments on commit bde9f07

Please sign in to comment.