diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..4ddacf0 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,49 @@ +image: python:latest + +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + # + PUBLIC_REGISTRY_PROJECT_ID: 32304092 + +cache: + paths: + - .cache/pip + - venv/ + +stages: + - check + - deploy + +before_script: + - python -V # Print out python version for debugging + +ruff: + stage: check + script: + - pip install ruff + - ruff check --output-format=gitlab --output-file gl-code-quality-report.json pyramid_celery + artifacts: + reports: + codequality: gl-code-quality-report.json + +# test: +# script: +# - pip install . +# - flake8 --exit-zero --format gl-codeclimate --output-file examples-report.json --tee examples/ +# - python -m json.tool < examples-report.json + +deploy_local: + stage: deploy + script: + - env + - pip install twine build + - python -m build -w + - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/* + +deploy_public: + stage: deploy + script: + - env + - pip install twine build + - python -m build -w + - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${PUBLIC_REGISTRY_PROJECT_ID}/packages/pypi dist/* diff --git a/pyramid_celery/loaders.py b/pyramid_celery/loaders.py index 199a8d6..b01bfdf 100644 --- a/pyramid_celery/loaders.py +++ b/pyramid_celery/loaders.py @@ -1,5 +1,6 @@ import datetime import json +from ast import literal_eval import celery.loaders.base import celery.schedules import configparser @@ -91,6 +92,17 @@ def get_route_config(parser, section): return config +def safe_conversion(value): + """convert a string to a more specific type""" + if value.lower() in ("true", "false"): + return bool(value) + try: + return literal_eval(value) + except (ValueError,SyntaxError,TypeError,MemoryError,RecursionError): + pass + return value + + class INILoader(celery.loaders.base.BaseLoader): ConfigParser = configparser.SafeConfigParser @@ -106,7 +118,7 @@ def read_configuration(self, fail_silently=True): config_dict = {} for key, value in self.parser.items('celery'): - config_dict[key] = value + config_dict[key] = safe_conversion(value) if celery_version.major > 6: # TODO: Check for invalid settings diff --git a/setup.py b/setup.py index 38dc01a..a5a51b1 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ requires = ['pyramid', 'celery'] setup(name='pyramid_celery', - version='4.0.0', + version='4.0.6', description='Celery integration with pyramid', long_description=README + "\n" + CHANGES, classifiers=[