From 3f87c330c059e3e450a1002efcf96b6af75fbfd5 Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Sat, 9 Jan 2021 19:53:35 -0800 Subject: [PATCH 1/9] Create python-package-conda.yml --- .github/workflows/python-package-conda.yml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/python-package-conda.yml diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml new file mode 100644 index 000000000..7bae7e247 --- /dev/null +++ b/.github/workflows/python-package-conda.yml @@ -0,0 +1,34 @@ +name: Python Package using Conda + +on: [push] + +jobs: + build-linux: + runs-on: ubuntu-latest + strategy: + max-parallel: 5 + + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.8 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Add conda to system path + run: | + # $CONDA is an environment variable pointing to the root of the miniconda directory + echo $CONDA/bin >> $GITHUB_PATH + - name: Install dependencies + run: | + conda env update --file environment.yml --name base + - name: Lint with flake8 + run: | + conda install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + conda install pytest + pytest From 21e47a6919b2f44470b671fee472f87298e91538 Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Sat, 9 Jan 2021 19:57:20 -0800 Subject: [PATCH 2/9] remove flake8 lint; add dependencies --- .github/workflows/python-package-conda.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 7bae7e247..a58aeac0d 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -20,14 +20,8 @@ jobs: echo $CONDA/bin >> $GITHUB_PATH - name: Install dependencies run: | - conda env update --file environment.yml --name base - - name: Lint with flake8 - run: | - conda install flake8 - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + conda install numpy scipy matplotlib pytest + conda install -c conda-forge slycot - name: Test with pytest run: | conda install pytest From d83e67d0f37f051ea268eab23158e68e98531067 Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Sat, 9 Jan 2021 22:11:04 -0800 Subject: [PATCH 3/9] skip X11 tests if no DISPLAY env variable --- control/tests/conftest.py | 3 ++- control/tests/rlocus_test.py | 3 +++ control/tests/sisotool_test.py | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/control/tests/conftest.py b/control/tests/conftest.py index b67ef3674..b7fac8fe5 100644 --- a/control/tests/conftest.py +++ b/control/tests/conftest.py @@ -26,7 +26,8 @@ "PendingDeprecationWarning") matrixerrorfilter = pytest.mark.filterwarnings("error:.*matrix subclass:" "PendingDeprecationWarning") - +X11only = pytest.mark.skipif(os.getenv("DISPLAY") is None, + reason="requires X11") @pytest.fixture(scope="session", autouse=True) def control_defaults(): diff --git a/control/tests/rlocus_test.py b/control/tests/rlocus_test.py index cf2b72cd3..47df12d2b 100644 --- a/control/tests/rlocus_test.py +++ b/control/tests/rlocus_test.py @@ -13,6 +13,8 @@ from control.statesp import StateSpace from control.bdalg import feedback +from control.tests.conftest import X11only + class TestRootLocus: """These are tests for the feedback function in rlocus.py.""" @@ -48,6 +50,7 @@ def test_without_gains(self, sys): roots, kvect = root_locus(sys, plot=False) self.check_cl_poles(sys, roots, kvect) + @X11only def test_root_locus_zoom(self): """Check the zooming functionality of the Root locus plot""" system = TransferFunction([1000], [1, 25, 100, 0]) diff --git a/control/tests/sisotool_test.py b/control/tests/sisotool_test.py index 65f87f28b..c584413ab 100644 --- a/control/tests/sisotool_test.py +++ b/control/tests/sisotool_test.py @@ -9,6 +9,7 @@ from control.rlocus import _RLClickDispatcher from control.xferfcn import TransferFunction +from control.tests.conftest import X11only @pytest.mark.usefixtures("mplcleanup") class TestSisotool: @@ -19,6 +20,7 @@ def sys(self): """Return a generic SISO transfer function""" return TransferFunction([1000], [1, 25, 100, 0]) + @X11only def test_sisotool(self, sys): sisotool(sys, Hz=False) fig = plt.gcf() From 627754fd9c4b7bd81cc16b9e8e22da1e85c8f308 Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Sat, 9 Jan 2021 22:11:12 -0800 Subject: [PATCH 4/9] expand test matrix to match Travis CI --- .github/workflows/python-package-conda.yml | 44 +++++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index a58aeac0d..3121938f2 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -1,28 +1,52 @@ -name: Python Package using Conda +name: Conda-based pytest -on: [push] +on: [push, pull_request] jobs: build-linux: runs-on: ubuntu-latest + strategy: max-parallel: 5 + matrix: + python-version: [2.7, 3.6, 3.9] + slycot: ["", "conda"] + array-and-matrix: [0] + include: + - python-version: 3.9 + slycot: conda + array-and-matrix: 1 steps: - uses: actions/checkout@v2 - - name: Set up Python 3.8 + - name: Set up Python uses: actions/setup-python@v2 - with: - python-version: 3.8 - - name: Add conda to system path + - name: Set up conda run: | - # $CONDA is an environment variable pointing to the root of the miniconda directory echo $CONDA/bin >> $GITHUB_PATH + conda create -q -n test-environment python=${{matrix.python-version}} - name: Install dependencies run: | - conda install numpy scipy matplotlib pytest + source $CONDA/bin/activate test-environment + conda install pip coverage pytest + conda install numpy matplotlib scipy + if [[ '${{matrix.python-version}}' == '2.7' ]]; then + # matplotlib for Python 2.7 seems to require X11 to run correctly + sudo apt install -y xvfb + fi + - name: Install slycot via conda (optional) + if: ${{ matrix.slycot == 'conda' }} + run: | + source $CONDA/bin/activate test-environment conda install -c conda-forge slycot - name: Test with pytest + env: + PYTHON_CONTROL_ARRAY_AND_MATRIX: ${{ matrix.array-and-matrix }} run: | - conda install pytest - pytest + source $CONDA/bin/activate test-environment + if [[ '${{matrix.python-version}}' == '2.7' ]]; then + # Run within (virtual) X11 environment for Python 2.7/matplotlib + xvfb-run pytest control/tests + else + coverage run -m pytest control/tests + fi From 47251c655276adbd898e01fb2660cdafeaaa9d58 Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Sun, 10 Jan 2021 19:02:02 -0800 Subject: [PATCH 5/9] simplify GitHub actions workflow --- .github/workflows/python-package-conda.yml | 36 +++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 3121938f2..9a3157a8a 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -9,7 +9,7 @@ jobs: strategy: max-parallel: 5 matrix: - python-version: [2.7, 3.6, 3.9] + python-version: [3.6, 3.9] slycot: ["", "conda"] array-and-matrix: [0] include: @@ -19,34 +19,28 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - - name: Set up conda + - name: Install dependencies run: | + # Set up conda echo $CONDA/bin >> $GITHUB_PATH conda create -q -n test-environment python=${{matrix.python-version}} - - name: Install dependencies - run: | source $CONDA/bin/activate test-environment - conda install pip coverage pytest + + # Set up (virtual) X11 + sudo apt install -y xvfb + + # Install test tools + conda install pip coverage pytest + conda install -c conda-forge pytest-xvfb pytest-cov + + # Install python-control dependencies conda install numpy matplotlib scipy - if [[ '${{matrix.python-version}}' == '2.7' ]]; then - # matplotlib for Python 2.7 seems to require X11 to run correctly - sudo apt install -y xvfb + if [[ '${{matrix.slycot}}' == 'conda' ]]; then + conda install -c conda-forge slycot fi - - name: Install slycot via conda (optional) - if: ${{ matrix.slycot == 'conda' }} - run: | - source $CONDA/bin/activate test-environment - conda install -c conda-forge slycot - name: Test with pytest env: PYTHON_CONTROL_ARRAY_AND_MATRIX: ${{ matrix.array-and-matrix }} run: | source $CONDA/bin/activate test-environment - if [[ '${{matrix.python-version}}' == '2.7' ]]; then - # Run within (virtual) X11 environment for Python 2.7/matplotlib - xvfb-run pytest control/tests - else - coverage run -m pytest control/tests - fi + xvfb-run --auto-servernum pytest control/tests From 6ff2e9bdbf5b75abe40f36f324f21b539370d29c Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Sun, 10 Jan 2021 21:38:02 -0800 Subject: [PATCH 6/9] pytest with slycot from source --- .github/workflows/control-slycot-src.yml | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/control-slycot-src.yml diff --git a/.github/workflows/control-slycot-src.yml b/.github/workflows/control-slycot-src.yml new file mode 100644 index 000000000..e4455ed4a --- /dev/null +++ b/.github/workflows/control-slycot-src.yml @@ -0,0 +1,36 @@ +name: Slycot from source + +on: [push, pull_request] + +jobs: + build-linux: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + - name: Install Python dependencies + run: | + # Set up conda + echo $CONDA/bin >> $GITHUB_PATH + + # Install test tools + conda install pip pytest + + # Install python-control dependencies + conda install numpy matplotlib scipy + + - name: Install slycot from source + run: | + # Install compilers, libraries, and development environment + sudo apt-get -y install gfortran cmake --fix-missing + sudo apt-get -y install libblas-dev liblapack-dev + conda install -c conda-forge scikit-build; + + # Compile and install slycot + git clone https://github.com/python-control/Slycot.git slycot + cd slycot; python setup.py build_ext install -DBLA_VENDOR=Generic + + - name: Test with pytest + run: pytest control/tests From 5bb9de40c6ee8443045dd4a42ae8fd9e266cff0f Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Mon, 11 Jan 2021 19:33:01 -0800 Subject: [PATCH 7/9] update xvfb configuration; remove X11 marks --- .github/workflows/control-slycot-src.yml | 7 +++++-- .github/workflows/python-package-conda.yml | 8 +++++--- control/tests/conftest.py | 3 +-- control/tests/rlocus_test.py | 3 --- control/tests/sisotool_test.py | 2 -- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/control-slycot-src.yml b/.github/workflows/control-slycot-src.yml index e4455ed4a..41d56bf4a 100644 --- a/.github/workflows/control-slycot-src.yml +++ b/.github/workflows/control-slycot-src.yml @@ -15,8 +15,11 @@ jobs: # Set up conda echo $CONDA/bin >> $GITHUB_PATH + # Set up (virtual) X11 + sudo apt install -y xvfb + # Install test tools - conda install pip pytest + conda install pip pytest # Install python-control dependencies conda install numpy matplotlib scipy @@ -33,4 +36,4 @@ jobs: cd slycot; python setup.py build_ext install -DBLA_VENDOR=Generic - name: Test with pytest - run: pytest control/tests + run: xvfb-run --auto-servernum pytest control/tests diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 9a3157a8a..b8a212b6f 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -23,15 +23,15 @@ jobs: run: | # Set up conda echo $CONDA/bin >> $GITHUB_PATH - conda create -q -n test-environment python=${{matrix.python-version}} + conda create -q -n test-environment python=${{matrix.python-version}} source $CONDA/bin/activate test-environment # Set up (virtual) X11 sudo apt install -y xvfb # Install test tools - conda install pip coverage pytest - conda install -c conda-forge pytest-xvfb pytest-cov + conda install pip coverage pytest + conda install -c conda-forge pytest-cov # Install python-control dependencies conda install numpy matplotlib scipy @@ -43,4 +43,6 @@ jobs: PYTHON_CONTROL_ARRAY_AND_MATRIX: ${{ matrix.array-and-matrix }} run: | source $CONDA/bin/activate test-environment + # Use xvfb-run instead of pytest-xvfb to get proper mpl backend + # See https://github.com/python-control/python-control/pull/504 xvfb-run --auto-servernum pytest control/tests diff --git a/control/tests/conftest.py b/control/tests/conftest.py index b7fac8fe5..b67ef3674 100644 --- a/control/tests/conftest.py +++ b/control/tests/conftest.py @@ -26,8 +26,7 @@ "PendingDeprecationWarning") matrixerrorfilter = pytest.mark.filterwarnings("error:.*matrix subclass:" "PendingDeprecationWarning") -X11only = pytest.mark.skipif(os.getenv("DISPLAY") is None, - reason="requires X11") + @pytest.fixture(scope="session", autouse=True) def control_defaults(): diff --git a/control/tests/rlocus_test.py b/control/tests/rlocus_test.py index 47df12d2b..cf2b72cd3 100644 --- a/control/tests/rlocus_test.py +++ b/control/tests/rlocus_test.py @@ -13,8 +13,6 @@ from control.statesp import StateSpace from control.bdalg import feedback -from control.tests.conftest import X11only - class TestRootLocus: """These are tests for the feedback function in rlocus.py.""" @@ -50,7 +48,6 @@ def test_without_gains(self, sys): roots, kvect = root_locus(sys, plot=False) self.check_cl_poles(sys, roots, kvect) - @X11only def test_root_locus_zoom(self): """Check the zooming functionality of the Root locus plot""" system = TransferFunction([1000], [1, 25, 100, 0]) diff --git a/control/tests/sisotool_test.py b/control/tests/sisotool_test.py index c584413ab..65f87f28b 100644 --- a/control/tests/sisotool_test.py +++ b/control/tests/sisotool_test.py @@ -9,7 +9,6 @@ from control.rlocus import _RLClickDispatcher from control.xferfcn import TransferFunction -from control.tests.conftest import X11only @pytest.mark.usefixtures("mplcleanup") class TestSisotool: @@ -20,7 +19,6 @@ def sys(self): """Return a generic SISO transfer function""" return TransferFunction([1000], [1, 25, 100, 0]) - @X11only def test_sisotool(self, sys): sisotool(sys, Hz=False) fig = plt.gcf() From 36ecea1a94961e4d2c6e8c1fbb9fc119c91360ed Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Mon, 11 Jan 2021 19:33:01 -0800 Subject: [PATCH 8/9] update xvfb configuration; remove X11 marks --- .github/workflows/control-slycot-src.yml | 7 +++++-- .github/workflows/python-package-conda.yml | 8 +++++--- control/tests/conftest.py | 3 +-- control/tests/rlocus_test.py | 3 --- control/tests/sisotool_test.py | 2 -- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/.github/workflows/control-slycot-src.yml b/.github/workflows/control-slycot-src.yml index e4455ed4a..41d56bf4a 100644 --- a/.github/workflows/control-slycot-src.yml +++ b/.github/workflows/control-slycot-src.yml @@ -15,8 +15,11 @@ jobs: # Set up conda echo $CONDA/bin >> $GITHUB_PATH + # Set up (virtual) X11 + sudo apt install -y xvfb + # Install test tools - conda install pip pytest + conda install pip pytest # Install python-control dependencies conda install numpy matplotlib scipy @@ -33,4 +36,4 @@ jobs: cd slycot; python setup.py build_ext install -DBLA_VENDOR=Generic - name: Test with pytest - run: pytest control/tests + run: xvfb-run --auto-servernum pytest control/tests diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 9a3157a8a..b8a212b6f 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -23,15 +23,15 @@ jobs: run: | # Set up conda echo $CONDA/bin >> $GITHUB_PATH - conda create -q -n test-environment python=${{matrix.python-version}} + conda create -q -n test-environment python=${{matrix.python-version}} source $CONDA/bin/activate test-environment # Set up (virtual) X11 sudo apt install -y xvfb # Install test tools - conda install pip coverage pytest - conda install -c conda-forge pytest-xvfb pytest-cov + conda install pip coverage pytest + conda install -c conda-forge pytest-cov # Install python-control dependencies conda install numpy matplotlib scipy @@ -43,4 +43,6 @@ jobs: PYTHON_CONTROL_ARRAY_AND_MATRIX: ${{ matrix.array-and-matrix }} run: | source $CONDA/bin/activate test-environment + # Use xvfb-run instead of pytest-xvfb to get proper mpl backend + # See https://github.com/python-control/python-control/pull/504 xvfb-run --auto-servernum pytest control/tests diff --git a/control/tests/conftest.py b/control/tests/conftest.py index b7fac8fe5..b67ef3674 100644 --- a/control/tests/conftest.py +++ b/control/tests/conftest.py @@ -26,8 +26,7 @@ "PendingDeprecationWarning") matrixerrorfilter = pytest.mark.filterwarnings("error:.*matrix subclass:" "PendingDeprecationWarning") -X11only = pytest.mark.skipif(os.getenv("DISPLAY") is None, - reason="requires X11") + @pytest.fixture(scope="session", autouse=True) def control_defaults(): diff --git a/control/tests/rlocus_test.py b/control/tests/rlocus_test.py index 47df12d2b..cf2b72cd3 100644 --- a/control/tests/rlocus_test.py +++ b/control/tests/rlocus_test.py @@ -13,8 +13,6 @@ from control.statesp import StateSpace from control.bdalg import feedback -from control.tests.conftest import X11only - class TestRootLocus: """These are tests for the feedback function in rlocus.py.""" @@ -50,7 +48,6 @@ def test_without_gains(self, sys): roots, kvect = root_locus(sys, plot=False) self.check_cl_poles(sys, roots, kvect) - @X11only def test_root_locus_zoom(self): """Check the zooming functionality of the Root locus plot""" system = TransferFunction([1000], [1, 25, 100, 0]) diff --git a/control/tests/sisotool_test.py b/control/tests/sisotool_test.py index c584413ab..65f87f28b 100644 --- a/control/tests/sisotool_test.py +++ b/control/tests/sisotool_test.py @@ -9,7 +9,6 @@ from control.rlocus import _RLClickDispatcher from control.xferfcn import TransferFunction -from control.tests.conftest import X11only @pytest.mark.usefixtures("mplcleanup") class TestSisotool: @@ -20,7 +19,6 @@ def sys(self): """Return a generic SISO transfer function""" return TransferFunction([1000], [1, 25, 100, 0]) - @X11only def test_sisotool(self, sys): sisotool(sys, Hz=False) fig = plt.gcf() From b7b696faee8339840c37d9eaa67e842ef3ecddaf Mon Sep 17 00:00:00 2001 From: Richard Murray Date: Mon, 11 Jan 2021 21:50:04 -0800 Subject: [PATCH 9/9] add coveralls --- .coveragerc | 1 + .github/workflows/python-package-conda.yml | 25 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.coveragerc b/.coveragerc index 1a7311855..971e393ef 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,6 +1,7 @@ [run] source = control omit = control/tests/* +relative_files = True [report] exclude_lines = diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index b8a212b6f..a3388af79 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -3,7 +3,7 @@ name: Conda-based pytest on: [push, pull_request] jobs: - build-linux: + test-linux: runs-on: ubuntu-latest strategy: @@ -19,6 +19,7 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Install dependencies run: | # Set up conda @@ -31,18 +32,36 @@ jobs: # Install test tools conda install pip coverage pytest - conda install -c conda-forge pytest-cov + pip install coveralls # Install python-control dependencies conda install numpy matplotlib scipy if [[ '${{matrix.slycot}}' == 'conda' ]]; then conda install -c conda-forge slycot fi + - name: Test with pytest env: PYTHON_CONTROL_ARRAY_AND_MATRIX: ${{ matrix.array-and-matrix }} run: | source $CONDA/bin/activate test-environment # Use xvfb-run instead of pytest-xvfb to get proper mpl backend + # Use coverage instead of pytest-cov to get .coverage file # See https://github.com/python-control/python-control/pull/504 - xvfb-run --auto-servernum pytest control/tests + xvfb-run --auto-servernum coverage run -m pytest control/tests + + - name: Coveralls parallel + # https://github.com/coverallsapp/github-action + uses: AndreMiras/coveralls-python-action@develop + with: + parallel: true + + coveralls: + name: coveralls completion + needs: test-linux + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: AndreMiras/coveralls-python-action@develop + with: + parallel-finished: true