{"id":176,"date":"2020-10-29T22:32:36","date_gmt":"2020-10-29T13:32:36","guid":{"rendered":"http:\/\/localhost:8000\/?p=176"},"modified":"2021-01-17T21:31:10","modified_gmt":"2021-01-17T12:31:10","slug":"poetry-direnv-vscode-debug","status":"publish","type":"post","link":"http:\/\/localhost:8000\/2020\/10\/poetry-direnv-vscode-debug.html","title":{"rendered":"Poetry+direnv\u3067\u74b0\u5883\u7ba1\u7406\u3057\u3066\u3044\u308bPython\u30a2\u30d7\u30ea\u3092VS Code\u4e0a\u3067Debug\u5b9f\u884c\u3059\u308b"},"content":{"rendered":"

\u3053\u3053\u6700\u8fd1Python\u306e\u30ed\u30fc\u30ab\u30eb\u958b\u767a\u74b0\u5883\u306b\u304a\u3044\u3066\u306f\u3001Poetry\u3067\u4eee\u60f3\u74b0\u5883\uff0b\u30d1\u30c3\u30b1\u30fc\u30b8\u7ba1\u7406\u3092\u884c\u3044\u3001direnv\u3067\u74b0\u5883\u5909\u6570\u7ba1\u7406\u3092\u884c\u3046\u30b9\u30bf\u30f3\u30b9\u306a\u306e\u3067\u3059\u304c\u3001VS Code\u4e0a\u3067Debug\u5b9f\u884c\u3057\u3088\u3046\u3068\u601d\u3063\u305f\u3089\u5c11\u3057\u8a2d\u5b9a\u304c\u5fc5\u8981\u3060\u3063\u305f\u306e\u3067\u30e1\u30e2\u7684\u306b\u6b8b\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n

Poetry<\/a><\/h2>\n

Poetry\u306f\u4eee\u60f3\u74b0\u5883\u69cb\u7bc9\u3068\u30d1\u30c3\u30b1\u30fc\u30b8\u7ba1\u7406\u3092\u307e\u3068\u3081\u3066\u5b9f\u884c\u3067\u304d\u308b\u4fbf\u5229\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002\u3064\u307e\u308a\u3001venv\u3068pip\u306e\u4ee3\u66ff\u30c4\u30fc\u30eb\u3068\u306a\u308a\u307e\u3059\u3002\u8a73\u7d30\u306f\u4ee5\u524d\u8a18\u4e8b\u3092\u66f8\u3044\u305f\u306e\u3067\u305d\u3061\u3089\u3092\u53c2\u7167\u304f\u3060\u3055\u3044\u3002
\n
poetry\u3067\u30d1\u30c3\u30b1\u30fc\u30b8\u30fb\u4eee\u60f3\u74b0\u5883\u3092\u7ba1\u7406<\/a><\/p>\n

direnv<\/a><\/h2>\n

12 factor<\/a> \u3092\u610f\u8b58\u3057\u3066\u3001\u8a2d\u5b9a\u306f\u74b0\u5883\u5909\u6570\u306b\u683c\u7d0d\u3059\u308b\u3068\u3044\u3046\u306e\u304c\u4e00\u822c\u7684\u306b\u306a\u3063\u3066\u304d\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u30bf\u30fc\u30df\u30ca\u30eb\u3067\u3042\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306bcd<\/code>\u3057\u305f\u3055\u3044\u306b\u3001\u73fe\u5728\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3082\u3057\u304f\u306f\u89aa\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u63a2\u7d22\u3057\u3066\u3001.envrc<\/code>\u304c\u5b58\u5728\u3057\u3066\u3044\u305f\u5834\u5408\u305d\u3053\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u308b\u5185\u5bb9\u3092\u74b0\u5883\u5909\u6570\u306b\u30ed\u30fc\u30c9\u3057\u3066\u304f\u308c\u308b\u4fbf\u5229\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002\u5225\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u79fb\u52d5\u3057\u305f\u969b\u306f\u3001\u74b0\u5883\u5909\u6570\u306f\u30a2\u30f3\u30ed\u30fc\u30c9\u3055\u308c\u307e\u3059\u3002<\/p>\n

\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h3>\n

mac\u30e6\u30fc\u30b6\u3067\u3042\u308c\u3070homebrew\u3067\u5165\u308c\u308b\u306e\u304c\u4e00\u756a\u697d\u3060\u3068\u601d\u3044\u307e\u3059\u3002\u305d\u306e\u4ed6\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<\/p>\n

brew install direnv<\/code><\/pre>\n

\u6b21\u306b\u30b7\u30a7\u30eb\u306b\u30d5\u30c3\u30af\u3057\u307e\u3059\u3002Bash\u306e\u5834\u5408\u306f.bashrc<\/code>\u306b\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8a18\u8f09\u3057\u307e\u3059\u3002\u305d\u306e\u4ed6\u306e\u30b7\u30a7\u30eb\u306e\u65b9\u306f\u3053\u3061\u3089<\/a>\u3092\u53c2\u7167\u304f\u3060\u3055\u3044\u3002<\/p>\n

eval "$(direnv hook bash)"<\/code><\/pre>\n

\u3053\u308c\u3067direnv\u304c\u30b7\u30a7\u30eb\u3067\u6709\u52b9\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n

\u8a2d\u5b9a<\/h3>\n

\u4efb\u610f\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b.envrc<\/code>\u3092\u4f5c\u6210\u3057\u3066\u3001\u8a2d\u5b9a\u3057\u305f\u3044\u74b0\u5883\u5909\u6570\u3092\u8a18\u8f09\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n

export PROJECT_DIR=\/hoge\/fuga\nexport PROJECT_ID=fuga\nexport PYTHONPATH="${PROJECT_DIR}:${PYTHONPATH}"<\/code><\/pre>\n

\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b.envrc<\/code>\u304c\u30d6\u30ed\u30c3\u30af\u3055\u308c\u3066\u3044\u308b\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\u306e\u3067\u3001<\/p>\n

direnv: error \/hoge\/fuga\/.envrc is blocked. Run `direnv allow` to approve its content<\/code><\/pre>\n

direnv allow<\/code>\u30b3\u30de\u30f3\u30c9\u3067\u30d6\u30ed\u30c3\u30af\u3092\u89e3\u9664\u3057\u3066\u3042\u3052\u307e\u3059\u3002\u4ee5\u5f8c.envrc<\/code>\u306e\u5185\u5bb9\u3092\u5909\u66f4\u3059\u308b\u305f\u3073\u306bdirenv allow<\/code>\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n

direnv allow\ndirenv: loading \/hoge\/fuga\/.envrc\ndirenv: export +PROJECT_DIR +PROJECT_ID +PYTHONPATH<\/code><\/pre>\n

\u3053\u308c\u306b\u3088\u308a\u3001\u3053\u306e\u4f8b\u3067\u306fPROJECT_DIR<\/code> PROJECT_ID<\/code> PYTHONPATH<\/code>\u304c\u74b0\u5883\u5909\u6570\u306b\u683c\u7d0d\u3055\u308c\u307e\u3057\u305f\u3002
\n\u4ee5\u5f8c\u306f\u3001\u30b7\u30a7\u30eb\u3067\u3053\u306e\/hoge\/fuga<\/code>\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u914d\u4e0b\u306bcd<\/code>\u3057\u305f\u3060\u3051\u3067\u81ea\u52d5\u7684\u306b.envrc<\/code>\u306b\u8a18\u8f09\u3055\u308c\u3066\u3044\u308b\u5185\u5bb9\u304c\u74b0\u5883\u5909\u6570\u306b\u683c\u7d0d\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

VS Code\u3067Debug\u5b9f\u884c<\/h2>\n

\u901a\u5e38\u306ePython Debug\u74b0\u5883\u6e96\u5099<\/h3>\n

\u307e\u305a\u3001VS Code\u306eExtensions\u30a2\u30a4\u30b3\u30f3\u304b\u3089Python\u30d7\u30e9\u30b0\u30a4\u30f3<\/a>\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n

\u6b21\u306b\u3001VS Code\u306eDebug\u30a2\u30a4\u30b3\u30f3\u304b\u3089Debug\u753b\u9762\u3092\u958b\u304d\u3001Add Configration...<\/code>\u3092\u30af\u30ea\u30c3\u30af\u3057\u3001Python File<\/code>\u3092\u9078\u629e\u3059\u308b\u3068\u3001\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306elaunch.json<\/code>\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n

{\n    "version": "0.2.0",\n    "configurations": [\n        {\n            "name": "Python: Current File",\n            "type": "python",\n            "request": "launch",\n            "program": "${file}",\n            "console": "integratedTerminal"\n        }\n    ]\n}<\/code><\/pre>\n

\u3053\u306e\u72b6\u614b\u3067\u4efb\u610f\u306epython\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u3066\u3001Start Debugging<\/code>\u30a2\u30a4\u30b3\u30f3\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u304bF5<\/code>\u3067Debug\u3092\u30b9\u30bf\u30fc\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n

\u305f\u3060\u3057\u3001\u8a2d\u5b9a\u306b\u3088\u3063\u3066\u306f\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306f\u500b\u5225\u306b\u5bfe\u5fdc\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n