Skip to content

Commit

Permalink
✨ MakeFile to ease development process (#22)
Browse files Browse the repository at this point in the history
* ✨Add Code Coverage Reports

* 🔥Remove Toxfile

* ✨MakeFile to ease development process

- Update workflow
- Create MakeFile
  • Loading branch information
keithrfung committed May 6, 2020
1 parent 9fcfab9 commit 8cf9c7b
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 224 deletions.
113 changes: 24 additions & 89 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [pull_request, repository_dispatch]

env:
PYTHON_VERSION: 3.8
CODE_COVERAGE: 90 #TODO Raise coverage to 100

jobs:
linux_check:
Expand All @@ -18,42 +17,16 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install gmpy2 requirements (GMP, MPFR, MPC)
run: |
sudo apt-get install libgmp-dev
sudo apt-get install libmpfr-dev
sudo apt-get install libmpc-dev
- name: Install pipenv
run: pip install pipenv
- name: Install dev dependencies
run: pipenv install --dev
- name: Change Directory
run: cd ${{ github.workspace }}
- name: Install package
run: pipenv run python -m pip install -e .
- name: Check linting with Pylint
run: pipenv run pylint .
- name: Check formatting with Black
continue-on-error: true #TODO Remove black check bypass
run: pipenv run black --check .
- name: Check package metadata
continue-on-error: true #TODO Remove package metadata check bypass
run: pipenv run python setup.py check --strict --metadata --restructuredtext
- name: Check static typing with mypy
continue-on-error: true #TODO Remove mypy check bypass
run: pipenv run mypy bench src stubs tests setup.py
- name: Test package import
run: pipenv run python -c 'import electionguard; print(electionguard.__package__ + " imported")'
- name: Run tests and check coverage
run: |
pipenv run coverage run -m pytest
pipenv run coverage report --fail-under=${{env.CODE_COVERAGE}}
pipenv run coverage erase
- name: Install and Run Tox
continue-on-error: true #TODO Remove tox check bypass
run: |
pip install tox tox-gh-actions
tox
- name: Setup Environment
run: make environment
- name: Install Module
run: make install validate
- name: Lint
run: make lint
- name: Test
run: make coverage
mac_check:
name: MacOS Check
runs-on: macos-latest
Expand All @@ -65,72 +38,34 @@ jobs:
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install gmpy2 requirements (GMP)
run: brew install gmp
- name: Install pipenv
run: pip install pipenv
- name: Install dev dependencies
run: pipenv install --dev
- name: Change Directory
run: cd ${{ github.workspace }}
- name: Install package
run: pipenv run python -m pip install -e .
- name: Check linting with Pylint
run: pipenv run pylint .
- name: Check formatting with Black
continue-on-error: true #TODO Remove black check bypass
run: pipenv run black --check .
- name: Check package metadata
continue-on-error: true #TODO Remove package metadata check bypass
run: pipenv run python setup.py check --strict --metadata --restructuredtext
- name: Check static typing with mypy
continue-on-error: true #TODO Remove mypy check bypass
run: pipenv run mypy bench src stubs tests setup.py
- name: Test package import
run: pipenv run python -c 'import electionguard; print(electionguard.__package__ + " imported")'
- name: Run tests and check coverage
run: |
pipenv run coverage run -m pytest
pipenv run coverage report --fail-under=${{env.CODE_COVERAGE}}
pipenv run coverage erase
- name: Install and Run Tox
continue-on-error: true #TODO Remove tox check bypass
run: |
pip install tox tox-gh-actions
tox
- name: Setup Environment
run: make environment
- name: Install Module
run: make install validate
- name: Lint
run: make lint
- name: Test
run: make coverage
windows_check:
name: Windows Check
runs-on: windows-latest
env:
PIP_FIND_LINKS: "packages/gmpy2-2.0.8-cp38-cp38-win_amd64.whl"
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install pipenv
run: pip install pipenv
- name: Install dev dependencies
run: pipenv install --dev
- name: Change Directory
run: cd ${{ github.workspace }}
- name: Install package
run: pipenv run python -m pip install -e .
- name: Check linting with Pylint
run: pipenv run pylint .
- name: Check formatting with Black
continue-on-error: true #TODO Remove black check bypass
run: pipenv run black --check .
- name: Check package metadata
continue-on-error: true #TODO Remove package metadata check bypass
run: pipenv run python setup.py check --strict --metadata --restructuredtext
- name: Check static typing with mypy
continue-on-error: true #TODO Remove mypy check bypass
run: pipenv run mypy bench src stubs tests setup.py
- name: Test package import
run: pipenv run python -c "import electionguard; print(electionguard.__package__ + ' imported');"
- name: Run tests
- name: Setup Environment
run: make environment
- name: Install Module
run: make install validate
- name: Lint
run: make lint
- name: Test
continue-on-error: true #TODO Remove Window tests bypass
run: pipenv run pytest -x
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pip-delete-this-directory.txt
htmlcov/
.tox/
.nox/
coverage/
.coverage
.coverage.*
.cache
Expand Down
96 changes: 96 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
CODE_COVERAGE ?= 90
WINDOWS_32BIT_GMPY2 ?= packages/gmpy2-2.0.8-cp38-cp38-win32.whl
WINDOWS_64BIT_GMPY2 ?= packages/gmpy2-2.0.8-cp38-cp38-win_amd64.whl
OS ?= $(shell python -c 'import platform; print(platform.system())')
IS_64_BIT ?= $(shell python -c 'from sys import maxsize; print(maxsize > 2**32)')

all: environment install validate lint coverage

environment:
@echo 🔧 PIPENV SETUP
pip install pipenv
pipenv install --dev

install:
@echo 📦 Install Module
@echo Operating System identified as $(OS)
ifeq ($(OS), Linux)
make install-linux
endif
ifeq ($(OS), Darwin)
make install-mac
endif
ifeq ($(OS), Windows)
make install-windows
endif
ifeq ($(OS), Windows_NT)
make install-windows
endif

install-mac:
@echo 🍎 MACOS INSTALL
# gmpy2 requirements
brew install gmp || true
# install module
pipenv run python -m pip install -e .

install-linux:
@echo 🐧 LINUX INSTALL
# gmpy2 requirements
sudo apt-get install libgmp-dev
sudo apt-get install libmpfr-dev
sudo apt-get install libmpc-dev
# install module
pipenv run python -m pip install -e .

install-windows:
@echo 🏁 WINDOWS INSTALL
# install module with local gmpy2 package
@echo IS_64_BIT
ifeq ($(IS_64_BIT), True)
pipenv run python -m pip install -f $(WINDOWS_64BIT_GMPY2) -e .
endif
ifeq ($(IS_64_BIT), False)
pipenv run python -m pip install -f $(WINDOWS_32BIT_GMPY2) -e .
endif


lint:
@echo 💚 LINT
@echo 1.Pylint
pipenv run pylint .
#TODO Remove Black formatting bypass
@echo 2.Black Formatting
pipenv run black --check . || true
#TODO Remove mypy bypass
@echo 3.Mypy Static Typing
pipenv run mypy bench src stubs tests setup.py || true
#TODO Remove package metadata bypass
@echo 4.Package Metadata
pipenv run python setup.py check --strict --metadata --restructuredtext || true

validate:
@echo ✅ VALIDATE
@pipenv run python -c 'import electionguard; print(electionguard.__package__ + " successfully imported")'

test:
@echo ✅ TEST
pipenv run pytest . -x

coverage:
@echo ✅ COVERAGE
pipenv run coverage run -m pytest
pipenv run coverage report --fail-under=$(CODE_COVERAGE)

coverage-html:
@make coverage
pipenv run coverage html -d coverage
@make coverage-erase

coverage-xml:
@make coverage
pipenv run coverage xml
@make coverage-erase

coverage-erase:
@pipenv run coverage erase
56 changes: 49 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ has its own [installation requirements (native C libraries)](https://gmpy2.readt

[pipenv](https://github.com/pypa/pipenv) is used to configure the environment. Installation instructions can be found [here](https://github.com/pypa/pipenv#installation).

### make (optional)

**make** is used to simplify the commands and GitHub Actions. This is built in for MacOS and Linux, but Windows installation instructions can be found [here](http://gnuwin32.sourceforge.net/packages/make.htm).

## Quick Start

Using **make**, the entire workflow can be run with one command: `make`

## Setup

**1. Initialize dev environment**
Expand All @@ -57,22 +65,43 @@ has its own [installation requirements (native C libraries)](https://gmpy2.readt
pipenv install --dev
```

OR

```
make environment
```

**2. Install `electionguard` module in edit mode**

```
pipenv run python -m pip install -e .
```

### Windows
OR

```
make install
```

Use supplied precompiled **gmpy2** package with the `--find-links` or `-f` option.
### Windows without Make

Use supplied precompiled **gmpy2** package with the `--find-links` or `-f` option.

**Note:** The 32 vs 64 bit is based on your installed python version NOT your system.
This code snippet will read `true` for 64 bit.

```
python -c 'from sys import maxsize; print(maxsize > 2**32)
```

**32-bit:**

**32-bit:**
```
pipenv run pip install -f packages/gmpy2-2.0.8-cp38-cp38-win32.whl -e .
```

**64-bit:**
**64-bit:**

```
pipenv run pip install -f packages/gmpy2-2.0.8-cp38-cp38-win_amd64 -e .
```
Expand All @@ -85,16 +114,29 @@ pipenv run pip install -f packages/gmpy2-2.0.8-cp38-cp38-win_amd64 -e .
pipenv run python -m pytest /tests
```

OR

```
make test
```

### Option 2: Run tests in VS Code

Install recommended test explorer extensions and run unit tests through tool.

**Windows:** Be sure to select the [virtual environment Python interpreter](https://docs.microsoft.com/en-us/visualstudio/python/installing-python-interpreters).
### Option 3: Code Coverage

```
pipenv run coverage report
```

### Option 3: Run tox
OR

This project is configured to use [tox](https://tox.readthedocs.io/en/latest/) to run its unit tests.
```
make coverage
```

**Windows:** Be sure to select the [virtual environment Python interpreter](https://docs.microsoft.com/en-us/visualstudio/python/installing-python-interpreters).

## Key concepts

Expand Down
Loading

0 comments on commit 8cf9c7b

Please sign in to comment.