<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Matt Davis</title>
    <description>The latest articles on DEV Community by Matt Davis (@matteius).</description>
    <link>https://dev.to/matteius</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F919151%2F4f564dec-18bf-4ec2-a3fe-3841f937ee8b.jpeg</url>
      <title>DEV Community: Matt Davis</title>
      <link>https://dev.to/matteius</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/matteius"/>
    <language>en</language>
    <item>
      <title>Pipenv: Named Categories</title>
      <dc:creator>Matt Davis</dc:creator>
      <pubDate>Sun, 09 Oct 2022 15:15:50 +0000</pubDate>
      <link>https://dev.to/matteius/pipenv-named-categories-2bh8</link>
      <guid>https://dev.to/matteius/pipenv-named-categories-2bh8</guid>
      <description>&lt;p&gt;Today I am happy to announce expanded support for "named package categories" in the release of &lt;code&gt;pipenv==2022.10.9&lt;/code&gt; and here I will explain what this feature is about and some ways you might find it helpful.  You may also wish to reference the &lt;a href="https://pipenv.pypa.io/en/latest/basics/#specifying-package-categories"&gt;package categories documentation&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;If you are already familiar with &lt;code&gt;pipenv&lt;/code&gt; then you are probably aware that until now the tool only supported two package groups: &lt;code&gt;packages&lt;/code&gt; and &lt;code&gt;dev-packages&lt;/code&gt;.  These mapped to the &lt;code&gt;default&lt;/code&gt; and &lt;code&gt;develop&lt;/code&gt; groups in the lock file.&lt;/p&gt;

&lt;p&gt;What if you wanted to have other groups defined? For example: sometimes prerequisites are required to build other packages that are part of your default package group and these have to be installed ahead of time.  &lt;/p&gt;

&lt;p&gt;Let's say the setup.py being built has &lt;code&gt;import six&lt;/code&gt; but &lt;code&gt;six&lt;/code&gt; is not installed, and so pipenv gets errors trying to build and install the dependent package.  The guidance prior was to &lt;code&gt;pipenv run pip install six&lt;/code&gt; ahead of running &lt;code&gt;pipenv sync&lt;/code&gt; so that it would be available.  Now though it should be possible to define an arbitrary group of prerequisites, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# install prerequisite package six
# note: single category syntax
pipenv install six --catetgories prereq

# install the perquisite group followed by the packages group
# note: multiple categories syntax
pipenv sync --categories="prereq packages"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Support was added for across the range of &lt;code&gt;pipenv&lt;/code&gt; commands for the &lt;code&gt;categories&lt;/code&gt; argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# lock and uninstall examples
pipenv lock --categories="prereq dev-packages"
pipenv uninstall six --categories prereq
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The &lt;code&gt;packages&lt;/code&gt;/&lt;code&gt;default&lt;/code&gt; specifiers are used to constrain all other categories just as they have done for &lt;code&gt;dev-packages&lt;/code&gt;/&lt;code&gt;develop&lt;/code&gt; category.  However this is the only way constraints are applied.  The presence of other named groups do not constraint each other, which means it is possible to define conflicting package versions across groups.  This may be desired in some use cases where users only are installing groups specific to their system platform.&lt;/p&gt;

&lt;p&gt;Some organizations may wish to explore using named package categories to specify platform specific dependencies in groups such as &lt;code&gt;linux&lt;/code&gt;, &lt;code&gt;windows&lt;/code&gt; or &lt;code&gt;macos&lt;/code&gt;.  Using platform groupings may be a useful mechanism to work around some limitations of the &lt;code&gt;pip&lt;/code&gt; resolver with regards to resolving certain platform specific packages targeting an alternate platform than the one being locked.&lt;/p&gt;

&lt;p&gt;This change was also made possible by the concurrent efforts of &lt;a href="https://github.com/oz123"&gt;Oz Tiram&lt;/a&gt; who first converted &lt;code&gt;pipenv&lt;/code&gt; to the library &lt;code&gt;plette&lt;/code&gt; for its Pipfile/Pipfile.lock management.  Since we have access to modify &lt;code&gt;plette&lt;/code&gt; it became possible to release changes required to support the feature of named package categories.&lt;/p&gt;

&lt;p&gt;This particular feature for arbitrarily named package groups was requested multiple times in the &lt;code&gt;pipenv&lt;/code&gt; issues reports. I hope the users of pipenv find this feature helpful in project workflows.  Have you imagined other use cases not described in this article?  Feel free to drop a message in the comments or send us a note.&lt;/p&gt;

</description>
      <category>pipenv</category>
      <category>python</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Pipenv Install Performance Improved</title>
      <dc:creator>Matt Davis</dc:creator>
      <pubDate>Tue, 06 Sep 2022 20:03:05 +0000</pubDate>
      <link>https://dev.to/matteius/pipenv-install-performance-improved-5cdn</link>
      <guid>https://dev.to/matteius/pipenv-install-performance-improved-5cdn</guid>
      <description>&lt;p&gt;It wasn't until I changed jobs in November of 2021 that I began using something other than &lt;code&gt;pip&lt;/code&gt; to manage Python packages for my projects.  I started using &lt;code&gt;pipenv&lt;/code&gt; at work and felt that it had a solid base and should use it in my own projects to manage package hashes and provide a more secure install.  I also quickly realized that there were areas of the &lt;code&gt;pipenv&lt;/code&gt; codebase that needed improvement.&lt;/p&gt;

&lt;p&gt;I found myself combing through the GitHub Issues, triaging reports and responding to other users.  At the start of 2022 I joined forces with &lt;a href="https://github.com/oz123" rel="noopener noreferrer"&gt;Oz Tiram&lt;/a&gt;--with the support of &lt;a href="https://github.com/frostming" rel="noopener noreferrer"&gt;Frost Ming&lt;/a&gt; who was seeking &lt;a href="https://pipenv.pypa.io/en/latest/" rel="noopener noreferrer"&gt;pipenv&lt;/a&gt; maintainers in order to work more exclusively on &lt;a href="https://pdm.fming.dev/latest/" rel="noopener noreferrer"&gt;pdm&lt;/a&gt;, a modern alternative python package manager.&lt;/p&gt;

&lt;p&gt;We have been hard at work in our spare time improving pipenv and there have have been more than a few exciting releases this year.  The latest and greatest &lt;code&gt;pipenv==2022.9.4&lt;/code&gt; has worked out the remaining edge cases in a performance optimization that was released the end of August 2022.&lt;/p&gt;

&lt;p&gt;Benchmarks have been a tough question to answer in the python package manager space--there are many variables: host computer, internet connection, private package indexes, many dependencies, resolver, installer, oh my!  Well fortunately at the end of July 2022 Lincoln Loop built an &lt;a href="https://lincolnloop.com/blog/python-package-manager-shootout/" rel="noopener noreferrer"&gt;independent benchmark for python package managers&lt;/a&gt; which runs on GitHub actions every 6 hours and averages the results over the prior 4 runs for the primary python package managers.   &lt;/p&gt;

&lt;p&gt;Upon learning of this benchmark, we began exporting the results at major release points in order to have data to track how pipenv performance is overtime.  The &lt;code&gt;2022.8.5&lt;/code&gt; release had an average install benchmark time of just under 150 seconds, and perhaps the &lt;code&gt;2022.8.24&lt;/code&gt; release was marginally faster than that, we had just fully dropped &lt;code&gt;pip-shims&lt;/code&gt; after all.  The reality was, pipenv install was still slow and so I spent a weekend looking over the install logic in more detail and refactoring how the batch install worked.&lt;/p&gt;

&lt;p&gt;The fundamental problem was that &lt;code&gt;pip&lt;/code&gt; was being invoked per individual dependency and on my 8 core SMT processor laptop it sounded like a plane taking off.  I began to wonder about batching up the resolved dependencies and invoking &lt;code&gt;pip&lt;/code&gt; a minimal number of times to accomplish the same install. It turned out that the prior level of parallelism used a lot of processing power without improving the wall clock time.  &lt;/p&gt;

&lt;p&gt;The other potential problem was doing a true batch install meant it was no longer possible to show an incremental progress bar, where the increment the completion of each individual package install.  The compromise here was to read the &lt;code&gt;stdout&lt;/code&gt; of the &lt;code&gt;pip&lt;/code&gt; process in real-time for users that pass in the &lt;code&gt;--verbose&lt;/code&gt; flag which allows observing the installation progress, though its not visually a progress bar.&lt;/p&gt;

&lt;p&gt;My PR went through the peer review process and fortunately Oz is very supportive of making such changes for performance, and so the excitement began to grow as we got closer to releasing the enhancement.  What would our benchmark tell us about the install performance after this released?   Based on my best feeling, I was expecting it could be a 33% speed increase but it was anybody's guess.  Then August 31st we got our first inclination that the improvement was closer to 50% for the case of installing the sentry requirements, whoa!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmfi34ajcyo2jygi17b53.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmfi34ajcyo2jygi17b53.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how does &lt;code&gt;pipenv==2022.9.4&lt;/code&gt; compare to the other package managers for install speed?  Here are the benchmarks at the time of writing:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0kd15xqfufdzvfgwp3fs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0kd15xqfufdzvfgwp3fs.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the latest benchmarks and complete stats for each operation: install, lock, update, add package, and tooling--visit the &lt;a href="https://lincolnloop.github.io/python-package-manager-shootout/" rel="noopener noreferrer"&gt;Python Package Manager Shootout&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>pipenv</category>
      <category>python</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
