Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
fix Cyclic dependencies (#295)
Browse files Browse the repository at this point in the history
* fix cycling dependencies

* push to registry all dev images

Co-authored-by: sdirollo <sebastien.dirollo@gmail.com>
Co-authored-by: Aureliano Sinatra <a.sinatra@qwant.com>
  • Loading branch information
3 people authored Jan 19, 2022
1 parent 65582df commit eff28c5
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 193 deletions.
39 changes: 29 additions & 10 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
on:
pull_request:
push:
branches:
- 'master'
tags:
- 'v*'
on: [push, pull_request]

env:
DOCKER_IMAGE_BASENAME: qwantresearch/idunn
Expand All @@ -15,8 +9,31 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Extract branch name
if: github.event_name != 'pull_request'
run: |
REF=${GITHUB_REF#refs/*/}
if [ "$REF" == "master" ]; then
IMAGE_TAG=latest
else
# Replace '/' with '__'
IMAGE_TAG=${REF//\//__}
fi
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
- name: Extract branch name
if: github.event_name == 'pull_request'
run: |
echo "IMAGE_TAG=$GITHUB_HEAD_REF" >> $GITHUB_ENV
# extract branch name on pull request
- name: Print branch name
run: echo "${IMAGE_TAG}"

- name: Set env variables
run: |
echo "DOCKER_IMAGE=${DOCKER_IMAGE_BASENAME}:$IMAGE_TAG" >> $GITHUB_ENV
- name: Login to DockerHub
if: github.event_name == 'push'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
Expand All @@ -36,5 +53,7 @@ jobs:
- run: docker build --label "org.label-schema.vcs-ref=$GITHUB_SHA" -t $DOCKER_IMAGE .

- if: github.event_name == 'push'
run: docker push $DOCKER_IMAGE
- name: Docker push
if: github.event_name == 'push' || github.event_name == 'pull_request'
run: |
docker push $DOCKER_IMAGE
3 changes: 2 additions & 1 deletion idunn/api/categories.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .utils import Category
from pydantic import BaseModel, Field
from typing import List

from idunn.utils.category import Category


class CategoryDescription(BaseModel):
name: str = Field(..., description="Unique label of the category.")
Expand Down
2 changes: 1 addition & 1 deletion idunn/api/closest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from idunn.utils.es_wrapper import get_elasticsearch
from idunn.utils import prometheus
from idunn.places import Street, Address, Place
from idunn.api.utils import Verbosity
from idunn.datasources.mimirsbrunn import fetch_closest
from idunn.utils.verbosity import Verbosity

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion idunn/api/instant_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from idunn.utils.result_filter import ResultFilter
from idunn.instant_answer import normalize
from .constants import PoiSource
from .utils import Verbosity
from ..utils.verbosity import Verbosity

logger = logging.getLogger(__name__)
result_filter = ResultFilter()
Expand Down
2 changes: 1 addition & 1 deletion idunn/api/places.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@


from idunn import settings
from idunn.api.utils import Verbosity
from idunn.utils.es_wrapper import get_elasticsearch
from idunn.utils.covid19_dataset import covid19_osm_task
from idunn.places import Place, Latlon, place_from_id
from idunn.places.base import BasePlace
from idunn.places.exceptions import PlaceNotFound
from idunn.places.exceptions import RedirectToPlaceId, InvalidPlaceId
from .closest import get_closest_place
from ..utils.verbosity import Verbosity

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions idunn/api/places_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

from idunn import settings
from idunn.places import POI, BragiPOI
from idunn.api.utils import Verbosity
from idunn.datasources.mimirsbrunn import fetch_es_pois, MimirPoiFilter
from idunn.datasources.pages_jaunes import pj_source
from idunn.geocoder.bragi_client import bragi_client
from .constants import PoiSource, ALL_POI_SOURCES
from .utils import Category
from ..utils.category import Category
from ..utils.verbosity import Verbosity

logger = logging.getLogger(__name__)

Expand Down
172 changes: 0 additions & 172 deletions idunn/api/utils.py

This file was deleted.

2 changes: 1 addition & 1 deletion idunn/datasources/pages_jaunes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from requests import HTTPError as RequestsHTTPError

from idunn import settings
from idunn.api.utils import CategoryEnum
from idunn.places.exceptions import PlaceNotFound
from idunn.places.models import pj_info, pj_find
from idunn.places.pj_poi import PjApiPOI
from idunn.utils.auth_session import AuthSession
from idunn.utils.category import CategoryEnum
from idunn.utils.geometry import bbox_inside_polygon, france_polygon

logger = logging.getLogger(__name__)
Expand Down
13 changes: 12 additions & 1 deletion idunn/geocoder/models/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
https://github.com/CanalTP/mimirsbrunn/blob/master/libs/bragi/src/routes/autocomplete.rs#L59
"""
import json
from enum import Enum

from geojson_pydantic.features import Feature
from typing import List, Optional
from fastapi import Query
from pydantic import BaseModel, Field, confloat, conint
from pydantic.dataclasses import dataclass

from idunn import settings
from idunn.api.utils import Type
from idunn.utils.math import with_precision
from .cosmogony import ZoneType

Expand All @@ -19,6 +20,16 @@
FOCUS_DECAY = float(settings["FOCUS_DECAY"])


class Type(str, Enum):
# pylint: disable=invalid-name
# City = "city" # this field is available in Bragi but deprecated
House = "house"
Poi = "poi"
StopArea = "public_transport:stop_area"
Street = "street"
Zone = "zone"


@dataclass
class QueryParams:
q: str = Query(..., title="Query string")
Expand Down
2 changes: 1 addition & 1 deletion idunn/geocoder/nlu_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from unidecode import unidecode

from idunn.api.places_list import MAX_HEIGHT, MAX_WIDTH
from idunn.api.utils import Category
from idunn.geocoder.models.params import QueryParams as GeocoderParams
from idunn import settings
from idunn.utils.circuit_breaker import IdunnCircuitBreaker
from idunn.utils.result_filter import ResultFilter

from .models.geocodejson import Intention, IntentionType
from .bragi_client import bragi_client
from ..utils.category import Category

logger = logging.getLogger(__name__)
result_filter = ResultFilter()
Expand Down
2 changes: 1 addition & 1 deletion idunn/places/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pytz import timezone, UTC
from typing import Optional, Union

from idunn.api.utils import Verbosity, build_blocks
from ..utils.verbosity import build_blocks, Verbosity
from idunn.datasources.wiki_es import wiki_es
from idunn.utils import maps_urls, tz
from .place import Place, PlaceMeta
Expand Down
27 changes: 26 additions & 1 deletion idunn/places/poi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@

from .base import BasePlace
from idunn import settings
from idunn.api.utils import get_name
from idunn.api.constants import PoiSource

OSM_CONTRIBUTION_HASHTAGS = settings["OSM_CONTRIBUTION_HASHTAGS"]


def get_name(properties, lang):
"""
Return the Place name from the properties field of the elastic response. Here 'name'
corresponds to the POI name in the language of the user request (i.e. 'name:{lang}' field).
If lang is None or if name:lang is not in the properties then name receives the local name
value.
>>> get_name({}, 'fr') is None
True
>>> get_name({'name':'spontini', 'name:en':'spontinien', 'name:fr':'spontinifr'}, None)
'spontini'
>>> get_name({'name':'spontini', 'name:en':'spontinien', 'name:fr':'spontinifr'}, 'cz')
'spontini'
>>> get_name({'name':'spontini', 'name:en':'spontinien', 'name:fr':'spontinifr'}, 'fr')
'spontinifr'
"""
name = properties.get(f"name:{lang}")
if name is None:
name = properties.get("name")
return name


class POI(BasePlace):
PLACE_TYPE = "poi"

Expand Down
Loading

0 comments on commit eff28c5

Please sign in to comment.