rapid_dev 0.1.0
RaPiD: A Python package for probabilistic risk assessment.
License: MIT
Requires Python: >=3.11,<4.0

# rapid


[![pypi](https://img.shields.io/pypi/v/rapid_dev.svg)](https://pypi.org/project/rapid_dev/)
[![python](https://img.shields.io/pypi/pyversions/rapid_dev.svg)](https://pypi.org/project/rapid_dev/)
[![tests](https://github.com/magkri/rapid_dev/actions/workflows/tests.yml/badge.svg)](https://github.com/magkri/rapid_dev/actions/workflows/tests.yml)

[//]: # ([![codecov]&#40;https://codecov.io/gh/swinter1/rapid_dev/branch/main/graphs/badge.svg&#41;]&#40;https://codecov.io/github/swinter1/rapid_dev&#41;)


Private preliminary development environment for rapid-models package.


- Documentation: <https://solid-adventure-93jg7jm.pages.github.io/>
- GitHub: <https://github.com/dnv-innersource/TDR_rapid_dev>
- Free software: MIT


## Getting started.

The instructions largely follow the information provide [here](https://waynerv.github.io/cookiecutter-pypackage/tutorial/). Alternately, once you have installed `poetry` you can follow the instruction below for additional detail about the tooling included, and an example of how to run each one. There is a dummy function present withing `rapid/rapid.py` which demonstrates the effect of each tool.

### 1. Clone the repo
Clone the repo to your local machine:
```shell
git clone https://github.com/dnv-innersource/TDR_rapid_dev.git
```
Change directory into the repo:
```shell
cd TDR_rapid_dev
```

### Install dependencies
#### poetry
#### Create the virtual environment using poetry. From this repo run:
- (optional) `poetry config virtualenvs.in-project true --local` Can change the config so the virtual environment is place in a file call `.venv` in the current directory.

Install all the dependencies required for development:
```shell
poetry install --with dev,test,docs
```

NOTE: poetry is used inplace of pip. Some basic poetry commands similar to pip;
- `poetry add <package name>` this is similar to pip install
- `poetry show` like `pip list`
After adding poetry packages the need to be installed using `poetry install`

#### Activate the poetry environment:
You can activate the poetry env like you would a typical venv if the folder has been built in your repo (as described above) using the following:

Linux/macOS:
```shell
source .venv/bin/activate
```

Windows:
```powershell
.venv\Scripts\activate.ps1
```

Or, use:
```shell
poetry shell
```

Alternately, to run commands like you typically would once you had activated your virtual environment, preface them with `poetry run <typical command>`

### Checking the installation
There is a sample function provide called 'junk_test_function' at `src\rapid\rapid.py` which can be used to demonstrate the be use of the different tools included in this repo.

## Tools
The tools can be configured in the `pyproject.toml` file.

### Formatters
#### ruff
Format the code according to the formatting rules in the `pyproject.toml` file:
```shell
ruff format
```
#### Poetry dependency sorting
To sort the poetry dependencies in the `pyproject.toml` file (which makes diffing easier):

First, install the poetry plugin [`poetry-plugin-sort`](https://github.com/andrei-shabanski/poetry-plugin-sort):
```shell
poetry self add poetry-plugin-sort
```
Then, run the following command:
```shell
poetry sort
```


### Linters
#### ruff
Check the code for issues according to the linting rules in the `pyproject.toml` file:
```shell
ruff check
```
Fix any issues that can be fixed automatically:
```shell
ruff check --fix
```
#### mypy
Perform static type checking on source code:
```shell
mypy
```

### Documentation
#### mkdocs
-`poetry run mkdocs serve` Will extract the Google docstring form you code and compile the documentation, giving you a local url where you can read the information.

The current setup constructs documentation matching the directory structure of `rapid`. It includes subdirectories and will include a page per python file. It is required that each subdirectory contains an `__init__.py`.

### Test code:
#### pytest
- `poetry run pytest` Will run all the unit test
- `pytest --cov=cookie_personal_pkg --cov-branch --cov-report=xml --cov-report=term-missing tests` generate a coverage report in addition to running pytest

### Manging code quality.
#### tox
- test your package with multiple version of python, operating system, etc. by running the above tests

#### pre-commit
pre-commit can be used to run a selection of the above tools on every commit (e.g. `ruff`). If any of them fail, the commit is aborted. You either have to fix the error to commit again, or add the updated files generate (e.g. files reformatted by `ruff`)
This tool can be run at anytime with the following:
- `poetry run pre-commit run --all-files`
By default this tool is not turned on to run on every commit. To turn it on run
- `poetry run pre-commit install`
To then commit skipping the pre-commit validation (e.g. commit temporary broken come) run:
- `git commit -m “MSG” --no-verify`


#### Make
This can be used to group a series of commands into one.This can be helpful as it is tedious to remember all the above commands that need to be run
- `make test`
Make might not come with git bash. If the approved answer to [this](https://stackoverflow.com/questions/66525016/how-to-run-make-command-in-gitbash-in-windows) stackoverflow query might resolve the issue

#### Bumpversion
- This is a convenience tool
- When you are ready to release a new version of your code, this tool helps make sure you updated to a consistent version everywhere

To use, run:
```shell
bump-my-version bump <major/minor/patch>
```
- `major` means before the first decimal, `minor` the second, `patch` the last


### Release checklist
See instruction [here](https://waynerv.github.io/cookiecutter-pypackage/pypi_release_checklist/)

### Publish a release:
- `poetry build` will build the package
- `poetry publish` will request you pypi credential and publish your package


## Using this repo:
### Getting started:
- When within run through poetry (e.g. within the shell) this package is available as `rapid` for use like a regular module.
- When developing the package with jupyter notebooks, the following command can be run in the notebook to ensure it is always using the most up-to-date code version.
```
%load_ext autoreload
%autoreload 2
```