diff --git a/.gitignore b/.gitignore index 72364f99f..441a11ffd 100644 --- a/.gitignore +++ b/.gitignore @@ -81,9 +81,14 @@ celerybeat-schedule # virtualenv venv/ ENV/ +.venv/ # Spyder project settings .spyderproject # Rope project settings .ropeproject + +# Visual Studio Code +.vscode/ + diff --git a/README.md b/README.md index df934860e..8a2e9e91e 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,19 @@ -# Python Flask app on Azure App Service Web +--- +page_type: sample +description: "A minimal sample app that can be used to demonstrate deploying Flask apps to Azure App Service on Linux." +languages: +- python +products: +- azure +- azure-app-service +--- -This is a minimal sample app that demonstrates how to run a Python Flask application on Azure App Service Web. +# Python Flask sample for Azure App Service (Linux) -This repository can directly be deployed to Azure App Service. +This is a minimal Flask app that can be deployed to Azure App Service on Linux. -For more information, please see the [Python on App Service Quickstart docs](https://docs.microsoft.com/en-us/azure/app-service-web/app-service-web-get-started-python). +For instructions on running and deploying the code, see [Quickstart: Create a Python app in Azure App Service on Linux](https://docs.microsoft.com/azure/app-service/quickstart-python). -# Contributing +## Contributing This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. diff --git a/app.py b/app.py new file mode 100644 index 000000000..7f8a1f2e8 --- /dev/null +++ b/app.py @@ -0,0 +1,6 @@ +from flask import Flask +app = Flask(__name__) + +@app.route("/") +def hello(): + return "Hello, World!" diff --git a/main.py b/main.py deleted file mode 100644 index a1897c800..000000000 --- a/main.py +++ /dev/null @@ -1,9 +0,0 @@ -from flask import Flask -app = Flask(__name__) - -@app.route('/') -def hello_world(): - return 'Hello, World!' - -if __name__ == '__main__': - app.run() diff --git a/ptvs_virtualenv_proxy.py b/ptvs_virtualenv_proxy.py deleted file mode 100644 index a4a412980..000000000 --- a/ptvs_virtualenv_proxy.py +++ /dev/null @@ -1,122 +0,0 @@ -# ############################################################################ - # - # Copyright (c) Microsoft Corporation. - # - # This source code is subject to terms and conditions of the Apache License, Version 2.0. A - # copy of the license can be found in the License.html file at the root of this distribution. If - # you cannot locate the Apache License, Version 2.0, please send an email to - # vspython@microsoft.com. By using this source code in any fashion, you are agreeing to be bound - # by the terms of the Apache License, Version 2.0. - # - # You must not remove this notice, or any other, from this software. - # - # ########################################################################### - -import datetime -import os -import sys -import traceback - -if sys.version_info[0] == 3: - def to_str(value): - return value.decode(sys.getfilesystemencoding()) - - def execfile(path, global_dict): - """Execute a file""" - with open(path, 'r') as f: - code = f.read() - code = code.replace('\r\n', '\n') + '\n' - exec(code, global_dict) -else: - def to_str(value): - return value.encode(sys.getfilesystemencoding()) - -def log(txt): - """Logs fatal errors to a log file if WSGI_LOG env var is defined""" - log_file = os.environ.get('WSGI_LOG') - if log_file: - f = open(log_file, 'a+') - try: - f.write('%s: %s' % (datetime.datetime.now(), txt)) - finally: - f.close() - -ptvsd_secret = os.getenv('WSGI_PTVSD_SECRET') -if ptvsd_secret: - log('Enabling ptvsd ...\n') - try: - import ptvsd - try: - ptvsd.enable_attach(ptvsd_secret) - log('ptvsd enabled.\n') - except: - log('ptvsd.enable_attach failed\n') - except ImportError: - log('error importing ptvsd.\n') - -def get_wsgi_handler(handler_name): - if not handler_name: - raise Exception('WSGI_ALT_VIRTUALENV_HANDLER env var must be set') - - if not isinstance(handler_name, str): - handler_name = to_str(handler_name) - - module_name, _, callable_name = handler_name.rpartition('.') - should_call = callable_name.endswith('()') - callable_name = callable_name[:-2] if should_call else callable_name - name_list = [(callable_name, should_call)] - handler = None - last_tb = '' - - while module_name: - try: - handler = __import__(module_name, fromlist=[name_list[0][0]]) - last_tb = '' - for name, should_call in name_list: - handler = getattr(handler, name) - if should_call: - handler = handler() - break - except ImportError: - module_name, _, callable_name = module_name.rpartition('.') - should_call = callable_name.endswith('()') - callable_name = callable_name[:-2] if should_call else callable_name - name_list.insert(0, (callable_name, should_call)) - handler = None - last_tb = ': ' + traceback.format_exc() - - if handler is None: - raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb)) - - return handler - -activate_this = os.getenv('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS') -if not activate_this: - raise Exception('WSGI_ALT_VIRTUALENV_ACTIVATE_THIS is not set') - -def get_virtualenv_handler(): - log('Activating virtualenv with %s\n' % activate_this) - execfile(activate_this, dict(__file__=activate_this)) - - log('Getting handler %s\n' % os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) - handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) - log('Got handler: %r\n' % handler) - return handler - -def get_venv_handler(): - log('Activating venv with executable at %s\n' % activate_this) - import site - sys.executable = activate_this - old_sys_path, sys.path = sys.path, [] - - site.main() - - sys.path.insert(0, '') - for item in old_sys_path: - if item not in sys.path: - sys.path.append(item) - - log('Getting handler %s\n' % os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) - handler = get_wsgi_handler(os.getenv('WSGI_ALT_VIRTUALENV_HANDLER')) - log('Got handler: %r\n' % handler) - return handler \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6aef94caf..e3e9a71d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -Flask==0.12.1 +Flask diff --git a/web.2.7.config b/web.2.7.config deleted file mode 100644 index 909a6f6e4..000000000 --- a/web.2.7.config +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/web.3.4.config b/web.3.4.config deleted file mode 100644 index 1552b7fd1..000000000 --- a/web.3.4.config +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -