Why would a pip installed package's __init__.py NOT have the canonical if __name__ == "__main__":?
<p>I am playing around with <a href="http://github.com/getpelican/pelican" rel="nofollow">pelican</a>, the static blog generator, which I have</p>

<ul>
<li><p>cloned from github</p>

<p>$ git clone <a href="https://github.com/getpelican/pelican.git" rel="nofollow">https://github.com/getpelican/pelican.git</a></p></li>
<li><p>installed into my virtualenv as an editable package</p>

<p>$ pip install -r dev_requirements.txt<br>
 $ pip install -e .</p></li>
</ul>

<p>Now I would like to run it, and debug it, using pycharm (and later in emacs)</p>

<p>I can't quite figure out how to do that!</p>

<p>I can run pelican from the command line.</p>

<pre><code>$ pelican /blog/content -o /blog/public -s /blog/pelicanconf.py --relative_urls
</code></pre>

<p>But I cannot figure out how to run it from pycharm....</p>

<p>That is, I can set a breakpoint at <code>__init__.py:main()</code> but when pycharm runs <code>__init__.py</code> nothing happens.
Presumably pycharm runs <code>__init__</code> and it loads the various modules and then exits.</p>

<p>Until I add the canonical invocation trope:</p>

<pre><code>if __name__ == "__main__":
    main()
</code></pre>

<p>at the bottom of <code>__init__.py</code></p>

<p>And then I can tell pycharm to run the <code>__init__.py</code> script and python enters the debugger at main() as I want.</p>

<hr>

<p>(edited)
So my questions are</p>

<ol>
<li>Why would a python package NOT have that trope at the end of its <code>__init__.py</code>?</li>
<li>How do I configure pycharm so that I can run and debug pelican (or similar python packages) from within it?</li>
</ol>

<p>The <a href="https://github.com/getpelican/pelican/blob/master/setup.py" rel="nofollow"><code>pelican/setup.py</code></a> defines several entrypoints:</p>

<pre><code>entry_points = {
    'console_scripts': [
        'pelican = pelican:main',
        'pelican-import = pelican.tools.pelican_import:main',
        'pelican-quickstart = pelican.tools.pelican_quickstart:main',
        'pelican-themes = pelican.tools.pelican_themes:main'
    ]
}
</code></pre>

<p>I guess the first one tells that the function <code>pelican.main()</code> is called when you execute the <code>pelican</code> command.</p>

<p>So if you want to run pelican from PyCharm, you probably just have to run the <code>main()</code> function of the <code>pelican/__init__.py</code></p>

<p>You can do that by:</p>

<ul>
<li>creating a simple script which just import and invoke the <code>pelican.main()</code> function</li>
<li>run this script (in debug mode for debugging)</li>
</ul>

python python-2.7 pycharm