<?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: Sharla</title>
    <description>The latest articles on DEV Community by Sharla (@elanorigby).</description>
    <link>https://dev.to/elanorigby</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%2F94605%2F0e505db6-7672-4cee-a5ae-6bab06bdb145.jpeg</url>
      <title>DEV Community: Sharla</title>
      <link>https://dev.to/elanorigby</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/elanorigby"/>
    <language>en</language>
    <item>
      <title>I love pipenv's custom script shortcuts</title>
      <dc:creator>Sharla</dc:creator>
      <pubDate>Wed, 22 Aug 2018 19:26:36 +0000</pubDate>
      <link>https://dev.to/elanorigby/i-love-pipenvs-custom-script-shortcuts-156k</link>
      <guid>https://dev.to/elanorigby/i-love-pipenvs-custom-script-shortcuts-156k</guid>
      <description>&lt;p&gt;&lt;em&gt;Update: I decided the below documentation is a bit naff, so I submitted a PR with some changes, and they were accepted! 🎉 Check it out - &lt;a href="https://pipenv.readthedocs.io/en/latest/advanced/#custom-script-shortcuts"&gt;https://pipenv.readthedocs.io/en/latest/advanced/#custom-script-shortcuts&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;From &lt;a href="https://pipenv.readthedocs.io/en/latest/advanced/#custom-script-shortcuts"&gt;the documentation&lt;/a&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  ☤ Custom Script Shortcuts
&lt;/h3&gt;

&lt;p&gt;Pipenv supports to customize shortcuts in the &lt;code&gt;scripts&lt;/code&gt; section. &lt;code&gt;pipenv run&lt;/code&gt; will automatically load it and find the correct command to replace with. Given the Pipfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [scripts]
    printfoo = "python -c \"print('foo')\""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can type in your terminal to run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    $ pipenv run printfoo
    foo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;/&lt;em&gt;end documentation&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;And it's really that simple! It runs the script you give it with the pipenv virtual environment context whether you have your pipenv shell activated or not. I have found this super useful for running tests, individual modules, and custom commands. &lt;/p&gt;

&lt;p&gt;For example, I use the autopep8 library so I can keep my whitespacing beautiful without the elbow grease of adding extra lines manually, so I have this line in the &lt;code&gt;[scripts]&lt;/code&gt; section of my Pipfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pep8 = "autopep8 -riv --max-line-length 150"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, I can run &lt;code&gt;pipenv run pep8 &amp;lt;file or directory name&amp;gt;&lt;/code&gt; and poof! one line at the end of each file, two lines between functions, one line between methods, etc. (Note: I do not actually think 150 is a good max line length, I just don't love where the tool auto-breaks lines, so I'd rather make those choices manually.)&lt;/p&gt;

&lt;h3&gt;
  
  
  Caveats
&lt;/h3&gt;

&lt;p&gt;As far as I can work out, anything that you could run in your terminal with your pipenv shell activated will work, with the notable exeption that you can't chain commands. I have not been able to get &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, &lt;code&gt;||&lt;/code&gt;, or &lt;code&gt;;&lt;/code&gt; to work. This doesn't really bother me, because if you really need to make a multiple command script, you can make an actual script file and run that from &lt;code&gt;[scripts]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, I have a somewhat complex script running my test suite (mostly to add color) and I have a &lt;code&gt;test.sh&lt;/code&gt; file in the &lt;code&gt;scripts/&lt;/code&gt; directory. This is what I have in my Pipfile:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[scripts]
tests = "./scripts/test.sh"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I type &lt;code&gt;pipenv run tests&lt;/code&gt; and so it does.&lt;/p&gt;

&lt;p&gt;If you've not been using this feature of pipenv, give it a try! Let me know what you end up using it for =)&lt;/p&gt;

&lt;p&gt;If you've not switch to using pipenv yet, consider this a bit of incentive. I just switched this project from &lt;code&gt;requirements.txt&lt;/code&gt; and virtualenv/pyenv and it was not bad at all. It took a bit of persistence to hunt down all the necessary changes in our continuous integration / deployment system, but the changes themselves were not difficult. &lt;/p&gt;

&lt;p&gt;Cheers 🥂🐍🙆🏻‍♀️    &lt;/p&gt;

</description>
      <category>python</category>
      <category>pip</category>
      <category>pipenv</category>
      <category>pipfile</category>
    </item>
  </channel>
</rss>
