twtrubiks / odoo-development-environment-tutorial

建立 odoo 開發環境 ( source code )

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

odoo13 用VS Code Debug,出現pylint(import-error)

akira32chen opened this issue · comments

第一次安裝hr_expense模組的時候,有觸發create的函式,但是我沒有留意,它已經在中斷點。
於是我STOP VS Code,再重新開啟專案,反安裝hr_expense模組,再安裝hr_expense模組,想在create函式下中斷點,卻發現不會中斷,但是會繼續跑下去。

我在env的環境重新安裝pip install pylint,還是沒用,想請教一下要如何解決這個問題?
現在只要開啟專案,都會出現三個錯誤與四個警告。

hr_expense.py

import re

from odoo import api, fields, models, _
from odoo.exceptions import UserError, ValidationError
from odoo.tools import email_split, float_is_zero

出現三個錯誤:

Unable to import 'odoo' pylint(import-error)[6, 1]
Unable to import 'odoo.exceptions' pylint(import-error)[7, 1]
Unable to import 'odoo.tools'  pylint(import-error)[8, 1]

與四個警告:

Anomalous backslash in string: '\d'. String constant might be missing an r prefix. pylint(anomalous-backslash-in-string) [598, 66]
Anomalous backslash in string: '\d'. String constant might be missing an r prefix. pylint(anomalous-backslash-in-string) [598, 74]
Anomalous backslash in string: '\s'. String constant might be missing an r prefix. pylint(anomalous-backslash-in-string) [604, 32]
Anomalous backslash in string: '\s'. String constant might be missing an r prefix. pylint(anomalous-backslash-in-string) [604, 37]

警告的問題都出現在re的表示式:

@api.model
def _parse_price(self, expense_description, currencies):
    """ Return price, currency and updated description """
    symbols, symbols_pattern, float_pattern = [], '', '[+-]?(\d+[.,]?\d*)' ## LINE 598
    price = 0.0

關閉VM前,我看到Ubuntu 18.04遭遇內部錯誤。是否傳送問題報告予開發者?
我選"傳送"

這是因為你裝了 pylint 的關係, 如果不需要 pylint 直接移除即可.
中斷點肯定是可以中斷的(我開發都用 vscode ), 可以看看是那部份和我文章操作的不一樣.
中斷點有可能是你的 launch.json 設定不正確.

我發現有一個不同,就是我的VS Code多出settings.json,Workspace Settings,是否這個需要刪除?
pylint好像不可以移除,不然不可以debug,請問一下要如何移除pylint?
hr_expense模組卸載後重新安裝的時候,在load demo的資料的時候,create的確有中斷,但是安裝好模組,創建一筆新的就無法中斷了。

終於成功了,是在費用的"創建費用報告"觸發create,不是儲存。但是pylint的錯誤與警告還在。

請問一下VS Code的user settings(settings.json),在ubuntu中的"terminal.integrated.shell.windows",要填甚麼?

"terminal.integrated.shell.windows": "C:\WINDOWS\System32\cmd.exe",

我找到一篇文章,在VS Code安裝flake8,並設定"python.linting.flake8Enabled": true,但是錯誤更多,於是我就改回pylint,之後VS Code的錯誤與警告就不見了。

pylint-dev/pylint#3721

In Visual Studio Code, ensure you're at a root prompt in the terminal, press Ctrl+Shift+P to open the palette, search/choose "Python: Select Linter", and choose "flake8" to use it instead of Pylint.

改回來後就正常了

{
    "python.pythonPath": "/home/[USER]/odoo/odoo13/odoo13/bin/python3",
    "python.venvPath":"/home/[USER]/odoo/odoo13",
    "python.terminal.activateEnvironment": true, // 自動啟動環境
    "python.linting.pylintEnabled": false,  // 需要 pip install pylint
    "python.linting.enabled": true,// 需要 pip install pylint
    //"python.linting.flake8Enabled": true,
}

我發現有一個不同,就是我的VS Code多出settings.json,Workspace Settings,是否這個需要刪除?
pylint好像不可以移除,不然不可以debug,請問一下要如何移除pylint?
hr_expense模組卸載後重新安裝的時候,在load demo的資料的時候,create的確有中斷,但是安裝好模組,創建一筆新的就無法中斷了。

因為要中斷在 write 才對.

終於成功了,是在費用的"創建費用報告"觸發create,不是儲存。但是pylint的錯誤與警告還在。

pylint 不一定要處理, 建議而已, 可以直接移除 pylint.