#author("2024-03-15T16:08:34+09:00","","")
#author("2024-03-15T16:33:41+09:00","","")
#topicpath

////////////////////////////////////////////////////////////////////////////////
* 目次 [#b4ee840e]
#contents();

////////////////////////////////////////////////////////////////////////////////
* 開発環境 [#ge17897e]
- python 開発の為の環境構築を記す。

////////////////////////////////////////////////////////////////////////////////
* emacs 環境 [#emacs]
- python コード用フォーマッタには、flake8, autopep8, pycodestyle isort 等があるが、 emacs で flycheck でのオンタイムチェックを行う関係から、flycheck でサポートされている flake8 と mypy を採用する。

//==============================================================================
** debian 環境での追加パッケージ [#tc06b6be]
- emacs
- elpa-flycheck
- pylint
- flake8
- isort
- elpa-py-isort
- mypy

//==============================================================================
** pylint [#pylint]
- インストールすると、flycheck から使われるようになる。
- 警告の意味が分からない場合は、[[Pylint 3.1.0-dev0 documentation>https://pylint.readthedocs.io/en/latest/index.html]] でキーワード検索することで、問題コード例と修正例を閲覧することが出来る。これを参考に指摘箇所を修正することが出来る。
//------------------------------------------------------------------------------
*** 設定ファイル [#bf6ef9be]
- 下記に配置する:
-- ${HOME}/.config/pylintrc
- 設定ファイルのサンプルは、以下にて出力される
 $ pylint --generate-rcfile > ~/.config/pylintrc


//==============================================================================
** mypy [#s60e75da]
- 静的型チェックを行う。
- 設定ファイルの適用順などは下記を参照:
-- [[The mypy configuration file>https://mypy.readthedocs.io/en/stable/config_file.html#the-mypy-configuration-file]]
//------------------------------------------------------------------------------
*** 設定ファイル [#ca97b726]
- 環境全体で一つの設定ファイルにしたい場合は、下記何れかとなる。
-- ${HOME}/.config/mypy/config
-- ${HOME}/.mypy.ini


//==============================================================================
** flake8 [#e0883e53]
- インストールすると、flycheck から使われるようになる。
- インストールは pip でローカルに行う。(debian11 のパッケージでは *.py を読み込んだ際にエラーが出る為)
//------------------------------------------------------------------------------
*** 設定ファイル [#r2d1eb50]
- 下記に配置する:
-- ${HOME}/.config/flake8
- 設定ファイル記述例
 [flake8]
 ignore = E226,E302,E41
 max-line-length = 160
 exclude = tests/*
 max-complexity = 10
- 参考:[[Configuration — flake8 2.5.5 documentation>https://flake8.pycqa.org/en/2.5.5/config.html]]
//------------------------------------------------------------------------------
*** 警告・エラーコード [#l2e0ee38]
- エラーコード番号に対応する警告内容は、下記を参照
-- [[Flake8 Rules>https://www.flake8rules.com/]]



//==============================================================================
** isort [#isort]
- python 標準の import 順に準拠していない箇所を指摘したり、修正したりする。



//==============================================================================
** configure for emacs [#emacs-config]
- flycheck
 (require 'flycheck)
 
 ;; checking error by compiler                                                                                                                                          
 (flycheck-define-checker c/c++
   "A C/C++ checker using clang++."
   :command ("clang" "-Wall" "-Wextra -std=c++20" source)
   :error-patterns  ((error line-start
                            (file-name) ":" line ":" column ":" " Error: " (message)
                            line-end)
                     (warning line-start
                              (file-name) ":" line ":" column ":" " Warning: " (message)
                              line-end))
   :modes (c-mode c++-mode))
 
 ;; エラーをツールチップ表示する                                                                                 
 ; (with-eval-after-load 'flycheck                                                                               
 ;   (flycheck-pos-tip-mode))                                                                                    
 


- isort
 (when (executable-find "isort") ; システム上に isort があるときだけ                                             
     (require 'py-isort)
     ;; 保存時にバッファ全体を自動整形する                                                                       
     (add-hook 'before-save-hook 'py-isort-before-save)
     )                                                                                                           

//==============================================================================
** links [#ye6be695]
- [[Pythonのリンター・フォーマッターをしっかりと理解する(Flake8, Black, isort, mypy)>https://zenn.dev/tanny/articles/cdb555d6124a2a]]


////////////////////////////////////////////////////////////////////////////////
* VSCode 環境 [#VSCode]

//==============================================================================
** configure for VSCode [#VSCode-config]



////////////////////////////////////////////////////////////////////////////////
* その他のツール [#b5c74002]
//==============================================================================
** autopep8 [#autopep8]
- python のコーディングルール "PEP8" に準拠していない箇所を指摘したり、修正したりする。
- PEP8 のドキュメント(日本語訳): [[pep8-ja>https://pep8-ja.readthedocs.io/ja/latest/]]



////////////////////////////////////////////////////////////////////////////////
* 参考リンク [#k7a77266]
- [[Pythonの主要なLint(pep8, pylint, flake8)の設定方法まとめ>https://qiita.com/zaki-yama/items/d05adce9d23d67144fbf]]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS