Commit 3ca1cc68 by Steven Bird

Merge pull request #933 from sadovnychyi/develop

Add support for Google App Engine
parents 35cbe3f5 48dbd02e
...@@ -94,6 +94,17 @@ try: ...@@ -94,6 +94,17 @@ try:
except ImportError: except ImportError:
pass pass
# Override missing methods on environments where it cannot be used like GAE.
import subprocess
if not hasattr(subprocess, 'PIPE'):
def _fake_PIPE(*args, **kwargs):
raise NotImplementedError('subprocess.PIPE is not supported.')
subprocess.PIPE = _fake_PIPE
if not hasattr(subprocess, 'Popen'):
def _fake_Popen(*args, **kwargs):
raise NotImplementedError('subprocess.Popen is not supported.')
subprocess.Popen = _fake_Popen
########################################################### ###########################################################
# TOP-LEVEL MODULES # TOP-LEVEL MODULES
########################################################### ###########################################################
......
...@@ -73,7 +73,7 @@ path = [] ...@@ -73,7 +73,7 @@ path = []
# User-specified locations: # User-specified locations:
path += [d for d in os.environ.get('NLTK_DATA', str('')).split(os.pathsep) if d] path += [d for d in os.environ.get('NLTK_DATA', str('')).split(os.pathsep) if d]
if os.path.expanduser('~/') != '~/': if 'APPENGINE_RUNTIME' not in os.environ and os.path.expanduser('~/') != '~/':
path.append(os.path.expanduser(str('~/nltk_data'))) path.append(os.path.expanduser(str('~/nltk_data')))
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
......
...@@ -924,6 +924,10 @@ class Downloader(object): ...@@ -924,6 +924,10 @@ class Downloader(object):
permission: ``/usr/share/nltk_data``, ``/usr/local/share/nltk_data``, permission: ``/usr/share/nltk_data``, ``/usr/local/share/nltk_data``,
``/usr/lib/nltk_data``, ``/usr/local/lib/nltk_data``, ``~/nltk_data``. ``/usr/lib/nltk_data``, ``/usr/local/lib/nltk_data``, ``~/nltk_data``.
""" """
# Check if we are on GAE where we cannot write into filesystem.
if 'APPENGINE_RUNTIME' in os.environ:
return
# Check if we have sufficient permissions to install in a # Check if we have sufficient permissions to install in a
# variety of system-wide locations. # variety of system-wide locations.
for nltkdir in nltk.data.path: for nltkdir in nltk.data.path:
...@@ -2267,4 +2271,3 @@ if __name__ == '__main__': ...@@ -2267,4 +2271,3 @@ if __name__ == '__main__':
downloader.download(download_dir=options.dir, downloader.download(download_dir=options.dir,
quiet=options.quiet, force=options.force, quiet=options.quiet, force=options.force,
halt_on_error=options.halt_on_error) halt_on_error=options.halt_on_error)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment