@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.
Please contact your system administrator.
Add correct host key in ~/.ssh/known_hosts to get rid of this message.
Offending RSA key in ~/.ssh/known_hosts:1
remove with:
ssh-keygen -f "~/.ssh/known_hosts" -R "github.com"
RSA host key for github.com has changed and you have requested strict checking.
# 古い鍵情報の破棄
$ ssh-keygen -R github.com
/home/y-uchiida/.ssh/known_hosts updated.
Original contents retained as /home/y-uchiida/.ssh/known_hosts.old
# 新しい鍵情報を追加
$ ssh -T github.com
The authenticity of host'github.com (20.27.177.113)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM. # 表示される鍵情報が正しいものか確認
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes # yes を入力
Warning: Permanently added 'github.com' (ECDSA) to the list of known hosts.
Hi y-uchiida! You've successfully authenticated, but GitHub does not provide shell access.
(python-flake8-sample-py3.11) $ poetry add --dev flake8
Creating virtualenv flake8-sample in /home/y-uchiida/python/flake8_sample/.venv
The --dev option is deprecated, use the `--group dev` notation instead.
Using version ^6.0.0 for flake8
Updating dependencies
Resolving dependencies... (0.2s)
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals
• Installing mccabe (0.7.0)
• Installing pycodestyle (2.10.0)
• Installing pyflakes (3.0.1)
• Installing flake8 (6.0.0)
Bash
CLI から実行する
それではFlake8 を使ってみます。
flake8 <チェック対象のファイルパス> で実行できます。
PEP 8に沿ってない内容のスクリプトを書いて、、、
if1is1:# リテラルの比較に is は使わないprint('always true')# インデントはスペース4つにする
Python
Flake8 で検査します。
(python-flake8-sample-py3.11) $ flake8 flake8_test.py
flake8_test.py:1:4: F632 use ==/!= to compare constant literals (str, bytes, int, float, tuple)
flake8_test.py:2:3: E111 indentation is not a multiple of 4
$ poetry add --dev black
Creating virtualenv python-black-sample in /home/y-uchiida/develop/python-black-sample/.venv
The --dev option is deprecated, use the `--group dev` notation instead.
Using version ^23.1.0 for black
Updating dependencies
Resolving dependencies... (0.5s)
Writing lock file
Package operations: 6 installs, 0 updates, 0 removals
• Installing click (8.1.3)
• Installing mypy-extensions (1.0.0)
• Installing packaging (23.0)
• Installing pathspec (0.11.0)
• Installing platformdirs (3.1.0)
• Installing black (23.1.0)
Bash
これだけでセットアップ完了です!
CLIから実行する
black <修正対象のファイルパス> で、自動フォーマットを実行できます。
こんな感じで、みるからにガタガタなファイルを作って…
defmain():print("this"+"is"+'main')return0
Python
コマンドを実行!
(python-black-sample-py3.11) $ black format_test.py
reformatted format_test.py
All done!1file reformatted.
Bash
以下のように修正されました。
defmain():print("this"+"is"+"main")return0
Python
Black の特徴
基本的な使い方がわかったところで、Black について知っておきましょう。
Blackは、ルールがとても厳格というか、選択の余地がないフォーマッターです。
ドキュメントの冒頭で、こんなことを書いています。
By using Black, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.
最近のコメント