def _ChooseEntrypoint(default_entrypoint, appinfo): """Prompt the user for an entrypoint. Args: default_entrypoint: (str) Default entrypoint determined from the app. appinfo: (apphosting.api.appinfo.AppInfoExternal or None) The parsed app.yaml file for the module if it exists. Returns: (str) The actual entrypoint to use. Raises: RubyConfigError: Unable to get entrypoint from the user. """ if console_io.CanPrompt(): if default_entrypoint: prompt = ( '\nPlease enter the command to run this Ruby app in ' 'production, or leave blank to accept the default:\n[{0}] ') entrypoint = console_io.PromptResponse( prompt.format(default_entrypoint)) else: entrypoint = console_io.PromptResponse( '\nPlease enter the command to run this Ruby app in production: ' ) entrypoint = entrypoint.strip() if not entrypoint: if not default_entrypoint: raise RubyConfigError('Entrypoint command is required.') entrypoint = default_entrypoint if appinfo: # We've got an entrypoint and the user had an app.yaml that didn't # specify it. # TODO(mmuller): Offer to edit the user's app.yaml msg = ( '\nTo avoid being asked for an entrypoint in the future, please ' 'add it to your app.yaml. e.g.\n entrypoint: {0}'.format( entrypoint)) log.status.Print(msg) return entrypoint else: msg = ( "This appears to be a Ruby app. You'll need to provide the full " 'command to run the app in production, but gcloud is not running ' 'interactively and cannot ask for the entrypoint{0}. Please either ' 'run gcloud interactively, or create an app.yaml with ' '"runtime:ruby" and an "entrypoint" field.'.format( ext_runtime_adapter.GetNonInteractiveErrorMessage())) raise RubyConfigError(msg)
def Fingerprint(path, params): """Check for a Python app. Args: path: (str) Application path. params: (ext_runtime.Params) Parameters passed through to the fingerprinters. Returns: (PythonConfigurator or None) Returns a module if the path contains a python app. """ entrypoint = None appinfo = params.appinfo if appinfo and appinfo.entrypoint: entrypoint = appinfo.entrypoint log.info('Checking for Python.') requirements_txt = os.path.join(path, 'requirements.txt') got_requirements_txt = os.path.isfile(requirements_txt) got_py_files = False # check for any python files. for _, _, files in os.walk(path): for filename in files: if filename.endswith('.py'): got_py_files = True if not got_requirements_txt and not got_py_files: return None # Query the user for the WSGI entrypoint: if not entrypoint: if console_io.CanPrompt(): entrypoint = console_io.PromptResponse( 'This looks like a Python app. If so, please enter the command to ' "run to run the app in production (enter nothing if it's not a " 'python app): ').strip() if not entrypoint: log.info( 'No entrypoint specified. Assuming this is not a python app.' ) elif appinfo: # We've got an entrypoint and the user had an app.yaml that didn't # specify it. # TODO(user): offer to edit the user's app.yaml. log.status.Print( 'To avoid being asked for an entrypoint in the ' 'future, please add the entrypoint to your app.yaml:\n' ' entrypoint: %s' % entrypoint) else: log.warn( "This appears to be a python app. You'll need to provide the " 'command to run the app in production. Please either run this ' 'interactively%s or create an app.yaml with "runtime: python" ' 'and an "entrypoint" field defining the full command.' % ext_runtime_adapter.GetNonInteractiveErrorMessage()) return None try: # Get the python interpreter version. Use the default if not specified. python_version = PythonVersionFromRuntimeConfig( appinfo.runtime_config if appinfo else None) except ValueError: # The python version was selected, but set to an invalid result. log.error( 'The python_version selected in runtime_config is invalid or not ' 'supported. Please select from the following options:\n' '%s', str(VALID_PYTHON_INTERPRETER_VERSIONS)) return None return PythonConfigurator(path, params, got_requirements_txt, entrypoint, use_python_3=python_version == '3')