Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deprecation of namespace_manager API #32

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions gaek/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@


import os
import warnings

from google.appengine.api import app_identity
from google.appengine.api import modules
from google.appengine.api import namespace_manager

try:
from google.appengine.api import namespace_manager
except ImportError:
namespace_manager = None


__all__ = (
Expand Down Expand Up @@ -85,8 +90,16 @@


# Namespace functions.
get_namespace = namespace_manager.get_namespace
google_apps_namespace = namespace_manager.google_apps_namespace
if namespace_manager == None:
get_namespace = deprecated_fn
google_apps_namespace = deprecated_fn
else:
get_namespace = namespace_manager.get_namespace
google_apps_namespace = namespace_manager.google_apps_namespace


def deprecated_fn():
warnings.warn('deprecated', DeprecationWarning)


# Helper functions.
Expand Down Expand Up @@ -191,11 +204,23 @@ def _get_modules_dict(keys):
return {k: getattr(modules, k)() for k in keys}


def _get_namespace_manager_dict(keys):
def _get_namespace_manager_dict_v2(keys):
"""Returns an empty dictionary since the namespace_manager API has been deprecated."""
return {}


def _get_namespace_manager_dict_v1(keys):
"""Return a dictionary of key/values from the namespace_manager module functions."""
return {k: getattr(namespace_manager, k)() for k in keys}


# Swap the function that's called if the namespace_manager is disabled.
if namespace_manager == None:
_get_namespace_manager_dict = _get_namespace_manager_dict_v2
else:
_get_namespace_manager_dict = _get_namespace_manager_dict_v1


def get_environ_dict():
"""Return a dictionary of all environment keys/values."""
return {
Expand Down
18 changes: 11 additions & 7 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

GAE_SDK_SHA1='abe54d95c4ce6ffc35452e027ca701f5d21dd56a'
GAE_SDK_FILE='google_appengine_1.9.35.zip'
GAE_SDK_SHA1='35c6857852f787ab777824ceaf645964cff696bc'
GAE_SDK_FILE='google_appengine_1.9.88.zip'

# Create virtual environment.
echo 'Creating virtual environment...'
Expand All @@ -22,10 +22,14 @@ unzip -q $GAE_SDK_FILE -d .dev_env/
rm $GAE_SDK_FILE

# Travis CI uses a different path.
cd .dev_env/site-packages/
ln -s ../google_appengine/google google
if [ -d ".dev_env/site-packages/" ]; then
cd .dev_env/site-packages/
ln -s ../google_appengine/google google
fi

# OSX path.
cd .dev_env/lib/python2.7/site-packages/
ln -s ../../../google_appengine/google google
cd ../../../../
if [ -d ".dev_env/lib/python2.7/site-packages/" ]; then
cd .dev_env/lib/python2.7/site-packages/
ln -s ../../../google_appengine/google google
cd ../../../../
fi