{"id":478,"date":"2023-06-18T11:41:07","date_gmt":"2023-06-18T11:41:07","guid":{"rendered":"https:\/\/blogs.gentoo.org\/gsoc\/?p=478"},"modified":"2023-06-18T11:41:07","modified_gmt":"2023-06-18T11:41:07","slug":"week-2-modernization-of-portage","status":"publish","type":"post","link":"https:\/\/blogs.gentoo.org\/gsoc\/2023\/06\/18\/week-2-modernization-of-portage\/","title":{"rendered":"Week 2 &#8211; Modernization of Portage"},"content":{"rendered":"<h1 id=\"week-2---modernization-of-portage\">Week 2 &#8211; Modernization of Portage<\/h1>\n<p>It is the second week of coding period and it has been a productive one. It started according to the\u00a0 plans and diverged in the second half for the good. The first half was towards type annotation and the second half was <code>dummy_threading<\/code> deprecation.<\/p>\n<h2 id=\"type-annotation\">Type annotation<\/h2>\n<p>In the words of Sam, my mentor, \u201cI\u2019d considere a GSOC project complete if some 50% of the\u00a0 codebase is just type annotated\u201d. Many portage developers were excited when we were talking\u00a0 about adding type hints and docstrings.<\/p>\n<p>Adding type hints and tidying up the codebase will also give me more exposure to the underlying functions. So, we decided, this week I\u2019ll do type annotations.<\/p>\n<h3 id=\"deciding-on-the-type-hints-style\">Deciding on the type hints style<\/h3>\n<p>Python 3.9 adds a simpler \u201cnative\u201d style type annotation, but portage has a minimum supported python version of 3.7.<\/p>\n<p>Eg.<\/p>\n<div id=\"cb1\" class=\"sourceCode\">\n<pre class=\"sourceCode py\"><code class=\"sourceCode python\"><span id=\"cb1-1\"><span class=\"co\"># Python 3.7 style<\/span><\/span>\r\n<span id=\"cb1-2\">a: typing.Optional[typing.List[<span class=\"bu\">str<\/span>]] <span class=\"op\">=<\/span> <span class=\"va\">None<\/span><\/span>\r\n<span id=\"cb1-3\">b: typing.Dict[<span class=\"bu\">int<\/span>] <span class=\"op\">=<\/span> {}<\/span>\r\n<span id=\"cb1-4\"><\/span>\r\n<span id=\"cb1-5\"><span class=\"co\"># Python 3.9 style<\/span><\/span>\r\n<span id=\"cb1-6\">a: <span class=\"bu\">list<\/span>[<span class=\"bu\">str<\/span>] <span class=\"op\">|<\/span> <span class=\"va\">None<\/span> <span class=\"op\">=<\/span> <span class=\"va\">None<\/span><\/span>\r\n<span id=\"cb1-7\">b: <span class=\"bu\">dict<\/span>[<span class=\"bu\">int<\/span>] <span class=\"op\">=<\/span> {}<\/span><\/code><\/pre>\n<\/div>\n<p>We can see that the 3.9 style is arguably more readable and we don\u2019t have to import the typing module.<\/p>\n<p>There is talk on increasing portage\u2019s MSV to python 3.9, but till that is accepted, we decided to stick with python 3.7 style type annotations.<\/p>\n<p>So, I added some type annotations and docstrings. Sam reviewed them and suggested a few\u00a0 changes. After making the necessary changes, the pull request was merged. It can be found <a href=\"https:\/\/github.com\/gentoo\/portage\/pull\/1048\">here<\/a>. Portage\u2019s need of type hints and docstrings can be felt by <span class=\"citation\" data-cites=\"ajakk\">@ajakk<\/span>\u2019s comment <a href=\"https:\/\/github.com\/gentoo\/portage\/pull\/1048#issuecomment-1583967905\">here<\/a><\/p>\n<h2 id=\"dummy_threading-deprecation\"><code>dummy_threading\u00a0<\/code>deprecation<\/h2>\n<p><code>dummy_threading<\/code> existed in python as threading was not stabilied in a few platforms. As I said in the first blog post, portage has to work on many platforms and different architectures. So, portage<br \/>\nhad to take into account of the cases where <code>threading<\/code> might not be available.<\/p>\n<p>But, things have been stabilized and from python version 3.7, <code>dummy_threading<\/code> is deprecated. Since portage\u2019s MSV is python 3.7 we decided to remove all <code>dummy_threading<\/code> related<br \/>\ncode.<\/p>\n<p>I removed everything related to <code>dummy_threading<\/code> and updated the tests according to the changed code. It took some 8 commits. I squashed everything and sent a pull request to GitHub. It can be found <a href=\"https:\/\/github.com\/gentoo\/portage\/pull\/1052\">here<\/a> Sam checked it once and it was held for some time to see if someone finds a mistake. Sam also said he wanted to get a look one more time with a fresh set of eyes. It was merged shortly.<\/p>\n<h2 id=\"summary\">Summary<\/h2>\n<p>TLDR, I sent two pull requests and both are merged<\/p>\n<ul>\n<li>The first one with some type hints and docstrings.<\/li>\n<li>The second one where all code related to <code>dummy_threading<\/code> is removed.<\/li>\n<\/ul>\n<p>So, that marks the end of week two. Next week\u2019s work probably is towards more type annotations and some minor improvements. I\u2019ll keep you posted. Until then, take care!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Week 2 &#8211; Modernization of Portage It is the second week of coding period and it has been a productive one. It started according to the\u00a0 plans and diverged in the second half for the good. The first half was &hellip; <a href=\"https:\/\/blogs.gentoo.org\/gsoc\/2023\/06\/18\/week-2-modernization-of-portage\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":180,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,19],"tags":[3,24],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/posts\/478"}],"collection":[{"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/users\/180"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/comments?post=478"}],"version-history":[{"count":1,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/posts\/478\/revisions"}],"predecessor-version":[{"id":479,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/posts\/478\/revisions\/479"}],"wp:attachment":[{"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/media?parent=478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/categories?post=478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gentoo.org\/gsoc\/wp-json\/wp\/v2\/tags?post=478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}