feat: replace mypy and pytype with pyrefly for static type analysis #28943
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Jenkinsfile.monai-premerge | |
| name: premerge | |
| permissions: | |
| contents: read | |
| on: | |
| # quick tests for pull requests and the releasing branches | |
| push: | |
| branches: | |
| - dev | |
| - main | |
| - releasing/* | |
| pull_request: | |
| head_ref-ignore: | |
| - dev | |
| concurrency: | |
| # automatically cancel the previously triggered workflows when there's a newer version | |
| group: build-${{ github.event.pull_request.number || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| # caching of these jobs: | |
| # - docker-py3-pip- (shared) | |
| # - ubuntu py37 pip- | |
| # - os-latest-pip- (shared) | |
| flake8-py3: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| opt: ["codeformat", "pyrefly"] | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python ${{ env.PYTHON_VER1 || '3.10' }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VER1 || '3.10' }} | |
| cache: 'pip' | |
| - name: Install dependencies | |
| run: | | |
| find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \; | |
| python -m pip install --upgrade pip wheel | |
| python -m pip install --no-build-isolation -r requirements-dev.txt | |
| - name: Lint and type check | |
| run: | | |
| # clean up temporary files | |
| $(pwd)/runtests.sh --build --clean | |
| $(pwd)/runtests.sh --build --${{ matrix.opt }} | |
| quick-py3: # full dependencies installed tests for different OS | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| os: [windows-latest, macOS-latest, ubuntu-latest] | |
| timeout-minutes: 120 | |
| steps: | |
| - if: runner.os == 'windows' | |
| name: Config pagefile (Windows only) | |
| uses: al-cheb/configure-pagefile-action@v1.4 | |
| with: | |
| minimum-size: 8GB | |
| maximum-size: 16GB | |
| disk-root: "D:" | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python ${{ env.PYTHON_VER1 || '3.10' }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VER1 || '3.10' }} | |
| cache: 'pip' | |
| - name: Prepare pip wheel | |
| run: | | |
| which python | |
| python -m pip install --upgrade pip wheel | |
| - if: runner.os == 'windows' | |
| name: Install torch cpu from pytorch.org (Windows only) | |
| run: | | |
| python -m pip install torch==${{ env.PYTORCH_VER1 || '2.8.0' }} torchvision==${{ env.TORCHVISION_VER1 || '0.23.0' }}+cpu --index-url https://download.pytorch.org/whl/cpu | |
| shell: bash | |
| - if: runner.os == 'Linux' | |
| name: Install itk pre-release (Linux only) | |
| run: | | |
| python -m pip install --pre -U itk | |
| find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \; | |
| - name: Install the dependencies | |
| run: | | |
| python -m pip install --user --upgrade pip wheel | |
| python -m pip install torch==${{ env.PYTORCH_VER1 || '2.8.0' }} torchvision==${{ env.TORCHVISION_VER1 || '0.23.0' }} | |
| cat "requirements-dev.txt" | |
| python -m pip install --no-build-isolation -r requirements-dev.txt | |
| python -m pip list | |
| BUILD_MONAI=0 python -m pip install -e . # test no compile installation | |
| shell: bash | |
| - name: Run compiled (${{ runner.os }}) | |
| run: | | |
| python -m pip uninstall -y monai | |
| BUILD_MONAI=1 python -m pip install -e . # compile the cpp extensions | |
| shell: bash | |
| - name: Run quick tests (CPU ${{ runner.os }}) | |
| run: | | |
| python -c 'import torch; print(torch.__version__); print(torch.rand(5,3))' | |
| python -c "import monai; monai.config.print_config()" | |
| python -m unittest -v | |
| env: | |
| QUICKTEST: True | |
| PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python # https://github.com/Project-MONAI/MONAI/issues/4354 | |
| packaging: | |
| runs-on: ubuntu-latest | |
| env: | |
| QUICKTEST: True | |
| shell: bash | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python ${{ env.PYTHON_VER1 || '3.10' }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VER1 || '3.10' }} | |
| cache: 'pip' | |
| - name: Install dependencies | |
| run: | | |
| find /opt/hostedtoolcache/* -maxdepth 0 ! -name 'Python' -exec rm -rf {} \; | |
| python -m pip install --user --upgrade pip "setuptools<70" wheel twine packaging | |
| # install the latest pytorch for testing | |
| # however, "pip install monai*.tar.gz" will build cpp/cuda with an isolated | |
| # fresh torch installation according to pyproject.toml | |
| python -m pip install torch==${{ env.PYTORCH_VER1 || '2.8.0' }} torchvision --extra-index-url https://download.pytorch.org/whl/cpu | |
| - name: Check packages | |
| run: | | |
| pip uninstall monai | |
| pip list | grep -iv monai | |
| git fetch --depth=1 origin +refs/tags/*:refs/tags/* | |
| set -e | |
| # build tar.gz and wheel | |
| python setup.py check -m -s | |
| python setup.py sdist bdist_wheel | |
| python -m twine check dist/* | |
| - run: echo "pwd=$PWD" >> $GITHUB_OUTPUT | |
| id: root | |
| - run: echo "tmp_dir=$(mktemp -d)" >> $GITHUB_OUTPUT | |
| id: mktemp | |
| - name: Move packages | |
| run: | | |
| printf ${{ steps.root.outputs.pwd }} | |
| printf ${{ steps.mktemp.outputs.tmp_dir }} | |
| # move packages to a temp dir | |
| cp dist/monai* "${{ steps.mktemp.outputs.tmp_dir }}" | |
| rm -r build dist monai.egg-info | |
| cd "${{ steps.mktemp.outputs.tmp_dir }}" | |
| ls -al | |
| - name: Install wheel file | |
| working-directory: ${{ steps.mktemp.outputs.tmp_dir }} | |
| run: | | |
| # install from wheel (use --no-build-isolation to keep system setuptools with pkg_resources) | |
| python -m pip install monai*.whl --no-build-isolation | |
| python -c 'import monai; monai.config.print_config()' 2>&1 | grep -iv "unknown" | |
| python -c 'import monai; print(monai.__file__)' | |
| python -m pip uninstall -y monai | |
| rm monai*.whl | |
| - name: Install source archive | |
| working-directory: ${{ steps.mktemp.outputs.tmp_dir }} | |
| run: | | |
| # install from tar.gz (use --no-build-isolation to keep system setuptools with pkg_resources) | |
| name=$(ls *.tar.gz | head -n1) | |
| echo $name | |
| python -m pip install $name[all] --no-build-isolation | |
| python -c 'import monai; monai.config.print_config()' 2>&1 | grep -iv "unknown" | |
| python -c 'import monai; print(monai.__file__)' | |
| - name: Quick test | |
| working-directory: ${{ steps.mktemp.outputs.tmp_dir }} | |
| run: | | |
| # run min tests | |
| cp ${{ steps.root.outputs.pwd }}/requirements*.txt . | |
| cp -r ${{ steps.root.outputs.pwd }}/tests . | |
| ls -al | |
| python -m pip install --no-build-isolation -r requirements-dev.txt | |
| python -m unittest -v | |
| env: | |
| PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION: python # https://github.com/Project-MONAI/MONAI/issues/4354 | |
| build-docs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - name: Set up Python ${{ env.PYTHON_VER1 || '3.10' }} | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: ${{ env.PYTHON_VER1 || '3.10' }} | |
| cache: 'pip' | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip wheel | |
| python -m pip install -r docs/requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu | |
| - name: Make html | |
| run: | | |
| cd docs/ | |
| make clean | |
| make html 2>&1 | tee tmp_log | |
| if [[ $(grep -c "ERROR:" tmp_log) != 0 ]]; then echo "found errors"; grep "ERROR:" tmp_log; exit 1; fi | |
| sed '/WARNING.*pip/d' tmp_log > tmp_log1; mv tmp_log1 tmp_log # monai#7133 | |
| if [[ $(grep -c "WARNING:" tmp_log) != 0 ]]; then echo "found warnings"; grep "WARNING:" tmp_log; exit 1; fi | |
| shell: bash |