My Python application can be install the normal way, or in development/editable mode with pip, like this:
virtualenv my_app
source my_app/bin/activate
pip install -e my_app
How can I make a function to introspect my virtualenv and check if my application runs in development/editable mode?
Is there any "flag" in sys module for that?
Motivation: have different configuration in development mode, and in production.
EDIT: I compare the virtualenv and the package directories.
import os
import sys
import pkg_resources
main_pkg = 'my_app'
package_dir = pkg_resources.resource_filename(main_pkg, '__init__.py')
virtualenv_dir = os.path.dirname(os.path.dirname(sys.executable))
common_path = os.path.commonprefix([package_dir, virtualenv_dir])
is_dev_mode = not common_path.startswith(virtualenv_dir)
I test if the package_dir is a subdirectory of the virtualenv_dir: if it is not a subdirectory, then I am on development mode.
EDIT2:
Is there a more reliable solution?
I want to know if there isn’t a data/a flag in the environment that would clearly indicate to me that my application is running in development mode.
What will happen if another dependency is in development mode too?