From dd50f3487e4db03b611722de5928466e3e51c6f8 Mon Sep 17 00:00:00 2001 From: Rui Vieira Date: Tue, 21 Mar 2023 11:34:40 +0000 Subject: [PATCH 1/7] Add ODH notebook image dependencies test to CI --- pyproject.toml | 3 +- requirements-dev.txt | 17 +++++++++++ requirements.txt | 9 +++--- tests/general/test_dependencies.py | 45 ++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 requirements-dev.txt create mode 100644 tests/general/test_dependencies.py diff --git a/pyproject.toml b/pyproject.toml index 5b14575..3f4ed99 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,8 @@ dev = [ "setuptools", "twine==3.4.2", "wheel~=0.38.4", - "xgboost==1.4.2" + "xgboost==1.4.2", + "dparse==0.6.2" ] [project.urls] diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..9f539ed --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,17 @@ +JPype1==1.4.1 +black~=22.12.0 +click==8.0.4 +joblib~=1.2.0 +jupyterlab~=3.5.3 +numpydoc==1.5.0 +pyarrow==7.0.0 +pylint==2.15.6 +pytest~=7.2.1 +pytest-benchmark==4.0.0 +pytest-forked~=1.6.0 +scikit-learn~=1.2.1 +setuptools +twine==3.4.2 +wheel~=0.38.4 +xgboost==1.4.2 +dparse==0.6.2 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 80eedf6..d3415e3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ -JPype1==1.4.1 -matplotlib==3.5.1 -pandas==1.2.5 +Jpype1==1.4.1 pyarrow==7.0.0 -bokeh==2.4.3 \ No newline at end of file +matplotlib~=3.6.3 +pandas~=1.5.3 +numpy~=1.24.1 +jupyter-bokeh~=3.0.5 \ No newline at end of file diff --git a/tests/general/test_dependencies.py b/tests/general/test_dependencies.py new file mode 100644 index 0000000..4e43a83 --- /dev/null +++ b/tests/general/test_dependencies.py @@ -0,0 +1,45 @@ +import urllib.request +from dparse import parse, filetypes + +VERSION = "datascience/ubi9-python-3.9" + +def test_dependencies(): + '''Tests whether TrustyAI's dependencies are compatible with ODH workbench-image's https://github.com/opendatahub-io/notebooks/tree/main/jupyter/datascience/ubi9-python-3.9''' + # download the pipfile + urllib.request.urlretrieve( + f"https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/{VERSION}/Pipfile", + "/tmp/Pipfile") + + with open('./requirements.txt', 'r') as file: + reqtxt = parse(file.read(), file_type=filetypes.requirements_txt) + + with open('./requirements-dev.txt', 'r') as file: + reqdevtxt = parse(file.read(), file_type=filetypes.requirements_txt) + + with open('/tmp/Pipfile', 'r') as file: + pipfile = parse(file.read(), file_type=filetypes.pipfile) + + reqtxt_names = {dependency.name: dependency for dependency in reqtxt.dependencies} + reqdevtxt_names = {dependency.name: dependency for dependency in reqdevtxt.dependencies} + + mismatched_specs = [] + + for dependency in pipfile.dependencies: + if dependency.name in reqtxt_names.keys(): + print(f"{dependency} found") + trusty_specs = reqtxt_names[dependency.name].specs + if dependency.specs == trusty_specs: + print(f"\tSpecs match ({dependency.specs})") + else: + print(f"\tSpecs do not match ({dependency.specs} ODH vs. {reqtxt_names[dependency.name].specs} TrustyAI)") + mismatched_specs.append(dependency) + if dependency.name in reqdevtxt_names.keys(): + print(f"{dependency} found") + trusty_specs = reqdevtxt_names[dependency.name].specs + if dependency.specs == trusty_specs: + print(f"\tSpecs match ({dependency.specs})") + else: + print(f"\tSpecs do not match ({dependency.specs} ODH vs. {reqtxt_names[dependency.name].specs} TrustyAI)") + mismatched_specs.append(dependency) + + assert len(mismatched_specs) == 0 \ No newline at end of file From 343cb69a9a0a6f8d1c6a17c297173d521316452a Mon Sep 17 00:00:00 2001 From: Rui Vieira Date: Wed, 22 Mar 2023 09:40:17 +0000 Subject: [PATCH 2/7] Add Pipfile parameter for ODH dependency check --- .github/actions/dependencies/action.yml | 16 +++++++++++++++ .github/workflows/workflow.yml | 20 ++++++++++++++++++- .../test_odh_dependencies.py} | 19 ++++++++++-------- 3 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 .github/actions/dependencies/action.yml rename tests/{general/test_dependencies.py => dependencies/test_odh_dependencies.py} (71%) diff --git a/.github/actions/dependencies/action.yml b/.github/actions/dependencies/action.yml new file mode 100644 index 0000000..ba5ac9f --- /dev/null +++ b/.github/actions/dependencies/action.yml @@ -0,0 +1,16 @@ +name: Test dependencies match +description: Test if TrustyAI dependencies match ODH workbench images +inputs: + pipfile: + description: 'Location of the reference Pipfile' + required: false + default: 'https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile' +runs: + using: "composite" + steps: + - name: Test against ODH dependencies + shell: bash + env: + INPUT_PIPFILE: ${{ inputs.pipfile }} + run: | + pytest -v -s tests/dependencies/test_odh_dependencies.py diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index c238517..3e2e7da 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,6 +1,14 @@ name: Tests -on: [ push, pull_request ] +on: + push: + pull_request: + workflow_dispatch: + inputs: + pipfile: + description: 'Location of Pipfile to validate dependencies' + required: false + default: 'https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile' jobs: build: @@ -34,6 +42,16 @@ jobs: run: | pytest -v -s tests/general pytest -v -s tests/initialization --forked + - name: Test ODH dependencies + if: "${{ github.event.inputs.pipfile != '' }}" + uses: ./.github/actions/dependencies + with: + pipfile: '${{ github.event.inputs.pipfile }}' + - name: Test ODH dependencies + if: "${{ github.event.inputs.pipfile == '' }}" + uses: ./.github/actions/dependencies + with: + pipfile: 'https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile' - name: Style run: | black --check $(find src/trustyai -type f -name "*.py") diff --git a/tests/general/test_dependencies.py b/tests/dependencies/test_odh_dependencies.py similarity index 71% rename from tests/general/test_dependencies.py rename to tests/dependencies/test_odh_dependencies.py index 4e43a83..0ce6cd8 100644 --- a/tests/general/test_dependencies.py +++ b/tests/dependencies/test_odh_dependencies.py @@ -1,14 +1,15 @@ +import os import urllib.request from dparse import parse, filetypes -VERSION = "datascience/ubi9-python-3.9" +DEFAULT_PIPFILE = "https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile" +INPUT_PIPFILE = os.getenv("INPUT_PIPFILE", DEFAULT_PIPFILE) -def test_dependencies(): + +def test_odh_dependencies(): '''Tests whether TrustyAI's dependencies are compatible with ODH workbench-image's https://github.com/opendatahub-io/notebooks/tree/main/jupyter/datascience/ubi9-python-3.9''' # download the pipfile - urllib.request.urlretrieve( - f"https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/{VERSION}/Pipfile", - "/tmp/Pipfile") + urllib.request.urlretrieve(INPUT_PIPFILE, "/tmp/Pipfile") with open('./requirements.txt', 'r') as file: reqtxt = parse(file.read(), file_type=filetypes.requirements_txt) @@ -31,7 +32,8 @@ def test_dependencies(): if dependency.specs == trusty_specs: print(f"\tSpecs match ({dependency.specs})") else: - print(f"\tSpecs do not match ({dependency.specs} ODH vs. {reqtxt_names[dependency.name].specs} TrustyAI)") + print( + f"\tSpecs do not match ({dependency.specs} ODH vs. {reqtxt_names[dependency.name].specs} TrustyAI)") mismatched_specs.append(dependency) if dependency.name in reqdevtxt_names.keys(): print(f"{dependency} found") @@ -39,7 +41,8 @@ def test_dependencies(): if dependency.specs == trusty_specs: print(f"\tSpecs match ({dependency.specs})") else: - print(f"\tSpecs do not match ({dependency.specs} ODH vs. {reqtxt_names[dependency.name].specs} TrustyAI)") + print( + f"\tSpecs do not match ({dependency.specs} ODH vs. {reqtxt_names[dependency.name].specs} TrustyAI)") mismatched_specs.append(dependency) - assert len(mismatched_specs) == 0 \ No newline at end of file + assert len(mismatched_specs) == 0 From 91ae9a37ec9b5a0def20491aa3d85ce76093ff78 Mon Sep 17 00:00:00 2001 From: Rui Vieira Date: Wed, 22 Mar 2023 13:24:35 +0000 Subject: [PATCH 3/7] Replace workflow_dispatch with env variable --- .github/actions/dependencies/action.yml | 3 +-- .github/workflows/workflow.yml | 18 ++---------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/.github/actions/dependencies/action.yml b/.github/actions/dependencies/action.yml index ba5ac9f..304904a 100644 --- a/.github/actions/dependencies/action.yml +++ b/.github/actions/dependencies/action.yml @@ -3,8 +3,7 @@ description: Test if TrustyAI dependencies match ODH workbench images inputs: pipfile: description: 'Location of the reference Pipfile' - required: false - default: 'https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile' + required: true runs: using: "composite" steps: diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 3e2e7da..9b19e25 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,14 +1,6 @@ name: Tests -on: - push: - pull_request: - workflow_dispatch: - inputs: - pipfile: - description: 'Location of Pipfile to validate dependencies' - required: false - default: 'https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile' +on: [ push, pull_request ] jobs: build: @@ -43,15 +35,9 @@ jobs: pytest -v -s tests/general pytest -v -s tests/initialization --forked - name: Test ODH dependencies - if: "${{ github.event.inputs.pipfile != '' }}" uses: ./.github/actions/dependencies with: - pipfile: '${{ github.event.inputs.pipfile }}' - - name: Test ODH dependencies - if: "${{ github.event.inputs.pipfile == '' }}" - uses: ./.github/actions/dependencies - with: - pipfile: 'https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile' + pipfile: '${{ vars.ODH_PIPFILE }}' - name: Style run: | black --check $(find src/trustyai -type f -name "*.py") From a34dca97fd743454e82bf8e8a2347251690bedcd Mon Sep 17 00:00:00 2001 From: Rui Vieira Date: Wed, 22 Mar 2023 14:20:06 +0000 Subject: [PATCH 4/7] Remove quotes --- .github/workflows/workflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9b19e25..e4fbeb1 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -37,7 +37,7 @@ jobs: - name: Test ODH dependencies uses: ./.github/actions/dependencies with: - pipfile: '${{ vars.ODH_PIPFILE }}' + pipfile: ${{ vars.ODH_PIPFILE }} - name: Style run: | black --check $(find src/trustyai -type f -name "*.py") From ba38f6988dfbcc0a5648ae3c0bfe7fb1d227cec1 Mon Sep 17 00:00:00 2001 From: Rui Vieira Date: Wed, 22 Mar 2023 16:16:57 +0000 Subject: [PATCH 5/7] Move env variable --- .github/workflows/workflow.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e4fbeb1..454a10f 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -2,6 +2,9 @@ name: Tests on: [ push, pull_request ] +env: + PIPFILE: ${{ vars.ODH_PIPFILE }} + jobs: build: runs-on: ubuntu-latest @@ -37,7 +40,7 @@ jobs: - name: Test ODH dependencies uses: ./.github/actions/dependencies with: - pipfile: ${{ vars.ODH_PIPFILE }} + pipfile: ${{ env.PIPFILE }} - name: Style run: | black --check $(find src/trustyai -type f -name "*.py") From a98b7676682827094edc066c70b54529ef73de4d Mon Sep 17 00:00:00 2001 From: Rui Vieira Date: Wed, 22 Mar 2023 17:08:25 +0000 Subject: [PATCH 6/7] Add default --- .github/workflows/workflow.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 454a10f..ebdbe44 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -2,9 +2,6 @@ name: Tests on: [ push, pull_request ] -env: - PIPFILE: ${{ vars.ODH_PIPFILE }} - jobs: build: runs-on: ubuntu-latest @@ -40,7 +37,7 @@ jobs: - name: Test ODH dependencies uses: ./.github/actions/dependencies with: - pipfile: ${{ env.PIPFILE }} + pipfile: ${{ vars.ODH_PIPFILE || "https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile" }} - name: Style run: | black --check $(find src/trustyai -type f -name "*.py") From c9c738feb457ca975844d32148f3bdf0b1d4274c Mon Sep 17 00:00:00 2001 From: Rui Vieira Date: Wed, 22 Mar 2023 17:10:48 +0000 Subject: [PATCH 7/7] Correct env scope --- .github/workflows/workflow.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index ebdbe44..e73ac88 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -2,6 +2,9 @@ name: Tests on: [ push, pull_request ] +env: + PIPFILE: ${{ vars.ODH_PIPFILE || 'https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile' }} + jobs: build: runs-on: ubuntu-latest @@ -37,7 +40,7 @@ jobs: - name: Test ODH dependencies uses: ./.github/actions/dependencies with: - pipfile: ${{ vars.ODH_PIPFILE || "https://raw.githubusercontent.com/opendatahub-io/notebooks/main/jupyter/datascience/ubi9-python-3.9/Pipfile" }} + pipfile: ${{ env.PIPFILE }} - name: Style run: | black --check $(find src/trustyai -type f -name "*.py")