Skip to content

Instantly share code, notes, and snippets.

@Visgean
Created December 22, 2015 15:13
Show Gist options
  • Save Visgean/cbd2102bb0b40bd9b90a to your computer and use it in GitHub Desktop.
Save Visgean/cbd2102bb0b40bd9b90a to your computer and use it in GitHub Desktop.
import os
from distutils.sysconfig import get_python_lib
from distutils.dir_util import copy_tree
def resolve_pip_data_files(fix_packages=None):
"""
See http://stackoverflow.com/questions/20298729/pip-installing-data-files-to-the-wrong-place/20370738#20370738 # noqa
and http://stackoverflow.com/questions/30980682/djangos-locale-files-installed-in-weird-place # noqa
data files need to be merged into proper folders, otherwise you will
receive weird messages as mentioned in https://code.djangoproject.com/ticket/18192
see claudep: I don't think we should do anything here. If Django files
are deleted, the user has to bear the consequences, sorry!
:param fix_packages: list of packages to fix, defaults to Django
"""
if fix_packages is None:
fix_packages = ['django', 'django_extensions']
env_path = os.environ.get('VIRTUAL_ENV', None)
site_packages = get_python_lib()
if not env_path:
return # not in virtual env
for package in fix_packages:
package_data_dir = os.path.join(env_path, package)
package_dir = os.path.join(site_packages, package)
if os.path.exists(package_data_dir) and os.path.exists(package_dir):
copy_tree(package_data_dir, package_dir)
if __name__ == '__main__':
resolve_pip_data_files()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment