Repository: tomekzaw/ewl (language: python)

Issue:
Setup CI/CD
* lint with `flake8`
* test with `pytest`
* publish to PyPI


Discussion / hints:

Fix patch:
diff --git a/.editorconfig b/.editorconfig
index 4ee6cd0..fa6c23c 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -42,3 +42,6 @@ indent_style = tab
 
 [docs/**.txt]
 max_line_length = 79
+
+[*.yml]
+indent_size = 2
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
new file mode 100644
index 0000000..7d15e98
--- /dev/null
+++ b/.github/workflows/lint.yml
@@ -0,0 +1,32 @@
+name: Lint with flake8
+
+on: [push]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Setup Python
+        uses: actions/setup-python@v2
+        with:
+          python-version: "3.9"
+      - name: Cache pip
+        uses: actions/cache@v2
+        with:
+          path: ~/.cache/pip
+          key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-
+            ${{ runner.os }}-
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          pip install setuptools flake8
+          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
+      - name: Install Python package
+        run: |
+          python setup.py install
+      - name: Lint with flake8
+        run: |
+          flake8 . --ignore E501 --exclude .venv
diff --git a/src/ewl/__init__.py b/src/ewl/__init__.py
index c06bf9e..ffd1caa 100644
--- a/src/ewl/__init__.py
+++ b/src/ewl/__init__.py
@@ -2,7 +2,7 @@
 from functools import cached_property
 from itertools import product
 from math import log2
-from typing import Optional, Sequence, Dict
+from typing import Sequence, Dict
 
 import numpy as np
 import sympy as sp
@@ -68,19 +68,18 @@ def J(psi, C: Matrix, D: Matrix) -> Matrix:
 
 
 class EWL:
-    def __init__(self, psi, strategies: Sequence[Matrix], provider: Optional[AccountProvider] = None):
+    def __init__(self, psi, strategies: Sequence[Matrix]):
         assert number_of_qubits(psi) == len(strategies)
 
         self.psi = psi
         self.strategies = strategies
 
-        if provider is None:
-            try:
-                self.provider = IBMQ.get_provider()
-            except IBMQProviderError:
-                raise RuntimeError('Please run this notebook on https://quantum-computing.ibm.com/lab')
-        else:
-            self.provider = provider
+    @cached_property
+    def provider(self) -> AccountProvider:
+        try:
+            return IBMQ.get_provider()
+        except IBMQProviderError:
+            raise RuntimeError('Please run this notebook on https://quantum-computing.ibm.com/lab')
 
     @cached_property
     def number_of_players(self) -> int:


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..c2f0372
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,32 @@
+name: Test with pytest
+
+on: [push]
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+      - name: Setup Python
+        uses: actions/setup-python@v2
+        with:
+          python-version: "3.9"
+      - name: Cache pip
+        uses: actions/cache@v2
+        with:
+          path: ~/.cache/pip
+          key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
+          restore-keys: |
+            ${{ runner.os }}-pip-
+            ${{ runner.os }}-
+      - name: Install dependencies
+        run: |
+          python -m pip install --upgrade pip
+          pip install setuptools pytest
+          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
+      - name: Install Python package
+        run: |
+          python setup.py install
+      - name: Test with pytest
+        run: |
+          pytest
diff --git a/tests/test_ewl.py b/tests/test_ewl.py
index 9b863ea..2a0fefd 100644
--- a/tests/test_ewl.py
+++ b/tests/test_ewl.py
@@ -137,4 +137,4 @@ def test_ewl_qc(ewl: EWL):
 
 
 def test_calculate_probs(ewl: EWL):
-    assert ewl.calculate_probs() == Matrix([0, 0, 1/2, 1/2])
+    assert ewl.calculate_probs() == Matrix([0, 0, 1 / 2, 1 / 2])