From b1ad9d5516c24f6124d8135809100fc257c2de77 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sat, 24 Sep 2022 19:52:05 +0200 Subject: [PATCH 01/12] Remove building docs from testing workflow since this is already tested in the build_docs workflow --- .github/workflows/test_package.yml | 34 ++++++++++-------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index a1cbc08..793968e 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -25,10 +25,10 @@ jobs: steps: # This action sets the current path to the root of your github repo - uses: actions/checkout@v3 - + - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: "3.10" - name: "Install code" run: pip install .[test,docs] @@ -38,15 +38,15 @@ jobs: - name: Mypy check run: | - pip install mypy - python -m mypy . --exclude=build + pip install mypy + python -m mypy . --exclude=build - name: Generate coverage report run: python -m pytest --cov=mypackage test - name: Generate html report run: python -m coverage html - + - name: Upload coverage report as artifact uses: actions/upload-artifact@v3 with: @@ -54,37 +54,25 @@ jobs: path: htmlcov if-no-files-found: error - - name: Build documentation - run: | - make doc - - - name: Upload documentation - uses: actions/upload-artifact@v3 - with: - name: documentation - path: docs/_build/html - if-no-files-found: error - - test-code: # This code depends on the result of check-code needs: check-code runs-on: ${{ matrix.os }} - + strategy: matrix: - os: [ubuntu-22.04, windows-latest, macos-12] - + os: [ubuntu-22.04, windows-latest, macos-12] + steps: - uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: "3.10" - uses: actions/checkout@v3 - + - name: "Install mypackage" run: pip install .[test] - name: Run tests run: | - python -m pytest test/ \ No newline at end of file + python -m pytest test/ From 9326fb49436fe0ae13f9f03d90cd4b1894483f8b Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sat, 24 Sep 2022 19:57:48 +0200 Subject: [PATCH 02/12] Move coverage report to final step --- .github/workflows/test_package.yml | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index 793968e..d76b11f 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -41,19 +41,6 @@ jobs: pip install mypy python -m mypy . --exclude=build - - name: Generate coverage report - run: python -m pytest --cov=mypackage test - - - name: Generate html report - run: python -m coverage html - - - name: Upload coverage report as artifact - uses: actions/upload-artifact@v3 - with: - name: code-coverage-report - path: htmlcov - if-no-files-found: error - test-code: # This code depends on the result of check-code needs: check-code @@ -75,4 +62,12 @@ jobs: - name: Run tests run: | - python -m pytest test/ + python -m pytest test --cov=mypackage --cov-report=html + + - name: Upload coverage report as artifact + if: matrix.os == 'ubuntu-22.04' + uses: actions/upload-artifact@v3 + with: + name: code-coverage-report + path: htmlcov + if-no-files-found: error From 9d7d88d15e0255cb15ed307f87abbf34d37dc5bb Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sat, 24 Sep 2022 20:03:47 +0200 Subject: [PATCH 03/12] Test multiple versions of python --- .github/workflows/test_package.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index d76b11f..911499a 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -49,14 +49,15 @@ jobs: strategy: matrix: os: [ubuntu-22.04, windows-latest, macos-12] + python-version: [3.8, 3.9, "3.10"] steps: - uses: actions/setup-python@v4 + - name: Set up Python ${{ matrix.python-version }} with: - python-version: "3.10" + python-version: ${{ matrix.python-version }} - uses: actions/checkout@v3 - - name: "Install mypackage" run: pip install .[test] From c3bccb29a3905cb8d68d88336d9bcb2b8f067cbb Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sat, 24 Sep 2022 20:06:44 +0200 Subject: [PATCH 04/12] Swtich order to uses and name in workflow --- .github/workflows/test_package.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index 911499a..f94657a 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -52,12 +52,13 @@ jobs: python-version: [3.8, 3.9, "3.10"] steps: - - uses: actions/setup-python@v4 - name: Set up Python ${{ matrix.python-version }} + - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - uses: actions/checkout@v3 + - name: "Install mypackage" run: pip install .[test] From a611ad63e6a81729b36f6e147e5a1071126e56e9 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sat, 24 Sep 2022 20:16:37 +0200 Subject: [PATCH 05/12] Move mypy config to setup.cfg. Add config for pytest. Use matrix from python version in check code --- .github/workflows/test_package.yml | 17 ++++++++++------- pyproject.toml | 7 ------- setup.cfg | 10 +++++++++- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index f94657a..c2bed1a 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -22,24 +22,27 @@ jobs: # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources runs-on: ubuntu-22.04 + strategy: + matrix: + python-version: [3.8, 3.9, "3.10"] + steps: # This action sets the current path to the root of your github repo - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 with: - python-version: "3.10" + python-version: ${{ matrix.python-version }} - name: "Install code" - run: pip install .[test,docs] + run: python -m pip install .[test] - name: Flake8 code - run: flake8 . + run: python -m flake8 - name: Mypy check - run: | - pip install mypy - python -m mypy . --exclude=build + run: python -m mypy test-code: # This code depends on the result of check-code @@ -64,7 +67,7 @@ jobs: - name: Run tests run: | - python -m pytest test --cov=mypackage --cov-report=html + python -m pytest - name: Upload coverage report as artifact if: matrix.os == 'ubuntu-22.04' diff --git a/pyproject.toml b/pyproject.toml index 1a7ac36..0fec40e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,11 +33,4 @@ docs = [ binder = [ # Required to interface with Binder when having a Dockerfile in root "jupyterlab", "notebook" -] - -[tool.mypy] -ignore_missing_imports = true # Does not show errors when importing untyped libraries -exclude = [ # We only want mypy to consider files that are not generated in installing or building documentation - "docs/", - "build/" ] \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index e8527bd..9c6d087 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,15 @@ # flake8 does not support pyproject.toml, see: # https://github.com/PyCQA/flake8/issues/234 [flake8] -exclude = docs +exclude = docs,venv max-line-length = 100 +[mypy] +files = src,test +ignore_missing_imports = true +exclude = docs,build +[tool:pytest] +addopts = --cov=src/mypackage --cov-report html --cov-report term-missing -v +testpaths = + test \ No newline at end of file From 3d51dd20b46edc8266d2d9c2264cbbce633a55cb Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sat, 24 Sep 2022 20:20:43 +0200 Subject: [PATCH 06/12] Remove some dashes --- .github/workflows/test_package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index c2bed1a..b936e1e 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -31,7 +31,7 @@ jobs: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - - uses: actions/setup-python@v4 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} @@ -56,7 +56,7 @@ jobs: steps: - name: Set up Python ${{ matrix.python-version }} - - uses: actions/setup-python@v4 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} From ffb4390ce7fc6ab49988ff88da4b8c63f2cf4e41 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sat, 24 Sep 2022 20:23:25 +0200 Subject: [PATCH 07/12] Only upload artifact from coverage report for python3.10 on ubuntu --- .github/workflows/test_package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index b936e1e..3ce50cf 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -70,7 +70,7 @@ jobs: python -m pytest - name: Upload coverage report as artifact - if: matrix.os == 'ubuntu-22.04' + if: matrix.os == 'ubuntu-22.04' && matrix.python-version == '3.10' uses: actions/upload-artifact@v3 with: name: code-coverage-report From 660ce5168d4343250337bbf24d42fdfb554e696a Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sun, 25 Sep 2022 20:40:26 +0200 Subject: [PATCH 08/12] Change python version to strings --- .github/workflows/test_package.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index 3ce50cf..0f9e680 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: - python-version: [3.8, 3.9, "3.10"] + python-version: ["3.8", "3.9", "3.10"] steps: # This action sets the current path to the root of your github repo @@ -52,7 +52,7 @@ jobs: strategy: matrix: os: [ubuntu-22.04, windows-latest, macos-12] - python-version: [3.8, 3.9, "3.10"] + python-version: ["3.8", "3.9", "3.10"] steps: - name: Set up Python ${{ matrix.python-version }} From 0bb6d1ed798dfcaa4781503132f7a341e761c7e3 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sun, 25 Sep 2022 20:42:18 +0200 Subject: [PATCH 09/12] Use mypackage as cov target instead of src/mypackage - this would only work for editable installs --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 9c6d087..6a7c0ee 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,6 +10,6 @@ ignore_missing_imports = true exclude = docs,build [tool:pytest] -addopts = --cov=src/mypackage --cov-report html --cov-report term-missing -v +addopts = --cov=mypackage --cov-report html --cov-report term-missing -v testpaths = test \ No newline at end of file From b0a76c425324e4d7630ec7fffb82cd5efaf8d551 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sun, 25 Sep 2022 20:43:08 +0200 Subject: [PATCH 10/12] Run test CI only on push to master or PR to master --- .github/workflows/test_package.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_package.yml b/.github/workflows/test_package.yml index 0f9e680..fca1aa8 100644 --- a/.github/workflows/test_package.yml +++ b/.github/workflows/test_package.yml @@ -4,7 +4,7 @@ on: push: # The CI is executed on every push on every branch branches: - - "**" + - main pull_request: # The CI is executed on every pull request to the main branch branches: From 8b6a585fa9efee26fc6d6e20c3b0e65b0c9f1f26 Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sun, 25 Sep 2022 20:59:53 +0200 Subject: [PATCH 11/12] Move mypy and pytest configurations to pyproject.toml and flake8 configurations to .flake8 --- .flake8 | 5 +++++ pyproject.toml | 13 +++++++++++++ setup.cfg | 15 --------------- 3 files changed, 18 insertions(+), 15 deletions(-) create mode 100644 .flake8 delete mode 100644 setup.cfg diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..2561054 --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +# flake8 does not support pyproject.toml, see: +# https://github.com/PyCQA/flake8/issues/234 +[flake8] +exclude = docs,venv +max-line-length = 100 \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 0fec40e..732f618 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,4 +33,17 @@ docs = [ binder = [ # Required to interface with Binder when having a Dockerfile in root "jupyterlab", "notebook" +] + +[tool.mypy] +ignore_missing_imports = true # Does not show errors when importing untyped libraries +exclude = [ # We only want mypy to consider files that are not generated in installing or building documentation + "docs/", + "build/" +] + +[tool.pytest.ini_options] +addopts = "--cov=mypackage --cov-report html --cov-report term-missing -v" +testpaths = [ + "test" ] \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 6a7c0ee..0000000 --- a/setup.cfg +++ /dev/null @@ -1,15 +0,0 @@ -# flake8 does not support pyproject.toml, see: -# https://github.com/PyCQA/flake8/issues/234 -[flake8] -exclude = docs,venv -max-line-length = 100 - -[mypy] -files = src,test -ignore_missing_imports = true -exclude = docs,build - -[tool:pytest] -addopts = --cov=mypackage --cov-report html --cov-report term-missing -v -testpaths = - test \ No newline at end of file From ee2a7e792fa7ddfe554e1b1ff408aea999263eea Mon Sep 17 00:00:00 2001 From: Henrik Finsberg Date: Sun, 25 Sep 2022 21:02:27 +0200 Subject: [PATCH 12/12] Add list of folders to be checked by mypy --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 732f618..a2c21b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,10 @@ exclude = [ # We only want mypy to consider files that are not generated in inst "docs/", "build/" ] +files = [ # Folder to which files that should be checked by mypy + "src", + "test" +] [tool.pytest.ini_options] addopts = "--cov=mypackage --cov-report html --cov-report term-missing -v"