Determine program was installed using "setup.py develop"
<p>I am developing a Gtk application and would like to use a system-wide, installed version and run a different development version at the same time.</p>

<p>The application cannot be started twice because <code>Gtk.Application</code> will try to connect to same DBus bus and refuse to be started twice. Therefore my idea is to determine whether I am in "development mode", i. e. the program has been installed using <code>./setup.py develop</code>, or not. </p>

<p>How can I achieve this? Or is there another, more general way to differ between development and installed versions of the program? I would prefer to avoid a special <code>--develop</code> option or the like which would be useless outside of development scope.</p>

<p>Due to how <code>setuptools</code> is designed the development mode is simply a transparent <code>.egg-link</code> object away, so internally it is effectively impossible to determine whether or not the package is loaded as an <code>egg-link</code> (i.e. development mode; relevant <a href="https://github.com/pypa/setuptools/blob/v27.2.0/pkg_resources/__init__.py#L1996" rel="nofollow">code here</a> and see how it just recursively invoke <code>find_distributions</code> which would in turn call this method again (through the internal import finder framework) before <a href="https://github.com/pypa/setuptools/blob/v27.2.0/pkg_resources/__init__.py#L1982" rel="nofollow">generating the metadata object</a>).</p>

<p>So what you can do instead is to create a distinct DBus bus per version of your application.  Typically for development your version number is different, and it is possible to pick up the version number through <a href="https://setuptools.readthedocs.io/en/latest/pkg_resources.html" rel="nofollow"><code>pkg_resources</code> API</a>.</p>

<pre><code>&gt;&gt;&gt; pkg_resources.get_distribution('setuptools').version
'18.2'
</code></pre>

<p>You can also use it to generate custom metadata which is written to your package's egg-info, and through that it is possible for your package to declare custom items that could say customize the bus name of the Dbus bus to be used, but this will take a bit more work to set up.  At the very least, you can declare a <code>setup.cfg</code> that tag a build</p>

<pre><code>[egg_info]
tag_build = dev
</code></pre>

<p>Rerun <code>setup.py develop</code> again and the version number will include a <code>dev</code> suffix which will show up in the version string returned by <code>pkg_resources.get_distribution</code> on your package's name.  This is not quite what you are looking for, but it might allow multiple versions of your application to be executed at the same time regardless of where they are installed or how they are installed.  Consider users that might use virtualenvs to have multiple local installations of your applications and want to run them at the same time, and in that case you might want to base it on the hash of the install location instead:</p>

<pre><code>&gt;&gt;&gt; pkg_resources.get_distribution('setuptools').location
'/tmp/.env3/lib/python3.5/site-packages'
</code></pre>

<p>Of course, if the package is found within <code>site-packages</code> it is probably done as a proper <code>install</code>, but there is nothing in the API that will tell you this.</p>

python setuptools gtk3