<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by CookSen on Medium]]></title>
        <description><![CDATA[Stories by CookSen on Medium]]></description>
        <link>https://medium.com/@senchao0930?source=rss-a0abc1a3ee8d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5bcxxK1a_CE7Nuy6rYRZtg.png</url>
            <title>Stories by CookSen on Medium</title>
            <link>https://medium.com/@senchao0930?source=rss-a0abc1a3ee8d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 14:31:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@senchao0930/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[[HLS with AWS FPGA] 專案介紹]]></title>
            <link>https://medium.com/@senchao0930/hls-with-aws-fpga-%E5%B0%88%E6%A1%88%E4%BB%8B%E7%B4%B9-18cac5e73744?source=rss-a0abc1a3ee8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/18cac5e73744</guid>
            <dc:creator><![CDATA[CookSen]]></dc:creator>
            <pubDate>Mon, 24 Jun 2024 09:11:35 GMT</pubDate>
            <atom:updated>2024-06-24T09:11:35.727Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*ZPGRhH2i9MCX9arkC_d-mQ.png" /></figure><p>今天這篇文章我打算介紹一下這個專案，主要會包含以下幾點：</p><ul><li>AWS FPGA</li><li>High Level Synthesis</li><li>Project Target</li></ul><p>那其實我自己也不是 aws 和 HSL 的專家…但就當作是學習的筆記，整理紀錄一下我在網路上找的資訊。</p><p>那就開始吧～</p><h3>AWS FPGA：</h3><p>上一篇文章大概介紹了如果開通兩個 instance 和一個 bucket，分別是 m5, f1 還有 s3，而這些都是使用 <strong>FPGA Developer AMI</strong> 以下的 instance，所以就先來介紹一下什麼是 <strong>FPGA Developer AMI 吧。</strong></p><h4>首先要先知道什麼是 AMI：</h4><p>AWS AMI (Amazon Machine Image) 是一種 pre-configured virtual machine image，可以用來在 Amazon Web Services (AWS) 中啟動 EC2 實例。AMI 包含了運行時環境所需的所有信息，包括 <strong>operating system, applications 和configuration settings</strong>。</p><h4>我們用到的 FPGA Developer AMI：</h4><p>AWS FPGA AMI (Field Programmable Gate Array Amazon Machine Image) 是一種專門設計用於在 AWS 雲端中開發和運行 FPGA 應用的 AMI。這些 AMI 提供了開發和部署 FPGA 應用所需的所有工具和軟體環境。這裡使用到的 AMI 是由 xilinx 提供的。</p><h4>主要功能</h4><ol><li><strong>預配置開發環境</strong>: FPGA AMI 包含所有必要的工具和軟體，如 Xilinx SDAccel 開發環境、HDK、SDK 以及 example codes 等。</li><li><strong>即時部署</strong>: 開發者可以使用 FPGA AMI 快速啟動並配置 F1 實例，這些實例內含高效能的 Xilinx FPGA，適合高運算需求的應用程序。</li><li><strong>硬體加速</strong>: FPGA 可用於加速多種工作負載，包括機器學習推理、基因體學計算、數據分析、視頻處理等。</li></ol><p>接下來我們使用的是 m5 還有 f1 這兩種 instances，那 aws 還有其他很多種 instances，在 reference 的影片中都有很詳細的圖：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qs467I2HAMRLXQ8fU1cWtQ.png" /><figcaption>reference: <a href="https://www.youtube.com/@youngkyuchoi4260">Youngkyu Choi</a> from <a href="https://www.youtube.com/watch?v=Y2Crd-9kcYM&amp;list=PLf4U4tpbjjz7x_bsG3sBEuXgVQPZfWJgW&amp;index=2">https://www.youtube.com/watch?v=Y2Crd-9kcYM&amp;list=PLf4U4tpbjjz7x_bsG3sBEuXgVQPZfWJgW&amp;index=2</a></figcaption></figure><p>所以我們用的是比較 general purpose 的 m5 （便宜） 還有 FPGA accelerated 的 f1（貴）。</p><p>透過 s3 的資料存取，這樣就可以把大部分時間花在 m5 上，然後把珍貴的血本下在 f1 上！</p><h4>工作流程：</h4><p>整個系統的工作流程大致如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y9DBiMSUNC7m2qZNoBHP8w.png" /><figcaption>reference: <a href="https://aws.amazon.com/marketplace/pp/prodview-gimv3gqbpe57k">https://aws.amazon.com/marketplace/pp/prodview-gimv3gqbpe57k</a></figcaption></figure><ol><li>首先在 m5 上面進行 HLS 的撰寫，並生成 AFI (Amazon FPGA Image)，並存到 s3 bucket 上。</li><li>再來透過 s3 bucket 將這個 AFI 從較便宜的 m5 移動到 f1。</li><li>最後在 f1 上面將 AFI 加載到 FPGA 上運行。</li></ol><p>實際操作預計下一篇文章會拿 example 示範～</p><h3>High Level Synthesis：</h3><p>（High-Level Synthesis，HLS）是一種將高層次描述語言（如 C/C++ 或 SystemC）轉換為硬體描述語言（如 Verilog 或 VHDL）的設計方法。HLS 使得設計者能夠在更高的抽象層次上工作，從而提高生產力並減少設計時間（理論上可以減少瘋狂雕 verilog 的時間…）。</p><h4>主要特點：</h4><ol><li>High level design： HLS 工具允許設計者使用高層次編程語言來描述設計，這與傳統的 RTL（Register Transfer Level）設計方法有很大的不同。</li><li>Automatic Hardware Generation：HLS 工具自動將高層次描述轉換為 RTL 代碼，這些 RTL 代碼可以進一步用於合成和實現硬體電路。</li><li>Optimization：HLS 工具通常提供多種優化選項，像是 loop unrolling, pipelining 和 resource sharing 等.</li></ol><p>這個專案主要會使用 c++ 來寫，更詳細的一些使用上要注意的東西之後實際用到時會再談，這裡就先只先大概介紹到這邊（因為自己也還沒學完…正在硬課 soc lab 中…）</p><h3>Project Target：</h3><p>最後是這個專案的目標，目前只是當作一個暑假的專案，想做到的部分大概有以下幾點：</p><ul><li>了解 aws 的 workflow</li><li>實作基本的 HLS，最好可以有一些進階的應用</li><li>加深對 FPGA 的知識</li><li>最後如果可以對碩論有一點貢獻那是最好……</li></ul><h4>結語：</h4><p>今天這篇文章大概介紹了 AWS FPGA 的一些知識，下一篇文會拿 example 裡的 hello_world 來做演釋，讓他真的在 aws 上跑起來～</p><h4>References:</h4><ol><li><a href="https://github.com/aws/aws-fpga">https://github.com/aws/aws-fpga</a></li><li><a href="https://www.youtube.com/playlist?list=PLf4U4tpbjjz7x_bsG3sBEuXgVQPZfWJgW">https://www.youtube.com/playlist?list=PLf4U4tpbjjz7x_bsG3sBEuXgVQPZfWJgW</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18cac5e73744" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[HLS with AWS FPGA] 環境設定]]></title>
            <link>https://medium.com/@senchao0930/hls-with-aws-fpga-%E7%92%B0%E5%A2%83%E8%A8%AD%E5%AE%9A-15c6062c974c?source=rss-a0abc1a3ee8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/15c6062c974c</guid>
            <category><![CDATA[fpga]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[high-level-synthesis]]></category>
            <dc:creator><![CDATA[CookSen]]></dc:creator>
            <pubDate>Sun, 23 Jun 2024 07:12:57 GMT</pubDate>
            <atom:updated>2024-06-23T07:12:57.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*ZPGRhH2i9MCX9arkC_d-mQ.png" /></figure><h4>前言：</h4><p>接下來幾篇文章我打算記錄一下自己學 High Level Synthesis 在 AWS FPGA platform 的過程！（當作被 CVSD 摧殘之後的下一個惡夢…）</p><p>之後應該會再寫幾篇介紹 HLS、 AWS FPGA 系統、專案的目標等等，然後今天會先從環境設定的部分開始寫，那就開始吧～</p><h4>環境設定：</h4><p>在這個專案我們一共需要三個 AWS 的 instance 和 bucket，分別是：</p><ol><li>m5.xlarge</li><li>f1.xlarge</li><li>s3 bucket</li></ol><p>開啟 m5 跟 f1 instance 的步驟其實大同小異，接下來會用 m5.xlarge 作為範例～</p><h4>M5.xlarge：</h4><p>先到 EC2 dashboard 選取 Launch instance：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*5FaaahSQ4VVTfcbGCmY1GA.png" /></figure><p>在 Amazon Machine Image (AMI) 的地方搜尋 FPGA，然後選取 FPGA Developer AMI：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-k5fQmcifmyDa2uGnBjzKg.png" /></figure><p>這個 AMI 是需要 subscribe 才能用的，所以要 subscribe 一下～</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*M0Ghw46kUNu7HPopyBKkqA.png" /></figure><p>再來就可以選這個 AMI 了：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*Au8PL9hKNNJA9XuVIZvM_g.png" /></figure><p>選擇 m5.xlarge 之後把 keypair 設定一下，第一次用的話要申請一下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*Njj-Cjy5bSVbmIV1LwA_6g.png" /></figure><p>然後就可以 launch instance 啦：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/1*MfBk4ssHRuBjCfoTP7TSBw.png" /></figure><p>順利的話就可以看到這個畫面了：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*vQRhDoQkVfqmY0nuIO-8cw.png" /></figure><h4>S3 bucket：</h4><p>S3 bucket 的話是到 S3 的頁面，點 create bucket：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rnt7FklOOiGRCypgvBdNEQ.png" /></figure><p>輸入 bucket name 之後直接 create 就好了：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*Ax0lieLEVfUFAoALS-Cukw.png" /></figure><p>接下來為了之後的練習我們要先創兩個 folder，分別是 dcp 還有 logs：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*7kiPeRrey3yUOQWVatohZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*aoLJ7jXa99ifv_yjUk06GA.png" /></figure><p>再來我們需要設定 credentials 來使用這個 bucket，所以先到 account 的地方，選這個 security credientials：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*-1ENUYqugDwe5DbCJFJHiQ.png" /></figure><p>選 Create access key，然後記得把這個 credential file download 下來！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oe11wbB--nR6J7S1vDqS6A.png" /></figure><p>這些之後要在 instance 進行 access 設定都會用到！</p><h4>結語：</h4><p>那到這裡 instance 跟 bucket 的設定都做完了，下一篇文章會開始介紹怎麼進行 aws fpga github 上面的 hello world！</p><h4>References：</h4><ol><li><a href="https://github.com/aws/aws-fpga">https://github.com/aws/aws-fpga</a></li><li><a href="https://www.youtube.com/playlist?list=PLf4U4tpbjjz7x_bsG3sBEuXgVQPZfWJgW">https://www.youtube.com/playlist?list=PLf4U4tpbjjz7x_bsG3sBEuXgVQPZfWJgW</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15c6062c974c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[網頁開發常見之 CORS 錯誤原因與 Express 解決辦法]]></title>
            <link>https://medium.com/swf-lab/%E7%B6%B2%E9%A0%81%E9%96%8B%E7%99%BC%E5%B8%B8%E8%A6%8B%E4%B9%8B-cors-%E9%8C%AF%E8%AA%A4%E5%8E%9F%E5%9B%A0%E8%88%87-express-%E8%A7%A3%E6%B1%BA%E8%BE%A6%E6%B3%95-bc5eeedea6dc?source=rss-a0abc1a3ee8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc5eeedea6dc</guid>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[express]]></category>
            <category><![CDATA[modern-web-development]]></category>
            <dc:creator><![CDATA[CookSen]]></dc:creator>
            <pubDate>Sun, 16 Apr 2023 09:56:11 GMT</pubDate>
            <atom:updated>2023-04-16T09:56:11.479Z</atom:updated>
            <content:encoded><![CDATA[<h3>前言</h3><p>相信有在開發前後端的人對 CORS (Cross-Origin Resource Sharing) 絕對不陌生，特別是他跳出的錯誤訊息：</p><blockquote>Access to fetch at ‘<a href="http://localhost:3000/&#39;">https://blablabla:3001/&#39;</a> from origin ‘<a href="http://localhost:8081&#39;/">http://localhost:3000&#39;</a> has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. If an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.</blockquote><p>而 CORS 其實是一種安全機制，用於限制在網頁上的跨域請求。雖然這項技術為網站提供了更好的安全性和可靠性，但在實際應用中，有時候會因為 CORS 錯誤而出現各種問題，如請求失敗或跨域資源無法正常載入等。因此，了解 CORS 錯誤的原因和解決辦法對於網頁開發人員來說是非常重要的。在這篇文章中，我們將探討 CORS 錯誤的原因和解決辦法，幫助讀者更好地了解這個議題並解決相關問題。</p><h3>什麼是 CORS 和 CORS 跨域錯誤？</h3><p>這裡就要從 CORS 的全名，Cross-Origin 中的 Origin 說起，Origin 是指發出跨域請求的網頁的源網域。它由協議（http:// 或 https://）、主機名稱和 Port 組成。例如，一個 Origin 可以是 https://example.com 或 http://localhost:3000。</p><p>而跨域請求是指從另一個源（Origin）發出的請求，例如從 https://api.example.com 發出到 https://example.com 的請求，可以看出這裡的主機名稱就不同了；或是從 http://localhost:3000 發送到 http://localhost:3001 也會是跨域請求，因為 Port 不同了。</p><p>而當跨域請求產生時，可以分為簡單請求與非簡單請求：</p><h4>簡單請求：</h4><p>滿足以下所有條件的跨域請求：</p><ul><li>使用GET、POST、HEAD方法之一。</li><li>Content-Type的值只能是text/plain、multipart/form-data、application/x-www-form-urlencoded中的一種。</li><li>請求標頭中沒有使用自定義標頭。</li></ul><p>對於簡單請求，瀏覽器直接發送跨域請求，並在請求標頭中加上一個Origin字段，表示這個請求的發起源，服務器收到這個請求後，在返回的標頭中加上一個Access-Control-Allow-Origin字段，指定允許哪些源發起跨域請求，瀏覽器接收到服務器的回應後，會根據Access-Control-Allow-Origin的值決定是否允許該請求。</p><p>實際舉例的話就例如 get 一個圖片，或是一段 HTML 文字等，這類 api 用法就不會遇到 cors 阻擋。</p><h4>非簡單請求：</h4><p>不滿足簡單請求條件的跨域請求，例如使用PUT、DELETE等方法，或者Content-Type為application/json等自定義類型，或者使用自定義請求標頭等。</p><p>對於非簡單請求，瀏覽器會在發送實際請求之前，會先發送一個預檢請求，即OPTIONS請求，這個請求中包含了Access-Control-Request-Method、Access-Control-Request-Headers等標頭，用於告訴服務器該實際請求中使用的HTTP方法和自定義標頭。服務器接收到這個預檢請求後，檢查該請求是否允許跨域請求，如果允許，就在回應標頭中加上Access-Control-Allow-Origin、Access-Control-Allow-Methods、Access-Control-Allow-Headers等標頭，告訴瀏覽器允許跨域請求。然後瀏覽器才會發送實際的跨域請求。</p><p>有點類似瀏覽器會協助保護被要求資料的一端，並幫忙兩者溝通。</p><p>而若要更進一步討論為什麼要分成簡單請求與非簡單請求，我個人是理解為可以從你是否能讀取這個資料當作判斷依據，像是我用簡單請求網路上的圖片、字型等資料，最後呈現的只會是瀏覽器，前端程式能取用的資源有限，因此就不像非簡單請求一樣需要 CORS 擋在中間。</p><p>開發網站時，常常會遇到前端與後端的Port不同，或是前後端各自擁有獨立的網域的狀況，當呼叫api時，就可能會遇到CORS錯誤。讀完前述內容後，就可以很容易理解這個錯誤出現的原因了吧！</p><h3>為什麼需要 CORS 擋在中間？</h3><p>CORS 的重要性在於它允許瀏覽器強制執行同源策略（Same Origin Policy）。同源策略是一種安全措施，可防止惡意腳本訪問它不應該訪問的資源。</p><p>如果沒有 CORS，惡意腳本可以向另一個網域的服務器發出請求，並訪問該頁面使用者未打算訪問的資源。也就是說今天你可以隨意架設一個前端戳你目標網域的所有 Port，取得被攻擊者所有資料，這當然會衍生出許多問題，因此就需要 CORS 對來源做把關。</p><h3>該如何解決 CORS 錯誤呢？</h3><p>解決 CORS 問題有很多種方法，分別可以從前端與後端下手，但大多從前端解決的方法都無法真正解決這個問題，所以這篇文章會主要介紹後端的解決辦法，並使用 Express 後端架構舉例。</p><p>預設情況下，Express 不允許跨域存取。換句話說，如果未設置 CORS 相關設置，則無法存取。不過，官方提供了一個易用的中介軟體來實作 CORS，讓我們一起來看看如何使用吧！</p><p>首先安裝：</p><pre>npm install cors<br>npm install @types/cors --save-dev</pre><p>再來在 express 專案中引入：</p><pre>var express = require(&#39;express&#39;);<br>var cors = require(&#39;cors&#39;);<br>var app = express();<br><br>app.use(cors());</pre><p>但這時候的 CORS 預設是全部開放，會有點危險，進一步設定可以像以下步驟：</p><pre>const corsOptions = {<br>  origin: [<br>    &#39;https://www.example.com&#39;,<br>    &#39;http://localhost:3001&#39;,<br>  ],<br>  methods: &#39;GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS&#39;,<br>  allowedHeaders: [&#39;Content-Type&#39;, &#39;Authorization&#39;],<br>};<br><br>app.use(cors(corsOptions));</pre><p>在 origin 這個 array 中新增你要許可的來源。</p><p>在 methods 設置可存取的方法，可以用逗號隔開也可以使用像 origin 的 string array 宣告。</p><p>在 allowedHeaders 中，這裡設定了[&#39;Content-Type&#39;, ‘Authorization’]。這表示只有在請求標頭中包含這兩個標頭時，才會允許跨域請求。</p><h3>結語：</h3><p>CORS 錯誤是我自己本身開發前後端時很常遇到的問題，特別是當先把前後其中一端架到伺服器後，要測試時就會看到這個讓人頭痛的錯誤。</p><p>希望這篇文章可以幫助正在頭痛或是不太懂背後原理的人們，也讓自己以後有個筆記可以回來複習複習。</p><h3>Reference:</h3><ul><li><a href="https://developer.mozilla.org/zh-TW/docs/Web/HTTP/CORS">跨來源資源共用（CORS） - HTTP | MDN</a></li><li><a href="https://expressjs.com/en/resources/middleware/cors.html">cors</a></li><li><a href="https://note.pcwu.net/2017/03/16/nodejs-cors/">[Node.js] 如何在 Node.js 設定 CORS</a></li><li><a href="https://blog.huli.tw/2021/02/19/cors-guide-1/">CORS 完全手冊（一）：為什麼會發生 CORS 錯誤？</a></li><li><a href="https://ithelp.ithome.com.tw/articles/10243077">[今晚我想來點 Express 佐 MVC 分層架構] DAY 09 - Express 安全防護 - iT 邦幫忙::一起幫忙解決難題，拯救 IT 人的一天</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc5eeedea6dc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swf-lab/%E7%B6%B2%E9%A0%81%E9%96%8B%E7%99%BC%E5%B8%B8%E8%A6%8B%E4%B9%8B-cors-%E9%8C%AF%E8%AA%A4%E5%8E%9F%E5%9B%A0%E8%88%87-express-%E8%A7%A3%E6%B1%BA%E8%BE%A6%E6%B3%95-bc5eeedea6dc">網頁開發常見之 CORS 錯誤原因與 Express 解決辦法</a> was originally published in <a href="https://medium.com/swf-lab">SWF Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unidata-好用且開源的web3數據訪問工具]]></title>
            <link>https://medium.com/swf-lab/unidata-%E5%A5%BD%E7%94%A8%E4%B8%94%E9%96%8B%E6%BA%90%E7%9A%84web3%E6%95%B8%E6%93%9A%E8%A8%AA%E5%95%8F%E5%B7%A5%E5%85%B7-3e8393df14ae?source=rss-a0abc1a3ee8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e8393df14ae</guid>
            <category><![CDATA[unidata]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[web-data]]></category>
            <category><![CDATA[web3]]></category>
            <dc:creator><![CDATA[CookSen]]></dc:creator>
            <pubDate>Wed, 08 Feb 2023 16:30:33 GMT</pubDate>
            <atom:updated>2023-02-08T16:30:33.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ZoeEyQjJU_T2JqoXaun0g.png" /><figcaption>from <a href="https://unidata.app/">https://unidata.app/</a></figcaption></figure><blockquote><strong>Unidata目的：”给 Web3 开发者提供人类友好的 Web3 数据的便捷访问。 “</strong></blockquote><blockquote><strong>— from </strong><a href="https://diygod.me/tag/%E5%88%86%E4%BA%AB%E5%A2%83">分享境</a> <strong>at</strong> <a href="https://diygod.me/unidata">https://diygod.me/unidata</a></blockquote><p>Unidata 是一個強大且開源的 web3 數據存取工具，主要解決了當前因鏈上數據缺乏標準格式而導致無法輕易存取自己或用戶所擁有的 web3 數據的問題。</p><p>Unidata 提出的解決方法為，設定統一格式，將這些數據分為四大類： assets, notes, profiles, links ，最常用到的 NFT 即屬於 assets 的範圍。同時，一般在取得 NFT 的過程中，不同的鏈會有不同的設計，以乙太鏈來舉例，要取得一地址之 NFT 需讀取其在所有主鏈、測鏈上的交易紀錄，這對需將資料展現在網頁的前端工程師來說是一項非常麻煩的工作，Unidata 就是在這時候 come to help，透過其 api 把資料透過友好且統一的格式回傳，提供相當便利之鏈上數據訪問方式。</p><p>今天這篇文章會大致演示四種資料的取得，都是用很簡單的 typescript 來做 api 的示範，欲取得更多資訊或是更詳細的支援列表這裡推薦大家去看他的<a href="https://unidata.app/">官方文件網站</a>！</p><h4>開始使用：</h4><p>Installation:</p><p>yarn add unidata</p><p>Initialization:</p><pre>import Unidata from &#39;unidata.js&#39;;<br><br>const unidata = new Unidata({<br>    infuraProjectID?: string;<br>    ipfsGateway?: string;<br>    moralisWeb3APIKey?: string;<br>    openseaAPIKey?: string;<br>    alchemyEthereumAPIKey?: string;<br>    alchemyPolygonAPIKey?: string;<br>    alchemyFlowAPIKey?: string;<br>    poapAPIKey?: string;<br>});</pre><p>在這裡先建構你的各種 key，以利之後直接呼叫。</p><h4>Get Assets:</h4><pre>const assets: Assets = await unidata.assets.get(options: {<br>    source: string;<br>    providers?: string[];<br>    identity: string;<br>    limit?: number;<br>    cursor?: any;<br>});  <br>// 填入有需要用到的資料就好。</pre><p>Example:</p><pre>import &quot;./App.css&quot;;<br>import Unidata from &quot;unidata.js&quot;;<br>import { Assets } from &quot;unidata.js&quot;;<br>import { useEffect, useState } from &quot;react&quot;;<br>import { Asset } from &quot;unidata.js&quot;;<br><br>const unidata = new Unidata({});<br><br>async function getData() {<br>  const assets: Assets = await unidata.assets.get({<br>    source: &quot;Ethereum NFT&quot;,<br>    identity: &quot;0x0af3aF1049efc7Be735fa1499CeE6125B61CA175&quot;,<br>  });<br>  return assets;<br>}<br><br>function App() {<br>  const [data, setData] = useState&lt;{<br>    cursor?: any[];<br>    list?: Asset[];<br>    total?: number;<br>  }&gt;({});<br><br>  useEffect(() =&gt; {<br>    getData().then((res) =&gt; {<br>      setData(res);<br>    });<br>  }, []);<br><br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;header className=&quot;App-header&quot;&gt;<br>        &lt;p&gt;Unidata Demo:&lt;/p&gt;<br>      &lt;/header&gt;<br>      &lt;div style={{ background: &quot;grey&quot;, marginTop: &quot;-20px&quot;, paddingTop: &quot;5%&quot; }}&gt;<br>        {data.list?.map((t) =&gt; {<br>          return (<br>            &lt;&gt;<br>              &lt;p style={{ color: &quot;white&quot; }}&gt;{t.name}&lt;/p&gt;<br>              {t.items &amp;&amp; typeof t.items[0].address &amp;&amp; (<br>                &lt;&gt;<br>                  &lt;img<br>                    style={{ width: &quot;250px&quot; }}<br>                    src={t.items[0].address!}<br>                  &gt;&lt;/img&gt;<br>                &lt;/&gt;<br>              )}<br>            &lt;/&gt;<br>          );<br>        })}<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>這樣可以得到這個人所有的 Assets 資料，如以下結果：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9z2EXAm4pEd5V4K3H2cwJQ.png" /></figure><p>這個地址是我在 opensea 上隨便找的，看來是的 NFT 大亨。</p><h4>Get Notes:</h4><p>這裡我直接演示 getNotes 這個 function，可以直接和上面 example 中的 getData 做替換使用：</p><pre>async function getNotes() {<br>  const notes: Notes = await unidata.notes.get({<br>    source: &quot;Ethereum NFT Activity&quot;,<br>    identity: &quot;0xd8da6bf26964af9d7eed9e03e53415d37aa96045&quot;,<br>    platform: &quot;Ethereum&quot;,<br>    limit: 10,<br>  });<br>  return notes;<br>}</pre><p>把結果 console.log 出來：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VCtFZhN0mVWav-KCoZeDqA.png" /></figure><p>即可以取得 limit 筆的資料。</p><h4>Get Links:</h4><p>Links 的部分目前僅支援 crossbell，雖然目前 web3 的社群網站似乎也不多就是了…</p><p>這裡就用筆者的 crossbell 演示吧！目前還沒有任何好友…有興趣的人可以互追一下！</p><pre>async function getLinks() {<br>  const links: Links = await unidata.links.get({<br>    source: &#39;Crossbell Link&#39;,<br>    identity: &#39;0x0b88cd9c5B6B73145332316C199a5B3a52415730&#39;,<br>    platform: &#39;Ethereum&#39;,<br>});<br>  return links;<br>}</pre><p>會取得：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*U7pJrxOU7M9LaOEkA_yuZw.png" /><figcaption>空蕩蕩的0</figcaption></figure><p>想看多一點人追蹤回傳的資料型態可以到官方文件的<a href="https://unidata.app/guide/links/Crossbell-Link.html#live-demo">這裡</a>看看！</p><h4>Get Profiles:</h4><p>Profiles 的部分目前也是支援 crossbell, ENS 和 infura，那這裡我一樣用我自己的地址作演示給大家看！</p><pre>async function getProfiles() {<br>  const profiles: Profiles = await unidata.profiles.get({<br>    source: &quot;Crossbell Profile&quot;,<br>    identity: &quot;0x0b88cd9c5B6B73145332316C199a5B3a52415730&quot;,<br>    platform: &quot;Ethereum&quot;,<br>  });<br>  return profiles;<br>}</pre><p>把回傳的數據 console.log 出來：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fii7f1BiXrvvSPRO41B6Ow.png" /></figure><p>就可以看到這個帳號的一切。</p><h4>結語：</h4><p>今天這篇文章主要是補足一些比較實際的使用方式，用簡單的 React 以typescript 演示如何取得資料並將其展示在前端，整個使用過程真的感覺到 Unidata 是個好東西阿！最後希望這篇文章可以幫助到各種需要用到鏈上資料的前端工程師，節省大家在和鏈互動時花的時間！</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e8393df14ae" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swf-lab/unidata-%E5%A5%BD%E7%94%A8%E4%B8%94%E9%96%8B%E6%BA%90%E7%9A%84web3%E6%95%B8%E6%93%9A%E8%A8%AA%E5%95%8F%E5%B7%A5%E5%85%B7-3e8393df14ae">Unidata-好用且開源的web3數據訪問工具</a> was originally published in <a href="https://medium.com/swf-lab">SWF Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Python Dev] 在 poetry 環境下使用 github actions 來進行 CI -最終回]]></title>
            <link>https://medium.com/swf-lab/python-dev-%E5%9C%A8-poetry-%E7%92%B0%E5%A2%83%E4%B8%8B%E4%BD%BF%E7%94%A8-github-actions-%E4%BE%86%E9%80%B2%E8%A1%8C-ci-%E6%9C%80%E7%B5%82%E5%9B%9E-d26e1a4ce5cd?source=rss-a0abc1a3ee8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d26e1a4ce5cd</guid>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[ci]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[CookSen]]></dc:creator>
            <pubDate>Sun, 09 Oct 2022 03:58:37 GMT</pubDate>
            <atom:updated>2022-10-09T03:58:37.867Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Python Dev] 在 poetry 環境下使用 github actions 和 coveralls 來進行 CI -最終</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*naq6tS17CmDxXFAOaO4KtQ.png" /></figure><h4><strong>前言：</strong></h4><p>上一篇介紹了 github actions 的基本設定以及用法，最終得以透過 workflow 裡的 yml 檔設定來讓 github actions 自動在指定動作發生後跑寫好的腳本。這篇文章我會將這個功能結合 release ，同時會使用 poetry 打包，讓 github actions 在每個版本 release 後都可以自動測試，如此一來即可確保這個版本是穩定的，不用親自下載測試！</p><h4><strong>Pypi 使用介紹：</strong></h4><p>pypi 應該是所有 python 使用者最熟悉的 Python Software repository 了，所以我這裡就不多做說明，直接介紹新增 package 的流程。</p><p><strong>1. 創建帳號：<br></strong> <a href="https://pypi.org/">https://pypi.org/</a><br>直接到網站進行註冊即可。</p><p><strong>2. 創建並取得 project token：</strong></p><p>到右上角選 account settings，往下滑會看到 Add API token 的區域：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*0oYnx_1CCj_XNOmjre6keA.png" /><figcaption>Add API Token.</figcaption></figure><p>這裡先選 Entire account 的選項。</p><p><strong>3. 將 Token 加入 GitHub secret：</strong></p><p>接著我們要使用 Github secret 這個酷炫功能，只要你把東西放到這裡，就算是青天大老爺來也無法再次查看，所以在放進去之前一定要好好記住。</p><p>這裡附上官方 doc：</p><p><a href="https://docs.github.com/en/actions/security-guides/encrypted-secrets">Using secrets in GitHub Actions - GitHub Docs</a></p><p>我們可以在 project settings 的地方看到這一個選項：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*WnItsxwUT1KagUvWhL2IOA.png" /><figcaption>GitHub secret</figcaption></figure><p>在右邊按 “New repository secret”，然後取一個你想要的名字：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qCmp69abcf0jmbgZu6EfMA.png" /><figcaption>New Secret</figcaption></figure><p>之後 add secret 就可以了。</p><p>到這裡 pypi 的設定就結束了，接下來我們回到 github actions 和 poetry 的設定步驟。</p><h4><strong>Poetry 設定：</strong></h4><p>Poetry 在設定 publish 時非常方便，我們只需修改它的 toml file ，也就是我們前幾篇提到的 pyproject.toml：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*S-XyZPXqD6RgtImJBrV71w.png" /></figure><p>可以依照下面格式填：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*_24xv25KSs1WUBprpEQ9tA.png" /></figure><p>都填完後就算準備好了，poetry 在打包時有自己的指令 “publish”，關於他的用法我們會在下一個段落介紹到。</p><p>接著就讓我們進入到 github actions 的設定吧。</p><h4><strong>GitHub Actions 設定：</strong></h4><p>這裡一樣是在 workflow 裡新增 yml 檔案，我建立了一個名為 publish.yml 的檔案：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*DN-4o8zMjvvXs575BN6X4g.png" /><figcaption>my yml files</figcaption></figure><p>裡面的內容可以大致照這樣寫：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*-Br_aRmA0NzMhp0nq7Lsqg.png" /></figure><p>這串指令的意思就是當 release 這個動作被偵測到時，就會自動跑下面的指令，其中包含一些：</p><p><strong>新增 tag 的指令：</strong></p><blockquote>git checkout -b release/$GITHUB_REF_NAME</blockquote><blockquote>git push origin release/@GITHUB_REF_NAME</blockquote><p><strong>測試安裝：</strong></p><blockquote>poetry build</blockquote><p><strong>刪除安裝產生的 dist 然後上傳至 pypi：</strong></p><blockquote>rm -rf dist</blockquote><blockquote>poetry publish — build — username=__token__ — password=$PYPI_TOKEN</blockquote><p>可以看到我用到了 secrets.PYPI_TOKEN 這個指令來使用 github secret，如此一來，透過這個 env 變數 poetry publish 就可以把此 package 順利包起來上傳到 pypi 上。</p><h4>Trigger release:</h4><p>那我們要如何 trigger release 呢？</p><p>很簡單，只要到 repo 右邊的欄位選 release，然後選 draft a new release：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvIkUcRoQFLO2GCj8mQGbg.png" /></figure><p>新增一個 tag，這裡記得要和 pyproject 裡的 version 一致，然後輸入這次 release 的名字，修改筆記的部分可以直接點 Generate release notes，他會直接幫你整理並貼上版本間新增的 branch 簡述：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKkf19FAHKX_YmHFNH6Zww.png" /><figcaption>Generate release notes like a boss</figcaption></figure><p>接著按 “publish release“ 就可以 trigger 這個 yml 腳本了，我們可以在 github actions 的頁面裡看到：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aHtIL_pL2y0hf-cGfHumcw.png" /></figure><p>到這裡就大功告成了，可以到 Pypi 看看你 project 的頁面如何！</p><p>附上這次示範的 Project：（順便幫我實習公司打個小廣告…）</p><p><a href="https://pypi.org/project/decanter-ai-sdk/">decanter-ai-sdk</a></p><h4>小結：</h4><p>這篇文章主要是在介紹如何將 poetry 結合 github actions 將 python 專案自動打包到 pypi 上，並於 release 同時使用微軟富爸爸免費提供的環境做測試。</p><p>如此一來可以確保每次版本更新時，package 的可靠性，而這幾個工具合作使用也可大大提升開發的效率，以上三篇介紹，希望有幫助到大家！（我自己是覺得非常有用啦～</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d26e1a4ce5cd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swf-lab/python-dev-%E5%9C%A8-poetry-%E7%92%B0%E5%A2%83%E4%B8%8B%E4%BD%BF%E7%94%A8-github-actions-%E4%BE%86%E9%80%B2%E8%A1%8C-ci-%E6%9C%80%E7%B5%82%E5%9B%9E-d26e1a4ce5cd">[Python Dev] 在 poetry 環境下使用 github actions 來進行 CI -最終回</a> was originally published in <a href="https://medium.com/swf-lab">SWF Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Python Dev] 在poetry環境下使用github actions和coveralls來進行CI 之二]]></title>
            <link>https://medium.com/swf-lab/python-dev-%E5%9C%A8poetry%E7%92%B0%E5%A2%83%E4%B8%8B%E4%BD%BF%E7%94%A8github-actions%E5%92%8Ccoveralls%E4%BE%86%E9%80%B2%E8%A1%8Cci-%E4%B9%8B%E4%BA%8C-ba6772acc847?source=rss-a0abc1a3ee8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba6772acc847</guid>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[cicd]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[CookSen]]></dc:creator>
            <pubDate>Sat, 10 Sep 2022 05:32:54 GMT</pubDate>
            <atom:updated>2024-03-07T04:24:39.059Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Python Dev] 在 poetry 環境下使用 github actions 和 coveralls 來進行 CI 之二</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*naq6tS17CmDxXFAOaO4KtQ.png" /></figure><h4>前言：</h4><p>上一篇我大致介紹了 poetry 和 poethepoet 是什麼，以及如何一起使用提高開發效率，我們最終得以透過 toml 檔裡的 task runner 來快速在 poetry 環境中執行一些套件的指令。今天我會介紹 github actions 同時介紹如何將這些 task 結合到你的 actions 中。</p><p>那就開始吧！</p><h4>Tasks and GitHub Actions:</h4><h4><strong>GitHub Actions:</strong></h4><p><strong>What is it:</strong></p><p>在使用 github actions 之前當然要先來介紹一下，讓大家知道為什麼他這麼受推崇！</p><p>Github actions 是 github 推出的一個 CI/CD 工具，他可以建立在幾乎所有語言的 Repo 上，而他最主要的目的我們可以透過官方說明了解：</p><blockquote>Automate your workflow from idea to production</blockquote><p>而其厲害之處在於他讓 github 不只有以往強力的版本控制能力，還新增了所謂的 workflows ，包含了能將一個專案最常遇到的 Build、Test、Deploy 等步驟自動化之功能。</p><p>這就表示，當我們多人在合作一個專案時，常常會有新的 feature branch 分給不同的人寫，而通常當一個人寫完他的部分準備建 PR 前，都大概會先經果幾個步驟，像是確認 linter、format、run unit test 然後建立 PR；等建好的 PR 被 approve 後，就要 merge 到 main branch ，這時候要考慮的點就是要準備 release ，要建立 note、tag 等等，並最後打包看是要 deploy 到哪裡。</p><p>而當越來越多人共同合作時，就會產生跟上一篇提到的 task 差不多的情況，也就是當貢獻者太多的時候，整個流程會變得很混亂，這時我們就需要 GitHub Actions 了！</p><p>GitHub Actions 可以透過設定去偵測不同的動作，比如說建立 PR ，merge 到某個 branch 或是 release 等，並可先寫好相關動作被 trigger 時該做什麼，如此一來在整個流程上會自動且清楚許多。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3QnUuMuXBmXjDQOdLZxvug.png" /><figcaption>ref: <a href="https://github.com/features/actions">https://github.com/features/actions</a></figcaption></figure><p>透過官方文件可以看到當 push 這個動作被偵測到時，GitHub Actions 就會自動跑 test 這個指令。</p><p>那我們接下來就直接看看實際上的運用吧！</p><p><strong>Usage:</strong></p><p>首先先附上官方文件 — <a href="https://docs.github.com/en/actions">GitHub Actions</a></p><p>再來我們要先在你的專案裡新增一個 folder 叫 .github，並在裡面再新增一個 workflows folder。</p><p>接著在裡面建立一個偵測 PR 的 workflow 吧！GitHub Action 是透過 yml 檔來設定 workflow 的，所以可以寫成這樣：</p><p>pr.yml:</p><pre>name: pr</pre><pre>on:<br>  pull_request:<br>    types:<br>      - opened<br>      - edited<br>      - synchronize</pre><pre>jobs:<br>  pr_test:<br>    runs-on: ubuntu-latest<br>    strategy:<br>      fail-fast: true<br>      matrix:<br>        python-version: [&quot;3.10&quot;]<br>        poetry-version: [&quot;1.1.14&quot;]<br>      <br>    steps:<br>      - uses: actions/checkout@v2</pre><pre>- name: Set up Python ${{ matrix.python-version }}<br>        uses: actions/setup-python@v2<br>        with:<br>          python-version: ${{ matrix.python-version }}</pre><pre>- uses: abatilo/actions-poetry@v2.0.0<br>        with:<br>          poetry-version: ${{ matrix.poetry-version }}</pre><pre>- name: Install dependencies<br>        run: poetry install</pre><pre>- name: Run Lint<br>        run: poetry run poe lint<br>      <br>      - name: Run Test<br>        run: |<br>          poetry run poe test</pre><p>這裡可以看到 code 主要目的是偵測 pull request，然後下面的 types 就是 specify 在哪種動作時會跑下面的 workflow，這裡也有其他寫法，可以寫成追蹤特定 branch 等形式。</p><blockquote>偵測 master branch：</blockquote><pre>name: pr</pre><pre>on:<br>  pull_request:<br>    branches: [&quot;master&quot;]</pre><p>再來 jobs 顧名思義就是可以設定各種你要跑的 job，接續的第一個縮排會是第一個 job 的名稱，然後一些環境基本設定，再來就是接 steps。</p><p>steps 可以讓你寫你要讓這台測試機跑哪些指令，而這些測試機都是微軟爸爸出資給 github 上 open source repo 使用的，在這裡也謝謝微軟爸爸讓我們一起為開源的環境盡一份心力！</p><p>這裡可以看到我跑的就是上ㄧ篇介紹用 poethepoet 建立的 tasks，像是安裝、跑 lint、還有跑 test 等。其中還有幾個比較特別的，像是 abatilo/actions-poetry@v2.0.0 ，這種其實就是別人寫好的一些套件 api，讓我們可以直接使用，要確認內容可以直接上網搜尋：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o6vWniLFv9UVjGRDi2GKtg.png" /><figcaption>ref: <a href="https://github.com/abatilo/actions-poetry">https://github.com/abatilo/actions-poetry</a></figcaption></figure><p>這些基本設定大功告成後就可以直接建一個 pr 然後 push 上去了。</p><p>之後到你 github repo 的頁面（記得要是同一個）：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4rRTTbA0-oXvI89KOVkEkA.png" /></figure><p>可以看到有一個 Actions 的按鈕，點開：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z5P0x4AGShBLoYLxnd-lJQ.png" /></figure><p>就可以看到 pr 的 workflow 已經成功運行了，點開裡面細看：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TCWZtks66AIV6bPv7wM8_g.png" /></figure><p>就可以看到你的 shell 指令運行的樣子了！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LVXWu77wwzOtt0yVT75Rfg.gif" /></figure><h4><strong>小結：</strong></h4><p>這篇文章介紹了 Github Actions 的一些基本用法，同時結合上一篇提到的 poetry 和 poethepoet，成功在 poetry 環境下建立一個 CI workflow。</p><p>那下一篇我會介紹如何使用一些外部好用的 CI 工具，同時示範使用 release workflow 讓他自動更新 tag 並 deploy。（這裡以pypi為例）</p><p>謝謝大家！</p><h4>Reference:</h4><ul><li>GitHub Action docs: <a href="https://github.com/features/actions">https://github.com/features/actions</a></li><li>我的 Repo: <a href="https://github.com/MoBagel/decanter-ai-sdk">https://github.com/MoBagel/decanter-ai-sdk</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba6772acc847" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swf-lab/python-dev-%E5%9C%A8poetry%E7%92%B0%E5%A2%83%E4%B8%8B%E4%BD%BF%E7%94%A8github-actions%E5%92%8Ccoveralls%E4%BE%86%E9%80%B2%E8%A1%8Cci-%E4%B9%8B%E4%BA%8C-ba6772acc847">[Python Dev] 在poetry環境下使用github actions和coveralls來進行CI 之二</a> was originally published in <a href="https://medium.com/swf-lab">SWF Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[[Python Dev] 在 poetry 環境下使用 github actions 來進行 CI 之一]]></title>
            <link>https://medium.com/swf-lab/python-dev-%E5%9C%A8-poetry-%E7%92%B0%E5%A2%83%E4%B8%8B%E4%BD%BF%E7%94%A8-github-actions-%E4%BE%86%E9%80%B2%E8%A1%8C-ci-%E4%B9%8B%E4%B8%80-42bd66da529e?source=rss-a0abc1a3ee8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/42bd66da529e</guid>
            <category><![CDATA[dev]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <dc:creator><![CDATA[CookSen]]></dc:creator>
            <pubDate>Fri, 09 Sep 2022 17:52:09 GMT</pubDate>
            <atom:updated>2022-09-09T17:52:09.334Z</atom:updated>
            <content:encoded><![CDATA[<h3>[Python Dev] 在poetry環境下使用github actions和coveralls來進行CI 之一</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k0t7bG77GJmodmInloMOjw.png" /></figure><h4><strong>前言：</strong></h4><p>前幾天想試著把 poetry、github actions 和 coveralls.py 這三個東西一起結合使用，建立一個可以自動更新 code coverage 的 CI 流程，最後得到還不錯的結果，所以想說寫一篇文做個紀錄同時推廣一下這些好用的開發工具。</p><p>這系列文會牽扯到幾個工具和他們的用法，我預計用三篇文章來完成。</p><h4><strong>三篇文章內容：</strong></h4><ul><li>簡述 Poetry、poethepoet 與開始使用</li><li>簡述 github actions 與 coveralls.py</li><li>建立開發流程</li></ul><p>那就開始吧！</p><h3><strong>Poetry and Poethepoet:</strong></h3><h4>Poetry:</h4><p><strong>What is it:</strong></p><p>Poetry 如同其他 pip, pipenv 等套件一樣，簡單來說就是 python 套件管理系統，但 Poetry 比其他套件更強的地方是他同時包含</p><ul><li>virtual environment</li><li>package dependency</li><li>packaging</li></ul><p>三個完善的管理功能。</p><p>而每一個套件管理系統都會有一套自己的 package 管理清單，有點像在寫 node 的時候會有的 package.json ，在 poetry 裡就是 pyproject.toml。而其實 pyproject.toml 這個檔案形式也有在 <a href="https://peps.python.org/pep-0621/">pep 621</a> 被提到，定義為正式的設定檔標準，已經有不少套件支持。接下來就大致介紹一下如何開始使用 poetry 吧！</p><p><strong>Usage:</strong></p><p>首先附上官方文件 — <a href="https://python-poetry.org/docs/">Poetry</a>。</p><p>再來不免俗的一定要先使用 pip 安裝：</p><p>pip install poetry</p><p>安裝好之後可以直接新增一個 poetry 專案：</p><p><em>是不是覺得跟React似曾相似阿</em></p><pre>poetry new --src my-package</pre><p>這時就會得到一個基本的 poetry project 架構：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*hyyMmXPdAbubtmW9LE01sg.png" /></figure><p>正常來講得到這個架構就可以開始開發了，但這裡我習慣再安裝 poethepoet 這個插件來進行之後的 task 管理，安裝同時我也會順便介紹一些 poetry 常用的操作指令。</p><p><strong>安裝：</strong>poetry add --dev &lt;poethepoet&gt;</p><blockquote>這時可以看到 pyproject.toml：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*YRvbIh5p_pJg4rUOvIgwwA.png" /></figure><blockquote>已經把我們用到的 dependencies 都更新好了。在這裡可以注意到 poetry add 有加上 dev 這個 flag 時，表示只供開發使用，所以一般人安裝的版本是不會有這些 dev 裡的 dependencies 的。如果安裝一般套件直接用 poetry add blablabla 就可以了。</blockquote><p><strong>刪除：</strong> poetry remove &lt;blablabla&gt;</p><p><strong>更新Lock：</strong> poetry lock</p><blockquote>這裡就要提到一下這個 lock 檔的作用了，在使用 poetry 時有可能會遇到要手動在 toml 檔裡解決衝突的狀況，當 toml 檔案受到變動時 lock 檔就有更新的必要，因為在 env setup 階段時主要是透過 lock 檔，這時就會需要上面提到的這個指令。</blockquote><p><strong>很酷的樹狀功能：</strong> poetry show --tree</p><blockquote>可以把 dependencies 用樹狀結構顯示出來：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*t3KqkqLsMybyVd0p1WVghw.jpeg" /></figure><p>那前面安裝的這個 poethepoet 又是怎麼個用法呢？我們接著介紹。</p><h4><strong>Poethepoet:</strong></h4><p><strong>What is it:</strong></p><p>要介紹 Poethepoet 我們可以直接看官方簡短的說明：</p><blockquote>A task runner that works well with poetry.</blockquote><p>就這麼簡單！但如果沒有接觸過類似概念應該會覺得有點模糊，不會沒關係，我相信透過接下來一些舉例可以讓各位很快了解他的概念以及好用之處。</p><p><strong>Usage:</strong></p><p>這裡先附上官方文件 — <a href="https://github.com/nat-n/poethepoet">Poethepoet</a></p><p>再來我們接續剛剛的 pyproject.toml 檔，在裡面新增幾行字。</p><blockquote><em>以下只是大概展示他的結構，會用到一些前面沒有提到的套件。</em></blockquote><pre>[tool.poe.env]<br>SRC = &quot;my-package&quot;<br>DIFF.default = &quot;&quot;<br>INPLACE.default = &quot;--in-place&quot;</pre><pre>[tool.poe.tasks]<br>_black = &#39;black $SRC $DIFF --color&#39;<br>_mypy-install-type = &#39;mypy $SRC --ignore-missing-imports --install-types --non-interactive&#39;<br>_mypy = &#39;mypy $SRC --ignore-missing-imports&#39;</pre><p>這些由 tool 開頭的就是 poethepoet 定義的 env 或是 task，env 的部分主要可以設置一些 Global variables；而 task 主要有四種形態，分別是 simple commands <em>(cmd)</em>, python scripts <em>(script)</em>, shell scripts <em>(shell)</em>, 和sequence tasks <em>(sequence)</em>，像這邊我可以結合 pytest, pytest-cov 來建立一個之後跑 unit test 的 task:</p><pre>[tool.poe.tasks.test]<br>help = &quot;Testing tasks.&quot;<br>shell = &quot;&quot;&quot;<br>echo run unit tests<br>pytest --cov=$SRC --cov-report term-missing<br>&quot;&quot;&quot;</pre><p>如此一來我只要在 terminal 跑 poe test 就可以進行 unit test ，這樣的功能在只有少數指令時可能會顯得有點雞肋或是混亂，但通常一個專案除了 test 外可能至少還會有 lint 跟 format 等需求，當有很多 task 要跑時，有這樣一個管理全部的工具就可以大大減少混亂程度並提高開發效率。</p><h4>小結：</h4><p>這篇文章主要先介紹 poetry 和 poethepoet 的基本用法，這些都和之後會一起使用的 github actions 息息相關。</p><p>下一篇會介紹 github actions 的基本用法跟如何和其他 CI 工具一起使用，讓專案在建 pr 或是 push 到任意 branch 時可以自動跑我們設定好的指令。（同時好好利用微軟爸爸給的資源）</p><p>謝謝大家！</p><h4>References:</h4><ul><li>pep-518:<a href="https://peps.python.org/pep-0518/">https://peps.python.org/pep-0518/</a></li><li>pep-621:<a href="https://peps.python.org/pep-0621/">https://peps.python.org/pep-0621/</a></li><li>poetry:<a href="https://python-poetry.org/docs/">https://python-poetry.org/docs/</a></li><li>poethepoet:<a href="https://github.com/nat-n/poethepoet">https://github.com/nat-n/poethepoet</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42bd66da529e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swf-lab/python-dev-%E5%9C%A8-poetry-%E7%92%B0%E5%A2%83%E4%B8%8B%E4%BD%BF%E7%94%A8-github-actions-%E4%BE%86%E9%80%B2%E8%A1%8C-ci-%E4%B9%8B%E4%B8%80-42bd66da529e">[Python Dev] 在 poetry 環境下使用 github actions 來進行 CI 之一</a> was originally published in <a href="https://medium.com/swf-lab">SWF Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>