Skip to content

Commit

Permalink
Merge pull request #949 from opendatacube/ci-updates
Browse files Browse the repository at this point in the history
Repo maintenance
  • Loading branch information
SpacemanPaul authored Aug 29, 2023
2 parents 0ca9b9a + d573414 commit e08f9cc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 23 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
args: ["--ignore=E501", "--select=F401,E201,E202,E203,E502,E241,E225,E306,E231,E226,E123,F811"]
Expand All @@ -19,7 +19,7 @@ repos:
# hooks:
# - id: bandit
- repo: https://github.com/PyCQA/pylint
rev: v2.17.0
rev: v3.0.0a7
hooks:
- id: pylint
args: ["--disable=C,R,W,E1136"]
5 changes: 3 additions & 2 deletions datacube_ows/ogc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from flask import g, render_template, request
from flask_log_request_id import current_request_id
from sqlalchemy import text

from datacube_ows import __version__
from datacube_ows.cube_pool import cube
Expand Down Expand Up @@ -183,10 +184,10 @@ def ping():
if dc:
# pylint: disable=protected-access
with dc.index._db.give_me_a_connection() as conn:
results = conn.execute("""
results = conn.execute(text("""
SELECT *
FROM wms.product_ranges
LIMIT 1"""
LIMIT 1""")
)
for r in results:
db_ok = True
Expand Down
13 changes: 5 additions & 8 deletions datacube_ows/startup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
'parse_config_file',
'initialise_flask',
'initialise_prometheus',
'generate_locale_selector',
'CredentialManager',
]

Expand Down Expand Up @@ -218,21 +217,19 @@ def request_extractor():
qreq = request.args.get('request')
return qreq

def generate_locale_selector(locales):
def selector_template():
return request.accept_languages.best_match(locales)
return selector_template

def initialise_babel(cfg, app):
if cfg and cfg.internationalised:
from flask_babel import Babel
app.config["BABEL_TRANSLATION_DIRECTORIES"] = cfg.translations_dir

def get_locale():
return request.accept_languages.best_match(cfg.locales, default=cfg.locales[0])

babel = Babel(app,
default_locale=cfg.locales[0],
locale_selector=get_locale,
default_domain=cfg.message_domain,
configure_jinja=False
)
babel.localeselector(generate_locale_selector(cfg.locales))
return babel
else:
return None
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
'lxml',
'deepdiff',
'matplotlib',
'pyparsing>=2.2.1,<3', # resolving dependency conflict between matplotlib and packaging
'pyparsing',
'numpy',
'scipy',
'Pillow',
'Babel',
'Flask-Babel<3.0.0', # API change in 3.0
'Flask-Babel>3.0.0', # New API in 3.x, bug in 3.0.0
'psycopg2',
'python_dateutil',
'pytz',
Expand All @@ -35,7 +35,7 @@
'python_slugify',
'geoalchemy2',
'lark',
'xarray!=2022.6.0',
'xarray',
'pyows',
'prometheus_flask_exporter',
'setuptools_scm'
Expand Down
8 changes: 0 additions & 8 deletions tests/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ def test_supported_version():
assert supported["wms"].versions[0].service == "wms"


def test_generate_locale_sel():
app = flask.Flask("test_generate_locale_selector")
from datacube_ows.startup_utils import generate_locale_selector
with app.test_request_context(headers={"Accept-Language": "sw, fr;q=0.7, de;q=0.2"}):
selector = generate_locale_selector(["en", "de", "sw"])
assert selector() == "sw"


@pytest.fixture
def babel_cfg():
cfg = MagicMock()
Expand Down

0 comments on commit e08f9cc

Please sign in to comment.