# OWS Project Manager

## Getting Started

### Installation

The installation is very straightforward, but make sure you are using at least
python 3.4. If you use a Mac, you can install it using `brew`. If you use
Windows, just ask for a remote VM that has it installed for you.

```
python -m venv env
source env/bin/activate
source .env
make pip_dev
```

### Updating

To update packages in developments.

```bash
make pip_dev
```

### Environment Variables

Copy .env.shadow to .env and add the appropriate environement variables for your
environment.

```bash
cp .env.shadow .env
```

### Running

When all dependencies have been installed, you can run the flask application
on your local instance by running:

```bash
python dev.py
```

or

```bash
make dev
```

or

```bash
docker compose up dev
```

You may use the PORT environment variable to run the dev server on a port
different than the default (5000)

```bash
PORT=5001 python dev.py
```

By using the development server, you will have access to specific features that
are not necessarily available in production, such as the exception tracer.

### Implementation of loggly

Add below line in file where you need to log message.

```bash
from flask import g
```

Implementation of loggly to log messages.

```bash
g.log.info('User has hit the homepage')
```

### Testing

If you get Segmentation Fault (`SIGSEGV`) or Bus Error (`SIGBUS`)
while running tests, run them inside a docker container instead.

#### General Instructions:

```bash
docker compose run test
```

#### Instructions for PyCharm:

1. Build [Dockerfile dev_env](Dockerfile) image:
    ```bash
    docker compose build dev_env
    ```
    Image will be tagged as `ows-project-manager_dev_env`
2. Set project python interpreter to docker image `ows-project-manager_dev_env`

    ![](doc/using-a-dockerized-remote-python-interpreter-1.png)
    ![](doc/using-a-dockerized-remote-python-interpreter-2.png)
    ![](doc/using-a-dockerized-remote-python-interpreter-3.png)

3. Set up test run/debug configuration

    ![](doc/configuring-tests-to-run-and-debug-in-dockerized-remote-python-interpreter-1.png)
    PyCharm Run/Debug Configuration: [.run/pytest-in-tests.run.xml](.run/pytest-in-tests.run.xml)

or

```bash
make test
```

or

```bash
py.test tests/ --cov project_manager --cov-report term-missing
```

### Linting

```bash
make lint
```

or

```bash
ruff check project_manager/ tests/
```
