microsoft / vscode-pylint

Linting support for python using the pylint library.
https://marketplace.visualstudio.com/items?itemName=ms-python.pylint
MIT License
70 stars 34 forks source link

Problem with extension in vscode/cursor #546

Closed rlemayd closed 5 months ago

rlemayd commented 5 months ago

Diagnostic Data

Behaviour

Expected Behavior

Don't get errors

Actual Behavior

Getting popup with error everytime i save a file, or change the interpreter

Reproduction Steps:

Save a file or change interpreter is how is happening to me

Logs:

Click here for detailed logs 2024-04-10 16:38:22.007 [info] No interpreter found from setting pylint.interpreter 2024-04-10 16:38:22.007 [info] Getting interpreter from ms-python.python extension for workspace /Users/richard/Documents/GitHub/bci_wholesale 2024-04-10 16:38:22.011 [info] Interpreter from ms-python.python extension for /Users/richard/Documents/GitHub/bci_wholesale: /Users/richard/Documents/GitHub/bci_wholesale/.venv/bin/python 2024-04-10 16:38:22.013 [info] Server: Stop requested 2024-04-10 16:38:22.013 [debug] Server State: Stopped 2024-04-10 16:38:22.013 [info] [Trace - 4:38:22 PM] Sending request 'shutdown - (2)'. 2024-04-10 16:38:22.033 [info] [Trace - 4:38:22 PM] Received response 'shutdown - (2)' in 22ms. 2024-04-10 16:38:22.033 [info] No result returned. 2024-04-10 16:38:22.033 [info] [Trace - 4:38:22 PM] Sending notification 'exit'. 2024-04-10 16:38:22.033 [info] No parameters provided. 2024-04-10 16:38:22.039 [info] No interpreter found from setting pylint.interpreter 2024-04-10 16:38:22.039 [info] Getting interpreter from ms-python.python extension for workspace /Users/richard/Documents/GitHub/bci_wholesale 2024-04-10 16:38:22.042 [info] Interpreter from ms-python.python extension for /Users/richard/Documents/GitHub/bci_wholesale: /Users/richard/Documents/GitHub/bci_wholesale/.venv/bin/python 2024-04-10 16:38:22.050 [info] Server run command: /Users/richard/Documents/GitHub/bci_wholesale/.venv/bin/python /Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py 2024-04-10 16:38:22.051 [info] Server: Start requested. 2024-04-10 16:38:22.051 [debug] Server State: Starting 2024-04-10 16:38:22.554 [info] CWD Server: /Users/richard/Documents/GitHub/bci_wholesale 2024-04-10 16:38:22.555 [info] Settings used to run Server: [ { "cwd": "/Users/richard/Documents/GitHub/bci_wholesale", "workspace": "file:///Users/richard/Documents/GitHub/bci_wholesale", "args": [ "[ \"--load-plugins=pylint_django\", \"--django-settings-module=config.settings.local\", \"--disable=W0223,E1137\" ]" ], "severity": { "convention": "Information", "error": "Error", "fatal": "Error", "refactor": "Hint", "warning": "Warning", "info": "Information" }, "path": [], "ignorePatterns": [], "interpreter": [ "/Users/richard/Documents/GitHub/bci_wholesale/.venv/bin/python" ], "importStrategy": "useBundled", "showNotifications": "onWarning", "extraPaths": [] } ] 2024-04-10 16:38:22.555 [info] Global settings: { "cwd": "${workspaceFolder}", "workspace": "/", "args": [ "[ \"--load-plugins=pylint_django\", \"--django-settings-module=config.settings.local\", \"--disable=W0223,E1137\" ]" ], "severity": { "convention": "Information", "error": "Error", "fatal": "Error", "refactor": "Hint", "warning": "Warning", "info": "Information" }, "path": [], "ignorePatterns": [], "interpreter": [], "importStrategy": "useBundled", "showNotifications": "onWarning", "extraPaths": [] } 2024-04-10 16:38:22.555 [info] sys.path used to run Server: /Users/richard/Documents/GitHub/bci_wholesale /Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs /Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool /opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python311.zip /opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11 /opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload /Users/richard/Documents/GitHub/bci_wholesale/.venv/lib/python3.11/site-packages 2024-04-10 16:38:22.562 [info] /Users/richard/Documents/GitHub/bci_wholesale/.venv/bin/python -m pylint --version 2024-04-10 16:38:22.565 [info] CWD Linter: /Users/richard/Documents/GitHub/bci_wholesale 2024-04-10 16:38:22.680 [info] pylint 3.0.2 astroid 3.0.1 Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] 2024-04-10 16:38:22.680 [info] Version info for linter running for /Users/richard/Documents/GitHub/bci_wholesale: pylint 3.0.2 astroid 3.0.1 Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] 2024-04-10 16:38:22.680 [info] SUPPORTED pylint>=2.12.2 FOUND pylint==3.0.2 2024-04-10 16:38:22.682 [debug] Server State: Running 2024-04-10 16:38:22.690 [info] [Trace - 4:38:22 PM] Received notification 'window/logMessage'. 2024-04-10 16:38:22.690 [info] Params: { "type": 4, "message": "/Users/richard/Documents/GitHub/bci_wholesale/.venv/bin/python -m pylint --reports=n --output-format=json [ \"--load-plugins=pylint_django\", \"--django-settings-module=config.settings.local\", \"--disable=W0223,E1137\" ] --clear-cache-post-run=y --from-stdin /Users/richard/Documents/GitHub/bci_wholesale/bci_wholesale/statements/apis.py" } 2024-04-10 16:38:22.690 [info] /Users/richard/Documents/GitHub/bci_wholesale/.venv/bin/python -m pylint --reports=n --output-format=json [ "--load-plugins=pylint_django", "--django-settings-module=config.settings.local", "--disable=W0223,E1137" ] --clear-cache-post-run=y --from-stdin /Users/richard/Documents/GitHub/bci_wholesale/bci_wholesale/statements/apis.py 2024-04-10 16:38:22.690 [info] [Trace - 4:38:22 PM] Received notification 'window/logMessage'. 2024-04-10 16:38:22.690 [info] Params: { "type": 4, "message": "CWD Linter: /Users/richard/Documents/GitHub/bci_wholesale" } 2024-04-10 16:38:22.691 [info] CWD Linter: /Users/richard/Documents/GitHub/bci_wholesale 2024-04-10 16:38:23.030 [info] [Trace - 4:38:23 PM] Received notification 'window/logMessage'. 2024-04-10 16:38:23.030 [info] Params: { "type": 1, "message": "Traceback (most recent call last):\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py\", line 770, in _run_tool_on_document\n result = utils.run_module(\n ^^^^^^^^^^^^^^^^^\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py\", line 208, in run_module\n return _run_module(module, argv, use_stdin, source)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py\", line 193, in _run_module\n runpy.run_module(module, run_name=\"__main__\")\n File \"\", line 229, in run_module\n File \"\", line 88, in _run_code\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__main__.py\", line 10, in \n pylint.run_pylint()\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__init__.py\", line 34, in run_pylint\n PylintRun(argv or sys.argv[1:])\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/run.py\", line 211, in __init__\n linter.check(args)\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py\", line 665, in check\n raise exceptions.InvalidArgsError(\npylint.exceptions.InvalidArgsError: Missing filename required for --from-stdin\n" } 2024-04-10 16:38:23.031 [info] [Error - 4:38:23 PM] Traceback (most recent call last): File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py", line 770, in _run_tool_on_document result = utils.run_module( ^^^^^^^^^^^^^^^^^ File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py", line 208, in run_module return _run_module(module, argv, use_stdin, source) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py", line 193, in _run_module runpy.run_module(module, run_name="__main__") File "", line 229, in run_module File "", line 88, in _run_code File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__main__.py", line 10, in pylint.run_pylint() File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__init__.py", line 34, in run_pylint PylintRun(argv or sys.argv[1:]) File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/run.py", line 211, in __init__ linter.check(args) File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py", line 665, in check raise exceptions.InvalidArgsError( pylint.exceptions.InvalidArgsError: Missing filename required for --from-stdin 2024-04-10 16:38:23.032 [info] [Trace - 4:38:23 PM] Received notification 'window/showMessage'. 2024-04-10 16:38:23.032 [info] Params: { "type": 1, "message": "Traceback (most recent call last):\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py\", line 770, in _run_tool_on_document\n result = utils.run_module(\n ^^^^^^^^^^^^^^^^^\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py\", line 208, in run_module\n return _run_module(module, argv, use_stdin, source)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py\", line 193, in _run_module\n runpy.run_module(module, run_name=\"__main__\")\n File \"\", line 229, in run_module\n File \"\", line 88, in _run_code\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__main__.py\", line 10, in \n pylint.run_pylint()\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__init__.py\", line 34, in run_pylint\n PylintRun(argv or sys.argv[1:])\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/run.py\", line 211, in __init__\n linter.check(args)\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py\", line 665, in check\n raise exceptions.InvalidArgsError(\npylint.exceptions.InvalidArgsError: Missing filename required for --from-stdin\n" } 2024-04-10 16:38:23.032 [info] [Trace - 4:38:23 PM] Received notification 'window/logMessage'. 2024-04-10 16:38:23.032 [info] Params: { "type": 1, "message": "Linting failed with error:\r\nTraceback (most recent call last):\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py\", line 144, in _linting_helper\n result = _run_tool_on_document(document, use_stdin=True, extra_args=extra_args)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py\", line 770, in _run_tool_on_document\n result = utils.run_module(\n ^^^^^^^^^^^^^^^^^\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py\", line 208, in run_module\n return _run_module(module, argv, use_stdin, source)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py\", line 193, in _run_module\n runpy.run_module(module, run_name=\"__main__\")\n File \"\", line 229, in run_module\n File \"\", line 88, in _run_code\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__main__.py\", line 10, in \n pylint.run_pylint()\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__init__.py\", line 34, in run_pylint\n PylintRun(argv or sys.argv[1:])\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/run.py\", line 211, in __init__\n linter.check(args)\n File \"/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py\", line 665, in check\n raise exceptions.InvalidArgsError(\npylint.exceptions.InvalidArgsError: Missing filename required for --from-stdin\n" } 2024-04-10 16:38:23.032 [info] [Error - 4:38:23 PM] Linting failed with error: Traceback (most recent call last): File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py", line 144, in _linting_helper result = _run_tool_on_document(document, use_stdin=True, extra_args=extra_args) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_server.py", line 770, in _run_tool_on_document result = utils.run_module( ^^^^^^^^^^^^^^^^^ File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py", line 208, in run_module return _run_module(module, argv, use_stdin, source) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/tool/lsp_utils.py", line 193, in _run_module runpy.run_module(module, run_name="__main__") File "", line 229, in run_module File "", line 88, in _run_code File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__main__.py", line 10, in pylint.run_pylint() File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/__init__.py", line 34, in run_pylint PylintRun(argv or sys.argv[1:]) File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/run.py", line 211, in __init__ linter.check(args) File "/Users/richard/.cursor/extensions/ms-python.pylint-2023.10.1/bundled/libs/pylint/lint/pylinter.py", line 665, in check raise exceptions.InvalidArgsError( pylint.exceptions.InvalidArgsError: Missing filename required for --from-stdin 2024-04-10 16:38:23.033 [info] [Trace - 4:38:23 PM] Received notification 'textDocument/publishDiagnostics'. 2024-04-10 16:38:23.033 [info] Params: { "uri": "file:///Users/richard/Documents/GitHub/bci_wholesale/bci_wholesale/statements/apis.py", "diagnostics": [] }

Outcome When Attempting Debugging Steps:

Did running it from the command line work? didnt stop running

Extra Details

karthiknadig commented 5 months ago

Can you share your settings file?

rlemayd commented 5 months ago

Of the project? Because this happens on all my projects

karthiknadig commented 5 months ago

Yes of the project.

rlemayd commented 5 months ago

this is the base.py

"""
Base settings to build other settings files upon.
"""

from datetime import timedelta
from pathlib import Path

import environ

BASE_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
# materials_lab/
APPS_DIR = BASE_DIR / "materials_lab"
env = environ.Env()

READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
if READ_DOT_ENV_FILE:
    # OS environment variables take precedence over variables from .env
    env.read_env(str(BASE_DIR / ".env"))

# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = env.bool("DJANGO_DEBUG", False)
# Local time zone. Choices are
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# though not all of them may be available with every OS.
# In Windows, this must be set to your system time zone.
TIME_ZONE = "UTC"
# https://docs.djangoproject.com/en/dev/ref/settings/#language-code
LANGUAGE_CODE = "en-us"
# https://docs.djangoproject.com/en/dev/ref/settings/#languages
# from django.utils.translation import gettext_lazy as _
# LANGUAGES = [
#     ('en', _('English')),
#     ('fr-fr', _('French')),
#     ('pt-br', _('Portuguese')),
# ]
# https://docs.djangoproject.com/en/dev/ref/settings/#site-id
SITE_ID = 1
# https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n
USE_I18N = True
# https://docs.djangoproject.com/en/dev/ref/settings/#use-tz
USE_TZ = True
# https://docs.djangoproject.com/en/dev/ref/settings/#locale-paths
LOCALE_PATHS = [str(BASE_DIR / "locale")]

# DATABASES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
DATABASES = {"default": env.db("DATABASE_URL")}
DATABASES["default"]["ATOMIC_REQUESTS"] = True
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# URLS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
ROOT_URLCONF = "config.urls"
# https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application
WSGI_APPLICATION = "config.wsgi.application"

# APPS
# ------------------------------------------------------------------------------
DJANGO_APPS = [
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.sites",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    # "django.contrib.humanize", # Handy template tags
    "django.contrib.admin",
    "django.forms",
    "storages",
]
THIRD_PARTY_APPS = [
    "crispy_forms",
    "crispy_bootstrap5",
    "django_celery_beat",
    "rest_framework",
    "rest_framework.authtoken",
    "corsheaders",
    "drf_spectacular",
]

LOCAL_APPS = [
    "materials_lab.users.apps.UsersConfig",
    "materials_lab.projects.apps.ProjectsConfig",
    "materials_lab.notifications.apps.NotificationsConfig",
    "materials_lab.finances.apps.FinancesConfig",
    "materials_lab.data.apps.DataConfig",
    "materials_lab.tests.apps.TestsConfig",
    "materials_lab.landing.apps.LandingConfig",
    "materials_lab.files.apps.FilesConfig",
]
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

# MIGRATIONS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#migration-modules
MIGRATION_MODULES = {"sites": "materials_lab.contrib.sites.migrations"}

# AUTHENTICATION
# -----------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.ModelBackend",
]

