Skip to content

Instantly share code, notes, and snippets.

@MasterKale
Last active December 12, 2017 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterKale/dcb5b14cdf92b5293c226c4958d1b2e7 to your computer and use it in GitHub Desktop.
Save MasterKale/dcb5b14cdf92b5293c226c4958d1b2e7 to your computer and use it in GitHub Desktop.
pkg_resources
"""
For some reason vendored third-party libraries don't have access to `pkg_resources`. Unfortunately,
this means these libraries will cause errors like this when they try to load:
ERROR 2017-12-12 06:13:05,691 wsgi.py:263]
Traceback (most recent call last):
File "/Users/mmiller/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
# ...snip...
File "/Users/mmiller/Repos/some_django_proj/lib/django_hosts/__init__.py", line 2, in <module>
import pkg_resources
ImportError: No module named pkg_resources
To combat this, we're stubbing out a few of its methods so that we don't need to maintain modified
copies of these third-party libraries
"""
def parse_version_stub(version):
"""
Simply pass through the version given
"""
return version
class DistStub(object):
version = '0.00'
DIST_STUB = DistStub()
def get_distribution_stub(dist_name):
"""
Return a basic class with a version property
"""
return DIST_STUB
# Stub out parse_version if it's not available
try:
from pkg_resources import parse_version as pv
parse_version = pv
except ImportError:
parse_version = parse_version_stub
# Stub out get_distribution if it's not available
try:
from pkg_resources import get_distribution as gd
get_distribution = gd
except ImportError:
get_distribution = get_distribution_stub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment