From 70f2def46d94bb0f9d7155e256f38ee8cda57b96 Mon Sep 17 00:00:00 2001
From: Jirka Borovec <Borda@users.noreply.github.com>
Date: Wed, 16 Sep 2020 01:35:50 +0200
Subject: [PATCH] adding minimal CI (#15)

* adding CI

* badge

* tests
---
 .github/workflows/ci-testing.yml | 70 ++++++++++++++++++++++++++++++++
 README.md                        |  1 +
 setup.cfg                        | 43 ++++++++++++++++++++
 setup.py                         |  1 +
 tests/requirements.txt           |  8 ++++
 tests/test_classifier.py         |  4 +-
 6 files changed, 125 insertions(+), 2 deletions(-)
 create mode 100644 .github/workflows/ci-testing.yml
 create mode 100644 setup.cfg
 create mode 100644 tests/requirements.txt

diff --git a/.github/workflows/ci-testing.yml b/.github/workflows/ci-testing.yml
new file mode 100644
index 0000000..e3da50c
--- /dev/null
+++ b/.github/workflows/ci-testing.yml
@@ -0,0 +1,70 @@
+name: CI testing
+
+# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
+on:
+  # Trigger the workflow on push or pull request, but only for the master branch
+  push:
+    branches:
+      - master
+  pull_request:
+    branches:
+      - master
+
+jobs:
+  pytest:
+
+    runs-on: ${{ matrix.os }}
+    strategy:
+      fail-fast: false
+      matrix:
+        os: [ubuntu-20.04, macOS-10.15, windows-2019]
+        python-version: [3.7]
+
+    # Timeout: https://stackoverflow.com/a/59076067/4521646
+    timeout-minutes: 35
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+
+    # Github Actions: Run step on specific OS: https://stackoverflow.com/a/57948488/4521646
+    - name: Setup macOS
+      if: runner.os == 'macOS'
+      run: |
+        brew install libomp  # https://github.com/pytorch/pytorch/issues/20030
+
+    # Note: This uses an internal pip API and may not always work
+    # https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow
+    - name: Get pip cache
+      id: pip-cache
+      run: |
+        python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
+
+    - name: Cache pip
+      uses: actions/cache@v2
+      with:
+        path: ${{ steps.pip-cache.outputs.dir }}
+        key: ${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}
+        restore-keys: |
+          ${{ runner.os }}-py${{ matrix.python-version }}-
+
+    - name: Install dependencies
+      run: |
+        pip install --requirement requirements.txt --upgrade --quiet --find-links https://download.pytorch.org/whl/cpu/torch_stable.html --use-feature=2020-resolver
+        pip install --requirement tests/requirements.txt --quiet --use-feature=2020-resolver
+        python --version
+        pip --version
+        pip list
+      shell: bash
+
+    - name: Tests
+      run: |
+        coverage run --source project -m py.test project tests -v --junitxml=junit/test-results-${{ runner.os }}-${{ matrix.python-version }}.xml
+
+    - name: Statistics
+      if: success()
+      run: |
+        coverage report
diff --git a/README.md b/README.md
index 82d6463..63571ba 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ The goal of this seed is to structure ML paper-code the same so that work can ea
 ARXIV   
 [![Paper](http://img.shields.io/badge/arxiv-math.co:1480.1111-B31B1B.svg)](https://www.nature.com/articles/nature14539)
 -->
+![CI testing](https://github.com/PyTorchLightning/deep-learning-project-template/workflows/CI%20testing/badge.svg?branch=master&event=push)
 
 
 <!--  
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..268bbb9
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,43 @@
+[tool:pytest]
+norecursedirs =
+    .git
+    dist
+    build
+addopts =
+    --strict
+    --doctest-modules
+    --durations=0
+
+[coverage:report]
+exclude_lines =
+    pragma: no-cover
+    pass
+
+[flake8]
+max-line-length = 120
+exclude = .tox,*.egg,build,temp
+select = E,W,F
+doctests = True
+verbose = 2
+# https://pep8.readthedocs.io/en/latest/intro.html#error-codes
+format = pylint
+# see: https://www.flake8rules.com/
+ignore =
+    E731  # Do not assign a lambda expression, use a def
+    W504  # Line break occurred after a binary operator
+    F401  # Module imported but unused
+    F841  # Local variable name is assigned to but never used
+    W605  # Invalid escape sequence 'x'
+
+# setup.cfg or tox.ini
+[check-manifest]
+ignore =
+    *.yml
+    .github
+    .github/*
+
+[metadata]
+license_file = LICENSE
+description-file = README.md
+# long_description = file:README.md
+# long_description_content_type = text/markdown
diff --git a/setup.py b/setup.py
index ff891d7..3de44dd 100644
--- a/setup.py
+++ b/setup.py
@@ -13,3 +13,4 @@ setup(
     install_requires=['pytorch-lightning'],
     packages=find_packages(),
 )
+
diff --git a/tests/requirements.txt b/tests/requirements.txt
new file mode 100644
index 0000000..09f038f
--- /dev/null
+++ b/tests/requirements.txt
@@ -0,0 +1,8 @@
+coverage
+codecov>=2.1
+pytest>=3.0.5
+pytest-cov
+pytest-flake8
+flake8
+check-manifest
+twine==1.13.0
\ No newline at end of file
diff --git a/tests/test_classifier.py b/tests/test_classifier.py
index a11a314..96be92b 100644
--- a/tests/test_classifier.py
+++ b/tests/test_classifier.py
@@ -1,7 +1,7 @@
-from project.datasets.mnist import mnist
-from project.lit_classifier_main import LitClassifier
 from pytorch_lightning import Trainer, seed_everything
 
+from project.lit_classifier_main import LitClassifier
+
 
 def test_lit_classifier():
     seed_everything(1234)
-- 
GitLab