# https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
AUTH_USER_MODEL = "users.User"
# https://docs.djangoproject.com/en/dev/ref/settings/#login-redirect-url
LOGIN_REDIRECT_URL = "users:redirect"
# https://docs.djangoproject.com/en/dev/ref/settings/#login-url
# Use the custom login view
LOGIN_URL = "users:login"

# PASSWORDS
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#password-hashers
PASSWORD_HASHERS = [
    # https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-argon2-with-django
    "django.contrib.auth.hashers.Argon2PasswordHasher",
    "django.contrib.auth.hashers.PBKDF2PasswordHasher",
    "django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher",
    "django.contrib.auth.hashers.BCryptSHA256PasswordHasher",
]
# https://docs.djangoproject.com/en/dev/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
    {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
    {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
    {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
    {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]

# MIDDLEWARE
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#middleware
MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "corsheaders.middleware.CorsMiddleware",
    "whitenoise.middleware.WhiteNoiseMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.locale.LocaleMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

# STATIC
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#static-root
STATIC_ROOT = str(BASE_DIR / "staticfiles")
# https://docs.djangoproject.com/en/dev/ref/settings/#static-url
STATIC_URL = "/static/"
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS
STATICFILES_DIRS = [str(APPS_DIR / "static")]
# https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders
STATICFILES_FINDERS = [
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
]

# MEDIA
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#media-root
MEDIA_ROOT = str(APPS_DIR / "media")
# https://docs.djangoproject.com/en/dev/ref/settings/#media-url
MEDIA_URL = "/media/"

# TEMPLATES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#templates
TEMPLATES = [
    {
        # https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-TEMPLATES-BACKEND
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        # https://docs.djangoproject.com/en/dev/ref/settings/#dirs
        "DIRS": [str(APPS_DIR / "templates")],
        # https://docs.djangoproject.com/en/dev/ref/settings/#app-dirs
        "APP_DIRS": True,
        "OPTIONS": {
            # https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.template.context_processors.i18n",
                "django.template.context_processors.media",
                "django.template.context_processors.static",
                "django.template.context_processors.tz",
                "django.contrib.messages.context_processors.messages",
            ],
        },
    }
]

# https://docs.djangoproject.com/en/dev/ref/settings/#form-renderer
FORM_RENDERER = "django.forms.renderers.TemplatesSetting"

# http://django-crispy-forms.readthedocs.io/en/latest/install.html#template-packs
CRISPY_TEMPLATE_PACK = "bootstrap5"
CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap5"

# FIXTURES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#fixture-dirs
FIXTURE_DIRS = (str(APPS_DIR / "fixtures"),)

# SECURITY
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-httponly
SESSION_COOKIE_HTTPONLY = True
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-httponly
CSRF_COOKIE_HTTPONLY = True
# https://docs.djangoproject.com/en/dev/ref/settings/#x-frame-options
X_FRAME_OPTIONS = "DENY"

# EMAIL
# Anymail
# ------------------------------------------------------------------------------
# https://anymail.readthedocs.io/en/stable/installation/#installing-anymail
INSTALLED_APPS += ["anymail"]  # noqa F405
# https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
# https://anymail.readthedocs.io/en/stable/installation/#anymail-settings-reference
# https://anymail.readthedocs.io/en/stable/esps/amazon_ses/
EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend"
ANYMAIL = {
    "MAILGUN_API_KEY": env("MAILGUN_PRIVATE_API_KEY"),
    "MAILGUN_API_URL": env("MAILGUN_API_URL", default="https://api.mailgun.net/v3"),
    "MAILGUN_SENDER_DOMAIN": env("MAILGUN_DOMAIN"),
    "MAILGUN_WEBHOOK_SIGNING_KEY": env("MAILGUN_WEBHOOK_SIGNING_KEY"),
}
EMAIL_TIMEOUT = 5
DEFAULT_FROM_EMAIL = env("DJANGO_DEFAULT_FROM_EMAIL")
EMAIL_SUBJECT_PREFIX = env(
    "DJANGO_EMAIL_SUBJECT_PREFIX"
)
FRONT_END_URL = env("FRONT_END_URL")
# ADMIN
# ------------------------------------------------------------------------------
# Django Admin URL.
ADMIN_URL = "admin/"
# https://docs.djangoproject.com/en/dev/ref/settings/#admins
ADMINS = []
# https://docs.djangoproject.com/en/dev/ref/settings/#managers
MANAGERS = ADMINS
# https://cookiecutter-django.readthedocs.io/en/latest/settings.html#other-environment-settings

# LOGGING
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#logging
# See https://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "verbose": {
            "format": "%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s",
        },
    },
    "handlers": {
        "console": {
            "level": "DEBUG",
            "class": "logging.StreamHandler",
            "formatter": "verbose",
        }
    },
    "root": {"level": "INFO", "handlers": ["console"]},
}

