Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit ed2ce04

Browse files
committed
🔨 remove usage of distutils for future releases deprecation
1 parent 0b3b88f commit ed2ce04

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

cube_builder/celery/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"""Define Cube Builder celery module initialization."""
2020

2121
import logging
22+
import os
2223

2324
import flask
2425
from bdc_catalog.models import db
@@ -27,6 +28,7 @@
2728
from flask import Flask
2829

2930
from cube_builder.config import Config
31+
from ..constants import to_bool
3032

3133
CELERY_TASKS = [
3234
'cube_builder.celery.tasks',
@@ -59,6 +61,7 @@ def create_celery_app(flask_app: Flask) -> Celery:
5961

6062
always_eager = flask_app.config.get('TESTING', False)
6163
celery.conf.update(dict(
64+
CELERY_ACKS_LATE=to_bool(os.getenv('CELERY_ACKS_LATE', '1')),
6265
CELERY_TASK_ALWAYS_EAGER=always_eager,
6366
CELERYD_PREFETCH_MULTIPLIER=Config.CELERYD_PREFETCH_MULTIPLIER,
6467
CELERY_RESULT_BACKEND='db+{}'.format(flask_app.config.get('SQLALCHEMY_DATABASE_URI')),

cube_builder/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"""Brazil Data Cube Configuration."""
1919

2020
import os
21-
from distutils.util import strtobool
2221

2322
from .version import __version__
23+
from .constants import to_bool
2424

2525
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
2626

@@ -99,7 +99,7 @@ class Config:
9999
BDC_AUTH_ACCESS_TOKEN_URL = os.getenv('BDC_AUTH_ACCESS_TOKEN_URL', None)
100100
"""Access token url used for retrieving user info in BDC-Auth
101101
Defaults to ``None``. Used when ``BDC_AUTH_REQUIRED`` is set."""
102-
BDC_AUTH_REQUIRED = strtobool(os.getenv('BDC_AUTH_REQUIRED', '0'))
102+
BDC_AUTH_REQUIRED = to_bool(os.getenv('BDC_AUTH_REQUIRED', '0'))
103103
"""Flag to manage when a Auth is required.
104104
Defaults to ``0``, that means that there is not authorization request to access ``Cube Builder`` API."""
105105

cube_builder/constants.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,25 @@
7777
PNG_MIME_TYPE = 'image/png'
7878

7979
SRID_ALBERS_EQUAL_AREA = 100001
80+
81+
82+
def to_bool(val: str):
83+
"""Convert a string representation to true or false.
84+
85+
This method was adapted from `pypa/distutils <https://github.com/pypa/distutils>`_
86+
to avoid import deprecated module.
87+
88+
The following values are supported:
89+
- ``True``: 'y', 'yes', 't', 'true', 'on', and '1'
90+
- ``False``: 'n', 'no', 'f', 'false', 'off', and '0'
91+
92+
Raises:
93+
ValueError: When the given string value could not be converted to boolean.
94+
"""
95+
val = val.lower()
96+
if val in ('y', 'yes', 't', 'true', 'on', '1',):
97+
return 1
98+
elif val in ('n', 'no', 'f', 'false', 'off', '0',):
99+
return 0
100+
101+
raise ValueError(f"invalid boolean value for {val}")

0 commit comments

Comments
 (0)