Skip to content

Instantly share code, notes, and snippets.

@alokm
Created July 29, 2019 02:16
Show Gist options
  • Save alokm/1e30c33fa015856fdc167d7fa486245c to your computer and use it in GitHub Desktop.
Save alokm/1e30c33fa015856fdc167d7fa486245c to your computer and use it in GitHub Desktop.
Solvo installation instructions

Introduction

This application is designed to serve as a self-contained backend service providing a non-linear multi-dimensional equation solver.

Installation

Pre-Requisites

  • a computer running Linux, WSL for Windows or Unix for MacOS
  • terminal access to a bash shell

Requirements (installed below)

  • Python 3.7.x
  • Pipenv (python isolated environment)
  • Sqlite3 (database)

Installation Instructions for Requirements

For Debian-based systems like Ubuntu (Linux)

Python 3.7.x

Install dependencies for building Python 3.7.x source

$ sudo apt update -y $ sudo apt install -y software-properties-common $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt install python3.7

Verify installation

$ python3.7 --version Python 3.7.3

Install Pipenv

$ sudo -H pip3 install pipenv

Install

$ sudo apt install sqlite3

Verify installation

$ sqlite3 --version 3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1 # or something like

!#### Installation Complete

For Windows users on Windows Subsystem for Linux (WSL)

  • Install Windows Subsystem for Linux using these instructions
  • Follow the instructions for Ubuntu/Debian Linux above

For MacOS users install using Homebrew instead of apt

Install Python

$ brew doctor $ brew install python3

Verify installation

$ python3 --version Python 3.7.0

Install Sqlite

$ brew install sqlite3

Verify installation

$ sqlite3 --version 3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1 # or something like

Installing and managing the app

Activate Python virtual environment

Let's activate an isolated virtual environment and install all required python dependencies:

$ pipenv shell --python 3.7 (myapi) $

Note the (myapi) added to the bash prompt above indicates this shell is now in an isolated virtual environment with all requiremensts from the Pipfile installed.

Run tests

To run all tests located in the tests/ directory

$ pytest

Access administration entry point

The main entry point for administrating the application is the manager app manage.py

Access manage.py help

$ ./manage.py

Create a database

The app does not have a database so let's create a database called db.sqlite in the current directory.

$ ./manage createdb

The database is now initialized with the columns and tables required by the app but there is no data.

Let's add some sample data:

$ ./manage.py seed_db

Now let's see an inventory of all urls exposed by the api:

$ ./manage.py show-urls

Now the database contains two models each with multiple equations. Let's open a shell to interact with our data

$ ./manage.py shell

We now have a python shell which includes access to the app context and database

get objects used to manipulate db

from myapi.models import db, Model, Equation, Variable

get all models in db

all_models = Model.query.all() print(all_models)

get all equations by model in db

for model in all_models: equations = Equation.query.filter(Equation.model_id == model.id) print(30*'') print(model.name) print(equations) print(30'*')

exit the shell environment and return to bash

exit()

Running the Server and accessing the API

To run the development server on localhost port 5000

$ ./manage runserver

And poke http://localhost:5000/model with GET/POST/PUT/DELETE requests with json data as follows:

  • Add a new model

endpoint: /model method: POST json = {"name": "Unique Model Name"}

  • List all models in db

endpoint: /model method: GET

  • Get a model by id

endpoint: /model/ method: GET

  • Update a model by id

endpoint: /model/ method: PUT json = {"name": "New Model Name"}

  • Delete a model

endpoint: /model/ method: DELETE

  • Add equation to a model

endpoint: /model/ method: POST json = {"text": "the equation string", "status": "True"}

  • Update an equation for a model

endpoint: /model/<model_id>/<equation_id> method: PUT json = {"text": "updated equation string"}

  • Delete an equation for a model

** Send a request to update the equation for a model and submit an empty string as text.

License

All code in MyAPI and Eq is licensed under the GNU AGPLv3 license. See License.txt for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment