Convert to using ExitStack instead of nested. (#21329)

* Convert to using ExitStack instead of nested.

nested is not available in Python3.

* Use ExitStack from contextlib2.

ExitStack has not been backported to the Python 2.7 standard library and
contextlib.nested is no longer available in Python 3.5.  We need to be
able to use something in both 2 and 3 as we transition so we'll pull in
contextlib2 which has backports of the full python3 contextlib.
This commit is contained in:
Feanil Patel
2019-08-12 16:55:05 -04:00
committed by GitHub
parent 1739e4b6b4
commit 9753eae441
5 changed files with 16 additions and 12 deletions

View File

@@ -5,7 +5,8 @@ from __future__ import absolute_import
import io
import os
from contextlib import contextmanager, nested
from contextlib import contextmanager
from contextlib2 import ExitStack
from importlib import import_module
from shutil import rmtree
from tempfile import mkdtemp
@@ -255,7 +256,7 @@ class StoreBuilderBase(object):
@contextmanager
def build(self, **kwargs):
"""
Build the modulstore, optionally building the contentstore as well.
Build the modulestore, optionally building the contentstore as well.
"""
contentstore = kwargs.pop('contentstore', None)
if not contentstore:
@@ -419,7 +420,8 @@ class MixedModulestoreBuilder(StoreBuilderBase):
"""
names, generators = list(zip(*self.store_builders))
with nested(*(gen.build_with_contentstore(contentstore, **kwargs) for gen in generators)) as modulestores:
with ExitStack() as stack:
modulestores = [stack.enter_context(gen.build_with_contentstore(contentstore, **kwargs)) for gen in generators]
# Make the modulestore creation function just return the already-created modulestores
store_iterator = iter(modulestores)
next_modulestore = lambda *args, **kwargs: next(store_iterator)

View File

@@ -34,6 +34,7 @@ boto==2.39.0 # Deprecated version of the AWS SDK; we shou
boto3==1.4.8 # Amazon Web Services SDK for Python
botocore==1.8.17 # via boto3, s3transfer
celery==3.1.25 # Asynchronous task execution library
contextlib2 # We need contextlib2.ExitStack so we can stop using contextlib.nested which doesn't exist in python 3
defusedxml
Django<1.12 # Web application framework
django-babel-underscore # underscore template extractor for django-babel (internationalization utilities)

View File

@@ -44,6 +44,7 @@ chardet==3.0.4
git+https://github.com/edx/openedx-chem.git@ff4e3a03d3c7610e47a9af08eb648d8aabe2eb18#egg=chem==1.0.0
click==7.0 # via code-annotations, user-util
code-annotations==0.3.2 # via edx-enterprise
contextlib2==0.5.5
coreapi==2.3.3 # via drf-yasg
coreschema==0.0.4 # via coreapi, drf-yasg
git+https://github.com/edx/crowdsourcehinter.git@a7ffc85b134b7d8909bf1fefd23dbdb8eb28e467#egg=crowdsourcehinter-xblock==0.2
@@ -162,7 +163,7 @@ mock==1.0.1
git+https://github.com/edx/MongoDBProxy.git@d92bafe9888d2940f647a7b2b2383b29c752f35a#egg=MongoDBProxy==0.1.0+edx.2
mongoengine==0.10.0
mpmath==1.1.0 # via sympy
mysqlclient==1.4.3
mysqlclient==1.4.4
networkx==1.7
newrelic==4.20.1.121
nltk==3.4.4
@@ -215,7 +216,7 @@ rfc6266-parser==0.0.5.post2
ruamel.ordereddict==0.4.14 ; python_version == "2.7" # via ruamel.yaml
ruamel.yaml.clib==0.1.2 # via ruamel.yaml
ruamel.yaml==0.16.1 # via drf-yasg
rules==2.0.1
rules==2.1
s3transfer==0.1.13 # via boto3
sailthru-client==2.2.3
scipy==1.2.1

View File

@@ -59,7 +59,7 @@ click-log==0.3.2
click==7.0
code-annotations==0.3.2
colorama==0.4.1
configparser==3.7.4
configparser==3.8.1
contextlib2==0.5.5
cookies==2.2.1
coreapi==2.3.3
@@ -213,7 +213,7 @@ mongoengine==0.10.0
more-itertools==5.0.0
moto==1.3.1
mpmath==1.1.0
mysqlclient==1.4.3
mysqlclient==1.4.4
networkx==1.7
newrelic==4.20.1.121
nltk==3.4.4
@@ -290,7 +290,7 @@ rfc6266-parser==0.0.5.post2
ruamel.ordereddict==0.4.14 ; python_version == "2.7"
ruamel.yaml.clib==0.1.2
ruamel.yaml==0.16.1
rules==2.0.1
rules==2.1
s3transfer==0.1.13
sailthru-client==2.2.3
scandir==1.10.0

View File

@@ -57,8 +57,8 @@ click-log==0.3.2 # via edx-lint
click==7.0
code-annotations==0.3.2
colorama==0.4.1 # via radon
configparser==3.7.4 # via entrypoints, flake8, importlib-metadata, pylint
contextlib2==0.5.5 # via importlib-metadata
configparser==3.8.1 # via entrypoints, flake8, importlib-metadata, pylint
contextlib2==0.5.5
cookies==2.2.1 # via moto
coreapi==2.3.3
coreschema==0.0.4
@@ -206,7 +206,7 @@ mongoengine==0.10.0
more-itertools==5.0.0 # via pytest
moto==1.3.1
mpmath==1.1.0
mysqlclient==1.4.3
mysqlclient==1.4.4
networkx==1.7
newrelic==4.20.1.121
nltk==3.4.4
@@ -281,7 +281,7 @@ rfc6266-parser==0.0.5.post2
ruamel.ordereddict==0.4.14 ; python_version == "2.7"
ruamel.yaml.clib==0.1.2
ruamel.yaml==0.16.1
rules==2.0.1
rules==2.1
s3transfer==0.1.13
sailthru-client==2.2.3
scandir==1.10.0 # via pathlib2