From 3d49b8d0fe961514ef4ecf3ed44f2aef9a17a13d Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 20 Mar 2024 10:29:38 -0700 Subject: [PATCH 01/16] safely convert ini parameters to bool and int --- pyramid_celery/loaders.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pyramid_celery/loaders.py b/pyramid_celery/loaders.py index 199a8d6..b186446 100644 --- a/pyramid_celery/loaders.py +++ b/pyramid_celery/loaders.py @@ -91,6 +91,18 @@ 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: + if float(value).is_integer(): + return int(value) + return float(value) + except ValueError: + 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 From 1855c90b83246b9ef17514ef96b797bfd8ad1b15 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 20 Mar 2024 10:54:41 -0700 Subject: [PATCH 02/16] added gitlab-ci --- .gitlab-ci.yml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..cceb508 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,43 @@ +image: python:latest + +variables: + PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" + # + PUBLIC_REGISTRY_PROJECT_ID: 32304092 + +cache: + paths: + - .cache/pip + - venv/ + +before_script: + - python -V # Print out python version for debugging + - pip install flake8 flake8-logging-format + +flake8: + script: + - flake8 --exit-zero --format pylint --output-file flake8.txt --tee flake8_gitlab_codeclimate scripts + - PYTHONPATH=. python scripts/report-to-gl-codeclimate.py < flake8.txt > gl-code-quality-report.json + 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: + script: + - env + - pip install twine + - python setup.py bdist_wheel + - 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: + script: + - env + - pip install twine + - python setup.py bdist_wheel + - 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/* From 2daf286feb2b80de49d8c318d0a829ad78dbc168 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 20 Mar 2024 11:00:20 -0700 Subject: [PATCH 03/16] bump-version --- .gitlab-ci.yml | 17 ++++++++--------- setup.py | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cceb508..b138f95 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,21 +12,20 @@ cache: before_script: - python -V # Print out python version for debugging - - pip install flake8 flake8-logging-format -flake8: +ruff: script: - - flake8 --exit-zero --format pylint --output-file flake8.txt --tee flake8_gitlab_codeclimate scripts - - PYTHONPATH=. python scripts/report-to-gl-codeclimate.py < flake8.txt > gl-code-quality-report.json + - pip install ruff + - ruff --output-format=gitlab --output-file gl-code-quality-report.json pyrmaid_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 +# 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: script: diff --git a/setup.py b/setup.py index 38dc01a..ba365c2 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.1', description='Celery integration with pyramid', long_description=README + "\n" + CHANGES, classifiers=[ From 04482bb07801a17ce0ff1aa9103ff550653fdb27 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 20 Mar 2024 11:03:38 -0700 Subject: [PATCH 04/16] uses stages --- .gitlab-ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b138f95..0c8ea0d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -10,10 +10,15 @@ cache: - .cache/pip - venv/ +stages: + check + deploy + before_script: - python -V # Print out python version for debugging ruff: + stage: check script: - pip install ruff - ruff --output-format=gitlab --output-file gl-code-quality-report.json pyrmaid_celery @@ -27,7 +32,8 @@ ruff: # - flake8 --exit-zero --format gl-codeclimate --output-file examples-report.json --tee examples/ # - python -m json.tool < examples-report.json -deploy: +deploy_local: + stage: deploy script: - env - pip install twine @@ -35,6 +41,7 @@ deploy: - 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 From d69eb196740e52e73cadbb86b247186a519cf5a5 Mon Sep 17 00:00:00 2001 From: kris kvilekval Date: Wed, 20 Mar 2024 18:04:14 +0000 Subject: [PATCH 05/16] Update .gitlab-ci.yml file --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0c8ea0d..09330fd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,8 +11,8 @@ cache: - venv/ stages: - check - deploy + - check + - deploy before_script: - python -V # Print out python version for debugging From 398b9d1a728f88ef79c20e847417fbeb9ffe112a Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 20 Mar 2024 11:10:31 -0700 Subject: [PATCH 06/16] typo --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 09330fd..063b4e1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,7 +21,7 @@ ruff: stage: check script: - pip install ruff - - ruff --output-format=gitlab --output-file gl-code-quality-report.json pyrmaid_celery + - ruff check --output-format=gitlab --output-file gl-code-quality-report.json pyramid_celery artifacts: reports: codequality: gl-code-quality-report.json From 01f883afe5a529293e3eaae7d899a76bc23e468c Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 20 Mar 2024 11:20:41 -0700 Subject: [PATCH 07/16] bump version; user build --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ba365c2..4238e52 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ requires = ['pyramid', 'celery'] setup(name='pyramid_celery', - version='4.0.1', + version='4.0.2', description='Celery integration with pyramid', long_description=README + "\n" + CHANGES, classifiers=[ From 16c4dd8f996a47d6e88a15226f9e1326bbe9b9fa Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 20 Mar 2024 16:31:04 -0700 Subject: [PATCH 08/16] install build --- .gitlab-ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 063b4e1..4ddacf0 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -36,14 +36,14 @@ deploy_local: stage: deploy script: - env - - pip install twine - - python setup.py bdist_wheel + - 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 - - python setup.py bdist_wheel + - 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/* From 38ed887004350120887d5a292c1aaff19066499a Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 22 May 2024 15:49:05 -0700 Subject: [PATCH 09/16] added json5 decoding for structures --- pyramid_celery/loaders.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pyramid_celery/loaders.py b/pyramid_celery/loaders.py index b186446..d648be4 100644 --- a/pyramid_celery/loaders.py +++ b/pyramid_celery/loaders.py @@ -1,5 +1,7 @@ import datetime import json +import pyjson5 as json5 +from pyjson5 import Json5DecoderException as JSONDecodeError import celery.loaders.base import celery.schedules import configparser @@ -93,6 +95,13 @@ def get_route_config(parser, section): def safe_conversion(value): """convert a string to a more specific type""" + try: + newval= json5.loads(value) + #print("JSON DECODED", type(newval), newval) + return newval + except JSONDecodeError: + pass + if value.lower() in ("true", "false"): return bool(value) try: From 8bcc9f0869b2c47b826aba63d0de95aad0817600 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Wed, 22 May 2024 15:59:06 -0700 Subject: [PATCH 10/16] bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4238e52..57bd683 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ requires = ['pyramid', 'celery'] setup(name='pyramid_celery', - version='4.0.2', + version='4.0.3', description='Celery integration with pyramid', long_description=README + "\n" + CHANGES, classifiers=[ From 62110dc429e5a8febececab9d8d863c7103084b4 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Thu, 23 May 2024 16:17:41 -0700 Subject: [PATCH 11/16] use ast literal_eval --- pyramid_celery/loaders.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/pyramid_celery/loaders.py b/pyramid_celery/loaders.py index d648be4..cbfc7b0 100644 --- a/pyramid_celery/loaders.py +++ b/pyramid_celery/loaders.py @@ -1,7 +1,6 @@ import datetime import json -import pyjson5 as json5 -from pyjson5 import Json5DecoderException as JSONDecodeError +from ast import literal_eval import celery.loaders.base import celery.schedules import configparser @@ -95,13 +94,6 @@ def get_route_config(parser, section): def safe_conversion(value): """convert a string to a more specific type""" - try: - newval= json5.loads(value) - #print("JSON DECODED", type(newval), newval) - return newval - except JSONDecodeError: - pass - if value.lower() in ("true", "false"): return bool(value) try: @@ -109,7 +101,12 @@ def safe_conversion(value): return int(value) return float(value) except ValueError: - return value + pass + try: + return literal_eval(value) + except ValueError: + pass + return value class INILoader(celery.loaders.base.BaseLoader): From 80863e8d43a0b4fe08d20e98140e47067190c387 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Thu, 23 May 2024 20:40:25 -0700 Subject: [PATCH 12/16] version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 57bd683..c8b5a93 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ requires = ['pyramid', 'celery'] setup(name='pyramid_celery', - version='4.0.3', + version='4.0.4', description='Celery integration with pyramid', long_description=README + "\n" + CHANGES, classifiers=[ From c33729e434e4bada0d29e3574419d82ef748fa24 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Fri, 19 Jul 2024 23:20:15 -0700 Subject: [PATCH 13/16] remove redundant converstion --- pyramid_celery/loaders.py | 6 ------ setup.py | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/pyramid_celery/loaders.py b/pyramid_celery/loaders.py index cbfc7b0..687a0e3 100644 --- a/pyramid_celery/loaders.py +++ b/pyramid_celery/loaders.py @@ -96,12 +96,6 @@ def safe_conversion(value): """convert a string to a more specific type""" if value.lower() in ("true", "false"): return bool(value) - try: - if float(value).is_integer(): - return int(value) - return float(value) - except ValueError: - pass try: return literal_eval(value) except ValueError: diff --git a/setup.py b/setup.py index c8b5a93..0fbcdad 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ requires = ['pyramid', 'celery'] setup(name='pyramid_celery', - version='4.0.4', + version='4.0.5', description='Celery integration with pyramid', long_description=README + "\n" + CHANGES, classifiers=[ From ee3042daac3709237dfd8335dda47b8469b2d131 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Mon, 22 Jul 2024 21:30:48 -0700 Subject: [PATCH 14/16] catch all ast errors --- pyramid_celery/loaders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid_celery/loaders.py b/pyramid_celery/loaders.py index 687a0e3..92b2ea9 100644 --- a/pyramid_celery/loaders.py +++ b/pyramid_celery/loaders.py @@ -98,7 +98,7 @@ def safe_conversion(value): return bool(value) try: return literal_eval(value) - except ValueError: + except ValueError,SyntaxError,TypeError,MemoryError,RecursionError: pass return value From 37d6880f2d9235d4a1acd796135b253a8ada106b Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Mon, 22 Jul 2024 21:31:24 -0700 Subject: [PATCH 15/16] bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0fbcdad..a5a51b1 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ requires = ['pyramid', 'celery'] setup(name='pyramid_celery', - version='4.0.5', + version='4.0.6', description='Celery integration with pyramid', long_description=README + "\n" + CHANGES, classifiers=[ From 656744f82c519242e096d513540efa8fc859c677 Mon Sep 17 00:00:00 2001 From: Kris Kvilekval Date: Mon, 22 Jul 2024 21:33:15 -0700 Subject: [PATCH 16/16] parens about exc --- pyramid_celery/loaders.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyramid_celery/loaders.py b/pyramid_celery/loaders.py index 92b2ea9..b01bfdf 100644 --- a/pyramid_celery/loaders.py +++ b/pyramid_celery/loaders.py @@ -98,7 +98,7 @@ def safe_conversion(value): return bool(value) try: return literal_eval(value) - except ValueError,SyntaxError,TypeError,MemoryError,RecursionError: + except (ValueError,SyntaxError,TypeError,MemoryError,RecursionError): pass return value