{"id":131850,"date":"2020-07-05T17:06:26","date_gmt":"2020-07-05T09:06:26","guid":{"rendered":"http:\/\/4563.org\/?p=131850"},"modified":"2020-07-05T17:06:26","modified_gmt":"2020-07-05T09:06:26","slug":"pycharm-%e5%ae%89%e8%a3%85%e4%bd%bf%e7%94%a8-black-%e6%8f%90%e5%8d%87python%e4%bb%a3%e7%a0%81%e8%b4%a8%e9%87%8f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=131850","title":{"rendered":"Pycharm \u5b89\u88c5\u4f7f\u7528 black \u63d0\u5347python\u4ee3\u7801\u8d28\u91cf"},"content":{"rendered":"<p>\u9488\u5bf9\u4ee3\u7801\u98ce\u683c\u4e0d\u4e00\u81f4\u95ee\u9898\uff0c\u5bfc\u81f4\u7684\u7ef4\u62a4\u6210\u672c\u8fc7\u9ad8\uff0c\u9488\u5bf9\u6027\u7684\u9547\u5b9a\u4ee3\u7801\u98ce\u683c\u7edf\u4e00\u6807\u51c6\uff0c\u662f\u5f88\u6709\u5fc5\u8981\u7684\u3002\u76ee\u524d\u5e02\u9762\u4e0a\u7528\u7684\u6bd4\u8f83\u591a\u7684python\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\u6709YAPF\u3001Black\u3002<\/p>\n<p>Black\uff0c\u53f7\u79f0\u4e0d\u59a5\u534f\u7684\u4ee3\u7801\u683c\u5f0f\u5316\u5de5\u5177\uff0c\u5b83\u68c0\u6d4b\u5230\u4e0d\u7b26\u5408\u89c4\u8303\u7684\u4ee3\u7801\u98ce\u683c\u76f4\u63a5\u5c31\u5e2e\u4f60\u5168\u90e8\u683c\u5f0f\u5316\u597d\uff0c\u6839\u672c\u4e0d\u9700\u8981\u4f60\u786e\u5b9a\uff0c\u76f4\u63a5\u66ff\u4f60\u505a\u597d\u51b3\u5b9a\u3002\u4ece\u800c\u8282\u7701\u5173\u6ce8\u4ee3\u7801\u89c4\u8303\u7684\u65f6\u95f4\u548c\u7cbe\u529b\uff0c\u5173\u6ce8\u7f16\u7a0b\u3002<\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5b89\u88c5-black-\u6269\u5c55\" title=\"\u5b89\u88c5 black \u6269\u5c55\"><\/a>\u5b89\u88c5 black \u6269\u5c55<\/h3>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>pip3 install black<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u5b89\u88c5\u76ee\u5f55\" title=\"\u5b89\u88c5\u76ee\u5f55\"><\/a>\u5b89\u88c5\u76ee\u5f55<\/h3>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>\u279c  servers which black<\/span><br><span>&#x2F;Library&#x2F;Frameworks&#x2F;Python.framework&#x2F;Versions&#x2F;3.6&#x2F;bin&#x2F;black<\/span><br><span>\u279c  servers where black<\/span><br><span>&#x2F;Library&#x2F;Frameworks&#x2F;Python.framework&#x2F;Versions&#x2F;3.6&#x2F;bin&#x2F;black<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u6d4b\u8bd5\u547d\u4ee4\u884c\u4f7f\u7528\" title=\"\u6d4b\u8bd5\u547d\u4ee4\u884c\u4f7f\u7528\"><\/a>\u6d4b\u8bd5\u547d\u4ee4\u884c\u4f7f\u7528<\/h3>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>\u279c  mws git:(feature&#x2F;datawarehouse-v3.0.0) \u2717 python3 -m black celery_tasks&#x2F;__init__.py<\/span><br><span>All done! \u2728 ? \u2728<\/span><br><span>1 file left unchanged.<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#pycharm-\u4e2d-\u96c6\u6210-black\" title=\"pycharm \u4e2d \u96c6\u6210 black\"><\/a>pycharm \u4e2d \u96c6\u6210 black<\/h3>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u5728-PyCharm-\u4e2d\u6253\u5f00External-tools\" title=\"\u5728 PyCharm \u4e2d\u6253\u5f00External tools\"><\/a>\u5728 PyCharm \u4e2d\u6253\u5f00<code>External tools<\/code><\/h4>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span># On macOS:<\/span><br><span>PyCharm -&gt; Preferences -&gt; Tools -&gt; External Tools<\/span><br><span><\/span><br><span># On Windows &#x2F; Linux &#x2F; BSD:<\/span><br><span>File -&gt; Settings -&gt; Tools -&gt; External Tools<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/07\/20200706_5f0354c429fba.png\" alt=\"Pycharm \u5b89\u88c5\u4f7f\u7528 black \u63d0\u5347python\u4ee3\u7801\u8d28\u91cf\"><\/p>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u6269\u5c55\u5de5\u5177\" title=\"\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u6269\u5c55\u5de5\u5177\"><\/a>\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u6269\u5c55\u5de5\u5177<\/h4>\n<p>\u914d\u7f6e\u4fe1\u606f\u5982\u4e0b\uff1a<\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>Name: Black<\/span><br><span>Description: Black is the uncompromising Python code formatter.<\/span><br><span>Program: &#x2F;Library&#x2F;Frameworks&#x2F;Python.framework&#x2F;Versions&#x2F;3.6&#x2F;bin&#x2F;black<\/span><br><span>Arguments: &quot;$FilePath$&quot;<\/span><br><span>Working directory: $ProjectFileDir$<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/07\/20200706_5f0354cce8790.png\" alt=\"Pycharm \u5b89\u88c5\u4f7f\u7528 black \u63d0\u5347python\u4ee3\u7801\u8d28\u91cf\"><\/p>\n<h4><a href=\"https:\/\/www.studytime.xin\/article\/#\u5982\u4f55\u4f7f\u7528-black-\u683c\u5f0f\u5316\u4ee3\u7801\" title=\"\u5982\u4f55\u4f7f\u7528 black \u683c\u5f0f\u5316\u4ee3\u7801\"><\/a>\u5982\u4f55\u4f7f\u7528 black \u683c\u5f0f\u5316\u4ee3\u7801<\/h4>\n<ol>\n<li>\u901a\u8fc7\u9009\u62e9 <code>Tools -&gt; External Tools -&gt; black<\/code> \u6765\u683c\u5f0f\u5316\u4ee3\u7801\u3002<\/li>\n<li>\u5728\u4ee3\u7801\u533a\u57df\u6309\u9f20\u6807\u53f3\u952e\uff0c\u9009\u62e9<code>External Tools<\/code>\u4e2d\u7684<code>black<\/code><\/li>\n<\/ol>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u8bbe\u7f6e\u5feb\u6377\u952e\u6267\u884c-black-\u683c\u5f0f\u5316\u4ee3\u7801\" title=\"\u8bbe\u7f6e\u5feb\u6377\u952e\u6267\u884c black \u683c\u5f0f\u5316\u4ee3\u7801\"><\/a>\u8bbe\u7f6e\u5feb\u6377\u952e\u6267\u884c black \u683c\u5f0f\u5316\u4ee3\u7801<\/h3>\n<p>\u6253\u5f00 <code>Preferences or Settings -&gt; Keymap -&gt; External Tools -&gt; External Tools - Black<\/code>\uff0c<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/07\/20200706_5f0354d31c67c.png\" alt=\"Pycharm \u5b89\u88c5\u4f7f\u7528 black \u63d0\u5347python\u4ee3\u7801\u8d28\u91cf\"><\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#black-File-Watchers-\u81ea\u52a8\u683c\u5f0f\u5316\" title=\"black + File Watchers \u81ea\u52a8\u683c\u5f0f\u5316\"><\/a>black + File Watchers \u81ea\u52a8\u683c\u5f0f\u5316<\/h3>\n<p>\u786e\u4fdd File Watchers\u63d2\u4ef6\u53ef\u7528\uff0c\u4e00\u822c\u800c\u8a00\u5b89\u88c5Pycharm\u5e94\u8be5\u4f1a\u9ed8\u8ba4\u5b89\u88c5\u3002<\/p>\n<p>\u9009\u62e9 <code>Preferences or Settings -&gt; Tools -&gt; File Watchers<\/code> \u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684<code>watcher<\/code><\/p>\n<figure>\n<table>\n<tr>\n<td>\n<pre><span>1<\/span><br><span>2<\/span><br><span>3<\/span><br><span>4<\/span><br><span>5<\/span><br><span>6<\/span><br><span>7<\/span><br><span>8<\/span><br><\/pre>\n<\/td>\n<td>\n<pre><span>Name: Black<\/span><br><span>File type: Python<\/span><br><span>Scope: Project Files<\/span><br><span>Program: &#x2F;Library&#x2F;Frameworks&#x2F;Python.framework&#x2F;Versions&#x2F;3.6&#x2F;bin&#x2F;black<\/span><br><span>Arguments: $FilePath$<\/span><br><span>Output paths to refresh: $FilePath$<\/span><br><span>Working directory: $ProjectFileDir$<\/span><br><span>Uncheck &quot;Auto-save edited files to trigger the watcher&quot;<\/span><br><\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/figure>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/07\/20200706_5f0354d896319.png\" alt=\"Pycharm \u5b89\u88c5\u4f7f\u7528 black \u63d0\u5347python\u4ee3\u7801\u8d28\u91cf\"><br \/><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/07\/20200706_5f0354dea250b.png\" alt=\"Pycharm \u5b89\u88c5\u4f7f\u7528 black \u63d0\u5347python\u4ee3\u7801\u8d28\u91cf\"><\/p>\n<h3><a href=\"https:\/\/www.studytime.xin\/article\/#\u7279\u6b8a\u8bf4\u660e\" title=\"\u7279\u6b8a\u8bf4\u660e\"><\/a>\u7279\u6b8a\u8bf4\u660e<\/h3>\n<p>\u4e24\u4e2a\u8bbe\u7f6e\u4e2d\u7684\u53c2\u6570Program\u4f7f\u7528 <code>which black<\/code> \u67e5\u8be2\u51fa\u6765\u7684\u8def\u5f84\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9488\u5bf9\u4ee3\u7801\u98ce\u683c\u4e0d\u4e00\u81f4\u95ee\u9898\uff0c\u5bfc\u81f4\u7684\u7ef4\u62a4&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/131850"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=131850"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/131850\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=131850"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=131850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}