<?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>Forem: Daniel Beadle</title>
    <description>The latest articles on Forem by Daniel Beadle (@djbeadle).</description>
    <link>https://forem.com/djbeadle</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%2F93664%2F25091217-d8d9-48de-adce-ee46a137f558.jpeg</url>
      <title>Forem: Daniel Beadle</title>
      <link>https://forem.com/djbeadle</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/djbeadle"/>
    <language>en</language>
    <item>
      <title>Debugging a Pip Package in Visual Studio Code</title>
      <dc:creator>Daniel Beadle</dc:creator>
      <pubDate>Fri, 10 May 2019 18:06:30 +0000</pubDate>
      <link>https://forem.com/djbeadle/debugging-a-pip-package-in-visual-studio-code-2if9</link>
      <guid>https://forem.com/djbeadle/debugging-a-pip-package-in-visual-studio-code-2if9</guid>
      <description>&lt;p&gt;Let's consider the case where you're writing some &lt;strong&gt;&lt;em&gt;incredibly&lt;/em&gt;&lt;/strong&gt; important business logic in a simple environment and you want to see exactly what the &lt;strong&gt;pyjokes&lt;/strong&gt; package is doing when you call &lt;em&gt;get_joke()&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;business_logic.py&lt;/strong&gt;:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;pyjokes&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;get_joke&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;get_joke&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The package's &lt;a href="https://github.com/pyjokes/pyjokes"&gt;Git repository&lt;/a&gt; is often a great place to start, but sometimes you want to be able to step through the package. &lt;br&gt;
Here's what you can do:&lt;/p&gt;

&lt;ol&gt;
   &lt;li&gt;
      Activate your virtual environment (if you haven't already)
   &lt;/li&gt;
   &lt;li&gt;
      Uninstall the package &lt;code&gt;pip uninstall pyjokes&lt;/code&gt;
   &lt;/li&gt;
   &lt;li&gt;
      Reinstall the package from source with the editable flag
      
         &lt;pre class="highlight bash"&gt;
pip install --editable git+git@github.com:pyjokes/pyjokes.git#egg=pyjokes
&lt;/pre&gt;
      
      &lt;ul&gt;
         &lt;li&gt;
            &lt;code&gt;--editable&lt;/code&gt; can be shortened to &lt;code&gt;-e&lt;/code&gt;
         &lt;/li&gt;
         &lt;li&gt;
            You aren't limited to Git repositories! You can also use "svn+" and "bzr+" and a few others. See Pip's &lt;a href="https://pip.pypa.io/en/stable/reference/pip_install/#vcs-support"&gt;VCS support documentation&lt;/a&gt;
         &lt;/li&gt;
         &lt;li&gt;
            &lt;code&gt;#egg=[Custom Name]&lt;/code&gt; creates a directory [Custom Name].egg.info relative to the project path. You probably won't care about this, but it's required.
         &lt;/li&gt;
      &lt;/ul&gt;
   &lt;/li&gt;
   &lt;li&gt;
      The pyjokes repository can now be found in &lt;code&gt;[virtual environment folder name] &amp;gt; src &amp;gt; pyjokes&lt;/code&gt;. But this isn't exactly what we're interested in.
   &lt;/li&gt;
   &lt;li&gt;
      Find where the source code actually exists in the repository, in this case it's a subfolder with the same name. Sometimes it's a subfolder called "src". &lt;code&gt;[virtual environment folder name] &amp;gt; src &amp;gt; pyjokes &amp;gt; pyjokes&lt;/code&gt;
   &lt;/li&gt;
   &lt;li&gt;
      Move this folder up to the root level of your project. For example, this project directory now contains the following files and directories:
&lt;ul&gt;
&lt;li&gt;pyjokes (folder)&lt;/li&gt;
&lt;li&gt;venv (virtual environment folder)&lt;/li&gt;
&lt;li&gt;business_logic.py&lt;/li&gt;
   &lt;/ul&gt;
&lt;/li&gt;

&lt;li&gt;Almost done! Set the breakpoints you want in the pyjokes source code, open business_logic.py, switch to the VSCode debugger and press the green run button. Two prompts will appear, select Python for the first and "current file" for the second!
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As an added bonus, you can edit the package too--good luck debugging!&lt;/p&gt;

</description>
      <category>python</category>
      <category>pip</category>
      <category>vscode</category>
      <category>debug</category>
    </item>
  </channel>
</rss>
