From 37772e88f3bba7ee4268359d13980e93d29eeaf5 Mon Sep 17 00:00:00 2001 From: Muhammad Farhan Date: Wed, 18 Sep 2024 19:11:58 +0500 Subject: [PATCH] fix: testing fix 101 --- pylint_django_settings.py | 39 ++++++++++++++++++++++++++++++++++++++- pylintrc | 10 +++++----- pylintrc_tweaks | 2 +- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/pylint_django_settings.py b/pylint_django_settings.py index 75ceab2505f7..549ef44950ac 100644 --- a/pylint_django_settings.py +++ b/pylint_django_settings.py @@ -55,5 +55,42 @@ def open(self): name_checker.config.django_settings_module = 'lms.envs.test' +def _get_django_settings_module(arguments): + # pylint command should not run with modules from both cms and (lms, common) at once + cms_module = False + lms_module = False + common_module = False + + for arg in arguments: + if arg.startswith('cms'): + cms_module = True + elif arg.startswith('lms'): + lms_module = True + elif arg.startswith('common'): + common_module = True + + if cms_module and (lms_module or common_module): + # when cms module is present in pylint command, it can't be parired with (lms, common) + # as common and lms gives error with cms test settings + raise ArgumentCompatibilityError( + "Modules from both common and lms can't be paired with cms while running pylint" + ) + elif cms_module: + # If a module from cms is present in pylint command arguments + # and ony other module from (openedx, pavelib) is present + # than test setting of cms is used + return 'cms.envs.test' + else: + # If any module form (lms, common, openedx, pavelib) is present in + # pylint command arguments than test setting of lms is used + return 'lms.envs.test' + + def register(linter): - linter.register_checker(SetDjangoSettingsChecker(linter)) + """Required function to register the plugin.""" + pass + + +def load_configuration(linter): + name_checker = get_checker(linter, ForeignKeyStringsChecker) + name_checker.config.django_settings_module = _get_django_settings_module(linter.cmdline_parser.parse_args()[1]) diff --git a/pylintrc b/pylintrc index 96b657e46eea..43ce9fe81495 100644 --- a/pylintrc +++ b/pylintrc @@ -64,18 +64,18 @@ # SERIOUSLY. # # ------------------------------ -# Generated by edx-lint version: 5.3.0 +# Generated by edx-lint version: 5.3.7 # ------------------------------ [MASTER] ignore = ,.git,.tox,migrations,node_modules,.pycharm_helpers persistent = yes -load-plugins = edx_lint.pylint,pylint_django,pylint_celery,pylint_pytest +load-plugins = edx_lint.pylint,pylint_django_settings,pylint_django,pylint_celery,pylint_pytest [MESSAGES CONTROL] enable = blacklisted-name, line-too-long, - + abstract-class-instantiated, abstract-method, access-member-before-definition, @@ -407,6 +407,6 @@ ext-import-graph = int-import-graph = [EXCEPTIONS] -overgeneral-exceptions = Exception +overgeneral-exceptions = builtins.Exception -# 567bf30b121db79bc07a7028651f7efa0724e8a4 +# e624ea03d8124aa9cf2e577f830632344a0a07d9 diff --git a/pylintrc_tweaks b/pylintrc_tweaks index 7911c08af9b2..1633da5c10a4 100644 --- a/pylintrc_tweaks +++ b/pylintrc_tweaks @@ -1,7 +1,7 @@ # pylintrc tweaks for use with edx_lint. [MASTER] ignore+ = ,.git,.tox,migrations,node_modules,.pycharm_helpers -load-plugins = edx_lint.pylint,pylint_django,pylint_celery,pylint_pytest +load-plugins = edx_lint.pylint,pylint_django_settings,pylint_django,pylint_celery,pylint_pytest [MESSAGES CONTROL] disable+ =