Last active
December 12, 2017 17:35
-
-
Save MasterKale/dcb5b14cdf92b5293c226c4958d1b2e7 to your computer and use it in GitHub Desktop.
pkg_resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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