New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/build linter #43
Conversation
新增 .pylintrc 設定檔,之後讓 pylint 跟 ci 可以使用 額外 disable messages: missing-module-docstring missing-class-docstring missing-function-docstring unused-argument too-many-arguments too-few-public-methods too-many-locals broad-except bare-except raise-missing-from 調整項目: 1. 在 requirements.txt 裡,新增 pylint,並指定起始版本為 2.15.5
調整項目: 1. 在 requirements.txt 裡 - 新增 isort,並指定起始版本為 5.10.1 - 新增 black,並指定起始版本為 22.10.0 2. 更新 README.md 檔案,加入 isort、black、pylint 的使用方法
加入 .pre-commit-config.yaml 設定檔,使用 hooks 如下 - black - isort - pylint 調整項目: 1. 在 requirements.txt 裡,新增 pre-commit,並指定起始版本為 2.20.0 2. 更新 README.md,加入 pre-commit 的使用方法
新增 linters.yml 設定檔,linters workflow 主要針對 3 個相關的 job - pylint - isort - black
調整項目: 1. 新增 3 個 badge 至 README.md
問題: 1. 某正常情境下,exit code 出現非 0 原因: 1. PR 沒有異動到 Python files 時, ${{ steps.changed-files.outputs.all_changed_files }} 會為空字串, 沒有 input 傳入,產生錯誤 調整項目: 1. 執行檢查的地方,寫成條件式,非空字串時才執行
這邊打一些補充及想法,根據 #17 (comment) 裡面列的相關 package。 目前
但整個專案 pylint 下來,大部分 Python 檔案還是都有出現其他的 message,如下:
以上的錯誤,是比較影響開發的維護性、可讀性跟流暢度,目前 目前想法是讓專案 rolling format,在 pre-commit 那一層機制下 (假設 PR 進去了,有 rebase or merge 過,並安裝它),會先在 local 開發端被 block 一次,後續的 commit 應該就會是 formatted 過的了,也剛好讓正在 develop 這幾隻檔案的人,可以順帶調整。 又或者直接開 branch,來特別處理全部 Python 檔案的 code style。 (目前 Action 裡的 workflow - Linters,裡面的 Step - Set changed files,現階段會對發 PR 的 branch,找出其 changed files,並檢查是否符合規範) 後續可以調整的 (開 issue 🤔),如下:
|
後續可以列出會影響開發的 format checking,而比較 minor 的可以考慮放過。 |
pylint~=2.15.5 | ||
isort~=5.10.1 | ||
black~=22.10.0 | ||
pre-commit~=2.20.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
這邊的 library 也幫忙補充到 Pipfile 中,之後 requirements.txt 會汰換。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
.github/workflows/linters.yml
Outdated
run: | | ||
[[ -n "${{ steps.changed-files.outputs.all_changed_files }}" ]] && | ||
echo "${{ steps.changed-files.outputs.all_changed_files }}" | xargs black --check --diff || | ||
echo "0 Python files changed." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
.pre-commit-config.yaml
Outdated
entry: pylint | ||
language: system | ||
types: [python] | ||
args: ["-rn", "-sn", "--rcfile=.pylintrc", "--fail-on=I"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上 No newline at end of the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
調整項目: 1. Pipfile 安裝 pylint、isort、black 及 pre-commit 2. linters.yml 加入換行 3. .pre-commit-config.yaml 加入換行
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Why need this change? / Root cause:
Changes made:
README.md
filerequirements.txt
file.pylintrc
file.pre-commit-config.yaml
filelinters.yml
file under.github/workflows
directoryTest Scope / Change impact:
linters.yml
) should work and check every pull requestissue #17