| 1 | """ |
| 2 | This script is a WSGI configuration/setup file suitable for use in |
| 3 | deploying the Flasgger demo_app to PythonAnywhere, https://www.pythonanywhere.com/ . |
| 4 | |
| 5 | To deploy: |
| 6 | |
| 7 | - Create a PythonAnywhere account if you don't already have one. Replace <username> |
| 8 | below with your PythonAnywhere username. |
| 9 | - Visit https://www.pythonanywhere.com/user/<username>/webapps and create a new/default |
| 10 | web app, using Manual Configuration and Python 3.6. |
| 11 | - Confirm you can access the Hello, World! page at https://<username>.pythonanywhere.com/ . |
| 12 | - Visit https://www.pythonanywhere.com/user/<username>/consoles/ and create a new bash console. |
| 13 | - From your home directory /home/<username>, run: |
| 14 | git clone https://github.com/rochacbruno/flasgger.git |
| 15 | ... or use another fork. |
| 16 | - cd ~/flasgger, then change to whichever branch you want to use. |
| 17 | - Create a new virtual environment: |
| 18 | mkvirtualenv --python=python3.6 |
| 19 | - Run: pip3 install -r requirements.txt -r requirements-dev.txt |
| 20 | - cd /var/www |
| 21 | - rm ${USERNAME}_pythonanywhere_com_wsgi.py |
| 22 | - ln -s ~/flasgger/etc/pythonanywhere/pythonanywhere_com_wsgi.py ${USERNAME}_pythonanywhere_com_wsgi.py |
| 23 | - Go to the web app console at https://www.pythonanywhere.com/user/<username>/webapps . |
| 24 | - Modify the configuration: |
| 25 | - Make the source path /home/<username>/flasgger |
| 26 | - Make the working directory /home/<username>/flasgger |
| 27 | - Change the virtual env path to /home/<username>/.virtualenvs/flasgger |
| 28 | - Reload the web app. |
| 29 | - Visit https://<username>.pythonanywhere.com/ and you should see the demo_app landing page. |
| 30 | - If an error occurs, review the log files. |
| 31 | """ |
| 32 | import os |
| 33 | import subprocess |
| 34 | import sys |
| 35 | |
| 36 | home = os.path.expanduser("~") |
| 37 | path = os.environ.get('FLASGGER_HOME') or home + '/flasgger' |
| 38 | |
| 39 | subprocess.check_call(['git', 'pull', path]) |
| 40 | |
| 41 | if path not in sys.path: |
| 42 | sys.path.append(path) |
| 43 | |
| 44 | from demo_app.app import application |