Skip to content

Build & Run

Daniel Lee Young Ph.D edited this page Jan 26, 2021 · 2 revisions

Installation Instructions for Developers

The software has been developed by CESER to run as a Django/Python web app on the EPA RTP RHEL server. No build & run instructions for users is therefore required. All data uploaded to the RTP RHEL server is QA'd and uploaded by CESER/LRTD/EDAB research staff or contractor support. Access this tool @ https://qappbuilder.epa.gov for use.

Local Installation

Please refer to the User Manual (UM) and SOPs

Software Configuration Management (SCM) SOP for more information.

Prerequisites

  1. Windows development machine preferred
  2. Git - https://git-scm.com/downloads a. Plus any Git clients.
  3. Python 3.8.1 - https://www.python.org/downloads/ a. When installing, make sure that pip gets chosen as an additional feature.
  4. Latest version of Pip. Included with Python installation.
  5. Visual Studio 2019 - https://www.visualstudio.com/downloads/ or other Integrated Development Environment with support for Django apps.
    • The free Community Edition is sufficient.
  6. PostgreSQL v 10 or higher.
  7. PgAdmin4

Setup Virtual Environments

These steps use the Windows Command Prompt to set up the Python environments necessary for developing multiple Python projects.

  1. Add pip to your path if necessary.
  2. Install necessary packages
    • pip install virtualenv
    • pip install virtualenvwrapper
    • pip install virtualenvwrapper-win
  3. Add an environment variable WORKON_HOME to specify the path to store environments. By default, this is %USERPROFILE%\Envs
  4. Create a QAPP Builder virtual environment with the command mkvirtualenv qappbuilder
  5. Switch between environments with the command workon {env_name}

Setup Python Django project in Visual Studio 2019

A fresh clone of the repository should not have any Visual Studio related files, such as .sln, .pyproj, .vs/, etc. If it does, then delete them. You’ll need to set up your local environment anyway.

  1. Open Visual Studio and select File > New > Project
  2. In the left pane, select Python and choose ‘From Existing Python Code’
  3. For the location, enter the file path to the python project (C:/Git/qappbuilder)
  4. Name the project.
  5. Submit and click next. Choose manage.py as the startup file and press next.
  6. On this final page, select both check boxes and change the project type to Django Web Project. Click finish.
  7. In the solution explorer, right click on Python Environments and select Add Virtual Environment.
    • Navigate the location to the virtual environment previously created (look in %USERPROFILE%\Envs). Alternatively, you can just create a new one in the default location through Visual Studio, which is inside the source code. This is okay and will be ignored by git
  8. In the solution explorer, right click on the new virtual environment and select install from requirements.txt
    • Alternatively, you can do this via command line with the following commands
      • cd /working/directory
      • workon {qappbuilder_env}
      • pip install –r requirements.txt
  9. Create a database called qappbuilder and import the latest data from the databases/ directory.
  10. Download and configure the local_settings.py file. Make sure to configure the proper Database settings.

INSTALLATION SETUP IDE

  1. Install Git @ https://git-scm.com/downloads
  2. Clone the repository to a local location. The Gateway uses C:\Git as the root directory, so the project is C:\Git\qappbuilder
  3. If the clone fails, you may need to extend the available path length and restart the cloning process:
    • From the git hub install, open Git shell (Alternatively, open Powershell.exe and cd to C:\Users\username\Documents\GitHub)
    • Type the command: git config –system core.longpaths true
*  Note: Make sure pgAdmin 4 is selected and installed.
    Command ran for importing a psql data dump:
    **psql -U postgres -d useeio-foodwaste -f dumpfilename**
    Or if psql isn’t in the path, we cd into the psql installation directory\bin\ (location of psql.exe) and ran
    **psql.exe-U postgres –d useeio-foodwaste –f “path\to\filename.sql”**

Install Python 64-bit 3.8.2 https://www.python.org/downloads/

*  The installation takes a while to get started.
*  When choosing additional features, make sure that pip gets installed as well.
*  Note: There are SDK .NETFramework issues when using older VS versions.

Install VS 2019 Extensions & Updates

*  Install SDK (.NETFramework 4.5.2)
*  Install GitHub Extension for Visual Studio

Install and Setup Python Virtual Environments

*  **pip install virtualenv**
*  **pip install virtualenvwrapper**
*  **pip install virtualenvwrapper-win**
*  Create a useeio-foodwaste virtual environment with the command **mkvirtualenv qappbuilder**

If the qappbuilder is not yet a VS project, you will need to open it in visual studio to get a proj file. Else, skip these steps

*  Open Visual Studio and select File > New > Project
*  In the left pane, select Python and choose ‘From Existing Python Code’
*  For the location, enter the file path to the python project (C:/Git/qappbuilder)
*  The project name should derive itself from the chosen file location, if not, give it a name.
*  Submit and click next. Choose manage.py as the startup file and press next.
*  On this final page, select both check boxes and change the project type to Django Web Project. Click finish.

Add the 'qappbuilder' virtual environment to your VS project

*  In the solution explorer on the right, right-click on 'Python Environments' and select 'Add Virtual Environment'.
*  For 'Location of the virtual environment', browse to the useeio-foodwaste virtual environment location, usually found in 'C:\Users\%Username%\Envs\'
*  Using the checkbox, you can let VS automatically install all required pip packages.

Install Python Packages (if they weren't installed)

*  In the solution explorer, expand Python Environment, right click the useeio-foodwaste environment, and select 'Install from requirements.txt'

The following pip packages are used and listed in requirements.txt

BUILD and RUN DJANGO APP

  1. Set up a PostgreSQL server if one is not already installed on the machine.
  2. Use qappbuilder.backup to import data into your local PostgreSQL.
  3. In the qappbuilder Project, edit (or create if not exists) the local_settings.py file, in the same directory as all the other python code (qappbuilder> qappbuilder). This file will be imported by settings.py and used to overwrite data in the setting.py
  4. Change the credentials in DATABASES so that it will work with your local copy.
  5. Open a terminal, go into the qappbuilder>qappbuilder directory, and run the following python commands

python manage.py migrate
python manage.py createsuperuser

Follow the prompts to create the user name and password. This will be used for logging into the local version.

  1. Launch the application from the terminal using

python manage.py runserver

This will run the application on http://localhost:8000 by default.

INSTALLATION & UPDATES (to server)

RHEL/FEDORA Server

PostgreSQL Install

[sudo yum install postgresql-server]

qappbuilder

Installation and updating qappbuilder Web Tool on Fedora Server. Fedora Command Line. The 'dnf' command (equivalent to apt-get)

Weekly security update commands

Update qappbuilder Web Tool from US EPA GitHub server https://github.com/USEPA/qappbuilder From root E4S folder, execute as su:

  • git add [file_names] (if any new files/directories were created)
    • git commit -m "Insert Comments Here"
    • git remote add origin https://[email protected]/USEPA/qappbuilder.git
    • git push origin master/branch_name (to merge server version with github version)
    • git pull origin master/branch_name (to merge github version with server version)