# Celery
# ------------------------------------------------------------------------------
if USE_TZ:
    # https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-timezone
    CELERY_TIMEZONE = TIME_ZONE
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-broker_url
CELERY_BROKER_URL = env("CELERY_BROKER_URL")
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_backend
CELERY_RESULT_BACKEND = CELERY_BROKER_URL
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-extended
CELERY_RESULT_EXTENDED = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-backend-always-retry
# https://github.com/celery/celery/pull/6122
CELERY_RESULT_BACKEND_ALWAYS_RETRY = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#result-backend-max-retries
CELERY_RESULT_BACKEND_MAX_RETRIES = 10
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-accept_content
CELERY_ACCEPT_CONTENT = ["json"]
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-task_serializer
CELERY_TASK_SERIALIZER = "json"
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std:setting-result_serializer
CELERY_RESULT_SERIALIZER = "json"
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-time-limit
# TODO: set to whatever value is adequate in your circumstances
CELERY_TASK_TIME_LIMIT = 5 * 60
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-soft-time-limit
# TODO: set to whatever value is adequate in your circumstances
CELERY_TASK_SOFT_TIME_LIMIT = 60
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#beat-scheduler
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#worker-send-task-events
CELERY_WORKER_SEND_TASK_EVENTS = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std-setting-task_send_sent_event
CELERY_TASK_SEND_SENT_EVENT = True

# django-rest-framework
# -------------------------------------------------------------------------------
# django-rest-framework - https://www.django-rest-framework.org/api-guide/settings/

# Add the following setting to use the custom token response handler
REST_FRAMEWORK = {
    "DEFAULT_AUTHENTICATION_CLASSES": (
        # "rest_framework.authentication.SessionAuthentication",
        # "rest_framework.authentication.TokenAuthentication",
        "rest_framework_simplejwt.authentication.JWTAuthentication",
    ),
    "DEFAULT_PERMISSION_CLASSES": (
        "rest_framework.permissions.IsAdminUser",
        "rest_framework.permissions.IsAuthenticated",
    ),
}

# Simplejwt configurations
SIMPLE_JWT = {
    "ACCESS_TOKEN_LIFETIME": timedelta(minutes=30),
    "REFRESH_TOKEN_LIFETIME": timedelta(days=1),
    # We don't want a new refresh token each time we refresh the acces token.
    "ROTATE_REFRESH_TOKENS": False,
    # For expired tokens that will be rotated
    "BLACKLIST_AFTER_ROTATION": True,
    # Algorith to decode jwt token
    "ALGORITHM": "HS256",
    # Key to sign tokens
    "SIGNING_KEY": env("SECRET_KEY", default="SECRET_KEY"),
    "AUDIENCE": None,
    "ISSUER": None,
    # Header style for requests. Authorization: JWT <token> or Authorization: Bearer <token>
    "AUTH_HEADER_TYPES": ("JWT", "Bearer"),
    "USER_ID_FIELD": "id",
    "USER_ID_CLAIM": "user_id",
    # Settings for type of tokens in auth. This projects just accepts Access Token authentication
    "AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
    "TOKEN_TYPE_CLAIM": "token_type",
    "JTI_CLAIM": "jti",
}

# django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup
CORS_URLS_REGEX = r".*$"

# By Default swagger ui is available only to admin user(s). You can change permission classes to change that
# See more configuration options at https://drf-spectacular.readthedocs.io/en/latest/settings.html#settings
SPECTACULAR_SETTINGS = {
    "TITLE": "materials_lab API",
    "DESCRIPTION": "Documentation of API endpoints of materials_lab",
    "VERSION": "1.0.0",
    "SERVE_PERMISSIONS": ["rest_framework.permissions.IsAdminUser"],
}
# Your stuff...
# ------------------------------------------------------------------------------
# Google drive

GDRIVE_AUTH_FILE = env("GDRIVE_AUTH_FILE", default="materials-lab.json")

# S3
AWS_ACCESS_KEY_ID = env("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env("AWS_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = env("AWS_STORAGE_BUCKET_NAME")
AWS_S3_CUSTOM_DOMAIN = f"{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com"
AWS_S3_OBJECT_PARAMETERS = {
    "CacheControl": "max-age=86400",
}
# AWS_LOCATION = "your-folder-name"  # Optional

And this is the local.py

from .base import *  # noqa
from .base import env

# GENERAL
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#debug
DEBUG = True
# https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
SECRET_KEY = env(
    "DJANGO_SECRET_KEY"
)
# https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ["localhost", "0.0.0.0", "127.0.0.1"]

# CACHES
# ------------------------------------------------------------------------------
# https://docs.djangoproject.com/en/dev/ref/settings/#caches
CACHES = {
    "default": {
        "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
        "LOCATION": "",
    }
}

# WhiteNoise
# ------------------------------------------------------------------------------
# http://whitenoise.evans.io/en/latest/django.html#using-whitenoise-in-development
INSTALLED_APPS = ["whitenoise.runserver_nostatic"] + INSTALLED_APPS  # noqa: F405

# django-debug-toolbar
# ------------------------------------------------------------------------------
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#prerequisites
INSTALLED_APPS += ["debug_toolbar"]  # noqa: F405
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#middleware
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]  # noqa: F405
# https://django-debug-toolbar.readthedocs.io/en/latest/configuration.html#debug-toolbar-config
DEBUG_TOOLBAR_CONFIG = {
    "DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],
    "SHOW_TEMPLATE_CONTEXT": True,
}
# https://django-debug-toolbar.readthedocs.io/en/latest/installation.html#internal-ips
INTERNAL_IPS = ["127.0.0.1", "10.0.2.2"]
if env("USE_DOCKER") == "yes":
    import socket

    hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
    INTERNAL_IPS += [".".join(ip.split(".")[:-1] + ["1"]) for ip in ips]

# django-extensions
# ------------------------------------------------------------------------------
# https://django-extensions.readthedocs.io/en/latest/installation_instructions.html#configuration
INSTALLED_APPS += ["django_extensions"]  # noqa: F405
# Celery
# ------------------------------------------------------------------------------

# https://docs.celeryq.dev/en/stable/userguide/configuration.html#task-eager-propagates
CELERY_TASK_EAGER_PROPAGATES = True
# Your stuff...
# ------------------------------------------------------------------------------
karthiknadig commented 5 months ago

@rlemayd Not this, I want the settings.json you use for the project. From the logs it looks like the way the pylint.args is defined is wrong.

From the logs it looks like this:

"args": [
"[ "--load-plugins=pylint_django", "--django-settings-module=config.settings.local", "--disable=W0223,E1137" ]"
],

Which results in pylint being called like this:

pylint --reports=n --output-format=json [ "--load-plugins=pylint_django", "--django-settings-module=config.settings.local", "--disable=W0223,E1137" ] --clear-cache-post-run=y --from-stdin /Users/richard/Documents/GitHub/bci_wholesale/bci_wholesale/statements/apis.py"

The args should really be defined like this:

"args": [
 "--load-plugins=pylint_django", "--django-settings-module=config.settings.local", "--disable=W0223,E1137"
],
rlemayd commented 5 months ago

This is my settings.json

{
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.organizeImports": "explicit"
  },
  "editor.stickyScroll.enabled": true,
  "[python]": {
    "editor.rulers": [88],
    "editor.defaultFormatter": "ms-python.black-formatter",
    "editor.formatOnSave": true
  },
  "[javascript]": {
    "editor.rulers": [80, 120],
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[javascriptreact]": {
    "editor.rulers": [80, 120],
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "isort.args": ["--profile", "black"],
  "pylint.args": [
    "--load-plugins=pylint_django",
    "--django-settings-module=config.settings.local",
    "--disable=W0223,E1137"
  ],
  "black-formatter.args": ["--line-length=88"],
  "workbench.settings.openDefaultSettings": true,
  "search.exclude": {
    "**/node_modules*": true
  },
  "python.languageServer": "Pylance",
  "python.analysis.typeCheckingMode": "off",
  "prettier.jsxSingleQuote": true
}
karthiknadig commented 5 months ago

@rlemayd Can you check both workspace and user settings? On a machine there can be up to 3 settings (User settings, machine settings, and workspace settings). Somewhere this setting has gone wrong. Please looks pylint.args in all those cases and make sure if they look like this:

  "pylint.args": [
    "--load-plugins=pylint_django",
    "--django-settings-module=config.settings.local",
    "--disable=W0223,E1137"
  ],

and NOT like this:

  "pylint.args": ["[ \"--load-plugins=pylint_django\", \"--django-settings-module=config.settings.local\", \"--disable=W0223,E1137\" ]"],

If the settings are correct you will see this in logs: image

image

If the settings are wrong then you will see this in logs: image

As you can see here the CLI looks wrong, and will result in error: image

rlemayd commented 5 months ago

Great, it was from the user settings. Thanks for the help!