From dd0ca644d7546df0cd53518a9717ef29a1b845be Mon Sep 17 00:00:00 2001 From: Arbab Khalil Date: Fri, 12 Jan 2024 15:50:50 +0000 Subject: [PATCH] chore: add reserved keywords linter (#144) --- .github/workflows/ci.yml | 2 +- Makefile | 5 ++++- db_keyword_overrides.yml | 10 ++++++++++ requirements/doc.txt | 8 +++++++- requirements/quality.txt | 5 +++++ requirements/test.in | 1 + requirements/test.txt | 11 +++++++++-- test_settings.py | 1 + tox.ini | 7 +++++++ 9 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 db_keyword_overrides.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 165dad9..c03c834 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,7 @@ jobs: matrix: os: [ubuntu-20.04] python-version: ['3.8'] - toxenv: [quality, django32, django42] + toxenv: [quality, django32, django42, check_keywords] steps: - uses: actions/checkout@v4 - name: setup pythons diff --git a/Makefile b/Makefile index 1ee9781..26e3493 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: clean compile_translations coverage diff_cover docs dummy_translations \ extract_translations fake_translations help pii_check pull_translations push_translations \ - quality requirements selfcheck test test-all upgrade validate + quality requirements selfcheck test test-all upgrade validate check_keywords .DEFAULT_GOAL := help @@ -123,3 +123,6 @@ dummy_translations: ## generate dummy translation (.po) files build_dummy_translations: extract_translations dummy_translations compile_translations ## generate and compile dummy translation files validate_translations: build_dummy_translations detect_changed_source_translations ## validate translations + +check_keywords: ## Scan the Django models in all installed apps in this project for restricted field names + python manage.py check_reserved_keywords --override_file db_keyword_overrides.yml diff --git a/db_keyword_overrides.yml b/db_keyword_overrides.yml new file mode 100644 index 0000000..dcc39cd --- /dev/null +++ b/db_keyword_overrides.yml @@ -0,0 +1,10 @@ +# This file is used by the 'check_reserved_keywords' management command to allow specific field names to be overridden +# when checking for conflicts with lists of restricted keywords used in various database/data warehouse tools. +# For more information, see: https://github.com/edx/edx-django-release-util/release_util/management/commands/check_reserved_keywords.py +# +# overrides should be added in the following format: +# - ModelName.field_name +--- +MYSQL: +SNOWFLAKE: +STITCH: diff --git a/requirements/doc.txt b/requirements/doc.txt index 06be330..95d9919 100644 --- a/requirements/doc.txt +++ b/requirements/doc.txt @@ -58,6 +58,7 @@ django==3.2.23 # django-waffle # djangorestframework # drf-jwt + # edx-django-release-util # edx-django-utils # edx-drf-extensions django-crum==0.7.9 @@ -89,6 +90,8 @@ drf-jwt==1.19.2 # via # -r requirements/test.txt # edx-drf-extensions +edx-django-release-util==1.3.0 + # via -r requirements/test.txt edx-django-utils==5.9.0 # via # -r requirements/test.txt @@ -198,6 +201,7 @@ pyyaml==6.0.1 # via # -r requirements/test.txt # code-annotations + # edx-django-release-util readme-renderer==42.0 # via -r requirements/doc.in requests==2.31.0 @@ -212,7 +216,9 @@ semantic-version==2.10.0 # -r requirements/test.txt # edx-drf-extensions six==1.16.0 - # via -r requirements/test.txt + # via + # -r requirements/test.txt + # edx-django-release-util snowballstemmer==2.2.0 # via sphinx soupsieve==2.5 diff --git a/requirements/quality.txt b/requirements/quality.txt index 1cacf2f..53605cc 100644 --- a/requirements/quality.txt +++ b/requirements/quality.txt @@ -60,6 +60,7 @@ django==3.2.23 # django-waffle # djangorestframework # drf-jwt + # edx-django-release-util # edx-django-utils # edx-drf-extensions django-crum==0.7.9 @@ -82,6 +83,8 @@ drf-jwt==1.19.2 # via # -r requirements/test.txt # edx-drf-extensions +edx-django-release-util==1.3.0 + # via -r requirements/test.txt edx-django-utils==5.9.0 # via # -r requirements/test.txt @@ -202,6 +205,7 @@ pyyaml==6.0.1 # via # -r requirements/test.txt # code-annotations + # edx-django-release-util requests==2.31.0 # via # -r requirements/test.txt @@ -213,6 +217,7 @@ semantic-version==2.10.0 six==1.16.0 # via # -r requirements/test.txt + # edx-django-release-util # edx-lint snowballstemmer==2.2.0 # via pydocstyle diff --git a/requirements/test.in b/requirements/test.in index ec6bf53..23d4971 100644 --- a/requirements/test.in +++ b/requirements/test.in @@ -7,3 +7,4 @@ pytest-cov # pytest extension for code coverage statistics pytest-django # pytest extension for better Django support code-annotations # provides commands used by the pii_check make target. ddt +edx-django-release-util # Contains the reserved keyword check diff --git a/requirements/test.txt b/requirements/test.txt index 43c2213..44ef626 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -46,6 +46,7 @@ ddt==1.7.0 # django-waffle # djangorestframework # drf-jwt + # edx-django-release-util # edx-django-utils # edx-drf-extensions django-crum==0.7.9 @@ -68,6 +69,8 @@ drf-jwt==1.19.2 # via # -r requirements/base.txt # edx-drf-extensions +edx-django-release-util==1.3.0 + # via -r requirements/test.in edx-django-utils==5.9.0 # via # -r requirements/base.txt @@ -140,7 +143,9 @@ pytz==2023.3.post1 # django # djangorestframework pyyaml==6.0.1 - # via code-annotations + # via + # code-annotations + # edx-django-release-util requests==2.31.0 # via # -r requirements/base.txt @@ -150,7 +155,9 @@ semantic-version==2.10.0 # -r requirements/base.txt # edx-drf-extensions six==1.16.0 - # via -r requirements/base.txt + # via + # -r requirements/base.txt + # edx-django-release-util sqlparse==0.4.4 # via # -r requirements/base.txt diff --git a/test_settings.py b/test_settings.py index b5c5753..fd369c5 100644 --- a/test_settings.py +++ b/test_settings.py @@ -31,6 +31,7 @@ def root(*args): 'django.contrib.contenttypes', 'edx_rbac', 'tests', + 'release_util', ) LOCALE_PATHS = [ diff --git a/tox.ini b/tox.ini index 65fb8cf..a6febf8 100644 --- a/tox.ini +++ b/tox.ini @@ -70,3 +70,10 @@ deps = commands = code_annotations django_find_annotations --config_file .pii_annotations.yml --lint --report --coverage +[testenv:check_keywords] +allowlist_externals = + make +deps = + -r{toxinidir}/requirements/test.txt +commands = + make check_keywords