name: lint_python
on: [pull_request, push]
jobs:
  lint_python:
    name: "Lint and code analysis"
    runs-on: ubuntu-latest
    strategy:
      fail-fast: true
      matrix:
        include:
          - os: ubuntu-latest
            python-version: "3.11"
            channel-priority: "flexible"
            envfile: ".github/environment-lint.yml"
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Cache conda
      uses: actions/cache@v4
      env:
        CACHE_NUMBER: 0
      with:
        path: ~/conda_pkgs_dir
        key: ${{ runner.os }}-${{ matrix.python-version }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles( matrix.envfile ) }}
    - name: Install conda environmnent
      uses: conda-incubator/setup-miniconda@v3
      with: 
        auto-update-conda: false
        python-version: ${{ matrix.python-version }}
        add-pip-as-python-dependency: true
        auto-activate-base: false
        activate-environment: lint
        # mamba-version: "*"
        channel-priority: ${{ matrix.channel-priority }}
        environment-file: ${{ matrix.envfile }}
        use-only-tar-bz2: false 

    - name: Conda info
      shell: bash -l {0}
      run: |
        conda info -a
        conda list

    - name: Spell check package
      shell: bash -l {0}
      run: codespell --ignore-words .codespell_ignore_list mir_eval

    - name: Security check
      shell: bash -l {0}
      run: bandit --recursive --skip B101,B110 .

    - name: Style check package
      shell: bash -l {0}
      run: python -m flake8 mir_eval
    
    - name: Format check package
      shell: bash -l {0}
      run: python -m black --check mir_eval

    - name: Format check tests
      shell: bash -l {0}
      run: python -m black --check tests

    - name: Docstring check
      shell: bash -l {0}
      run: python -m velin --check mir_eval
    
    - name: Docstring style check
      shell: bash -l {0}
      run: python -m pydocstyle mir_eval
