<commit_before># None of this is django-specific. Don't import from django.

import os
import sys
import contextlib
import subprocess
import getpass

import djangae.utils as utils


_SCRIPT_NAME = 'dev_appserver.py'


def _find_sdk_from_python_path():
    import google.appengine
    return os.path.abspath(os.path.dirname(google.__path__[0]))


def _find_sdk_from_path():
    # Assumes `script_name` is on your PATH - SDK installers set this up
    which = 'where' if sys.platform == "win32" else 'which'
    path = subprocess.check_output([which, _SCRIPT_NAME])
    return os.path.dirname(os.path.realpath(path))


@contextlib.contextmanager
def _local(devappserver2=None, configuration=None, options=None, wsgi_request_info=None, **kwargs):
    original_environ = os.environ.copy()

    devappserver2._setup_environ(configuration.app_id)
    storage_path = devappserver2._get_storage_path(options.storage_path, configuration.app_id)
    dispatcher = None
    request_data = wsgi_request_info.WSGIRequestInfo(dispatcher)

    apis = devappserver2.DevelopmentServer._create_api_server(
        request_data, storage_path, options, configuration)
    apis.start()

    try:
        yield
    finally:
        apis.quit()
        os.environ = original_environ<commit_msg>Fixes 19 - correctly find the SDK dir when app engine installed as part of the Google Cloud SDK.<commit_after># None of this is django-specific. Don't import from django.

import os
import sys
import contextlib
import subprocess
import getpass

import djangae.utils as utils


_SCRIPT_NAME = 'dev_appserver.py'


def _find_sdk_from_python_path():
    import google.appengine
    return os.path.abspath(os.path.dirname(google.__path__[0]))


def _find_sdk_from_path():
    # Assumes `script_name` is on your PATH - SDK installers set this up
    which = 'where' if sys.platform == "win32" else 'which'
    path = subprocess.check_output([which, _SCRIPT_NAME])
    sdk_dir = os.path.dirname(os.path.realpath(path))

    if os.path.exists(os.path.join(sdk_dir, 'bootstrapping')):
        # Cloud SDK
        sdk_dir = os.path.abspath(os.path.join(sdk_dir, '..', 'platform', 'google_appengine'))
        if not os.path.exists(sdk_dir):
            raise RuntimeError(
                'The Cloud SDK is on the path, but the app engine SDK dir could not be found'
            )
        else:
            return sdk_dir
    else:
        # Regular App Engine SDK
        return sdk_dir


@contextlib.contextmanager
def _local(devappserver2=None, configuration=None, options=None, wsgi_request_info=None, **kwargs):
    original_environ = os.environ.copy()

    devappserver2._setup_environ(configuration.app_id)
    storage_path = devappserver2._get_storage_path(options.storage_path, configuration.app_id)
    dispatcher = None
    request_data = wsgi_request_info.WSGIRequestInfo(dispatcher)

    apis = devappserver2.DevelopmentServer._create_api_server(
        request_data, storage_path, options, configuration)
    apis.start()

    try:
        yield
    finally:
        apis.quit()
        os.environ = original_environ
{'fraction_non_alphanumeric': 0.08958602846054334, 'fraction_numerical': 0.00517464424320828, 'mean_word_length': 3.693474962063733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6842420', 'n_tokens_mistral': 1005, 'n_tokens_neox': 962, 'n_words': 231}