|
| 1 | +name: Test qlib from source |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + timeout-minutes: 180 |
| 12 | + # we may retry for 3 times for `Unit tests with Pytest` |
| 13 | + |
| 14 | + runs-on: ${{ matrix.os }} |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + os: [windows-latest, ubuntu-24.04, ubuntu-22.04, macos-14, macos-15] |
| 18 | + # In github action, using python 3.7, pip install will not match the latest version of the package. |
| 19 | + # Also, python 3.7 is no longer supported from macos-14, and will be phased out from macos-13 in the near future. |
| 20 | + # All things considered, we have removed python 3.7. |
| 21 | + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Test qlib from source |
| 25 | + uses: actions/checkout@v3 |
| 26 | + |
| 27 | + - name: Set up Python ${{ matrix.python-version }} |
| 28 | + uses: actions/setup-python@v4 |
| 29 | + with: |
| 30 | + python-version: ${{ matrix.python-version }} |
| 31 | + |
| 32 | + - name: Update pip to the latest version |
| 33 | + run: | |
| 34 | + python -m pip install --upgrade pip |
| 35 | +
|
| 36 | + - name: Installing pytorch for macos |
| 37 | + if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }} |
| 38 | + run: | |
| 39 | + python -m pip install torch torchvision torchaudio |
| 40 | +
|
| 41 | + - name: Installing pytorch for ubuntu |
| 42 | + if: ${{ matrix.os == 'ubuntu-24.04' || matrix.os == 'ubuntu-22.04' }} |
| 43 | + run: | |
| 44 | + python -m pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cpu |
| 45 | +
|
| 46 | + - name: Installing pytorch for windows |
| 47 | + if: ${{ matrix.os == 'windows-latest' }} |
| 48 | + run: | |
| 49 | + python -m pip install torch torchvision torchaudio |
| 50 | +
|
| 51 | + - name: Set up Python tools |
| 52 | + run: | |
| 53 | + make dev |
| 54 | +
|
| 55 | + - name: Lint with Black |
| 56 | + run: | |
| 57 | + make black |
| 58 | +
|
| 59 | + - name: Make html with sphinx |
| 60 | + # Since read the docs builds on ubuntu 22.04, we only need to test that the build passes on ubuntu 22.04. |
| 61 | + if: ${{ matrix.os == 'ubuntu-22.04' }} |
| 62 | + run: | |
| 63 | + make docs-gen |
| 64 | +
|
| 65 | + - name: Check Qlib with pylint |
| 66 | + run: | |
| 67 | + make pylint |
| 68 | +
|
| 69 | + - name: Check Qlib with flake8 |
| 70 | + run: | |
| 71 | + make flake8 |
| 72 | +
|
| 73 | + - name: Check Qlib with mypy |
| 74 | + run: | |
| 75 | + make mypy |
| 76 | + |
| 77 | + - name: Check Qlib ipynb with nbqa |
| 78 | + run: | |
| 79 | + make nbqa |
| 80 | +
|
| 81 | + - name: Test data downloads |
| 82 | + run: | |
| 83 | + python scripts/get_data.py qlib_data --name qlib_data_simple --target_dir ~/.qlib/qlib_data/cn_data --interval 1d --region cn |
| 84 | + python scripts/get_data.py download_data --file_name rl_data.zip --target_dir tests/.data/rl |
| 85 | +
|
| 86 | + - name: Install Lightgbm for MacOS |
| 87 | + if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }} |
| 88 | + run: | |
| 89 | + brew update |
| 90 | + brew install libomp || brew reinstall libomp |
| 91 | + python -m pip install --no-binary=:all: lightgbm |
| 92 | +
|
| 93 | + - name: Check Qlib ipynb with nbconvert |
| 94 | + run: | |
| 95 | + make nbconvert |
| 96 | +
|
| 97 | + - name: Test workflow by config (install from source) |
| 98 | + run: | |
| 99 | + python -m pip install numba |
| 100 | + python qlib/cli/run.py examples/benchmarks/LightGBM/workflow_config_lightgbm_Alpha158.yaml |
| 101 | +
|
| 102 | + - name: Unit tests with Pytest (MacOS) |
| 103 | + if: ${{ matrix.os == 'macos-14' || matrix.os == 'macos-15' }} |
| 104 | + uses: nick-fields/retry@v2 |
| 105 | + with: |
| 106 | + timeout_minutes: 60 |
| 107 | + max_attempts: 3 |
| 108 | + command: | |
| 109 | + # Limit the number of threads in various libraries to prevent Segmentation faults caused by OpenMP multithreading conflicts under macOS. |
| 110 | + export OMP_NUM_THREADS=1 # Limit the number of OpenMP threads |
| 111 | + export MKL_NUM_THREADS=1 # Limit the number of Intel MKL threads |
| 112 | + export NUMEXPR_NUM_THREADS=1 # Limit the number of NumExpr threads |
| 113 | + export OPENBLAS_NUM_THREADS=1 # Limit the number of OpenBLAS threads |
| 114 | + export VECLIB_MAXIMUM_THREADS=1 # Limit the number of macOS Accelerate/vecLib threads |
| 115 | + cd tests |
| 116 | + python -m pytest . -m "not slow" --durations=0 |
| 117 | +
|
| 118 | + - name: Unit tests with Pytest (Ubuntu and Windows) |
| 119 | + if: ${{ matrix.os != 'macos-13' && matrix.os != 'macos-14' && matrix.os != 'macos-15' }} |
| 120 | + uses: nick-fields/retry@v2 |
| 121 | + with: |
| 122 | + timeout_minutes: 60 |
| 123 | + max_attempts: 3 |
| 124 | + command: | |
| 125 | + cd tests |
| 126 | + python -m pytest . -m "not slow" --durations=0 |
0 commit comments