update #12
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
| name: Python package | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: ['3.9', '3.10', '3.11'] | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Cache pip packages | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.cache/pip | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y python3-venv | |
| - name: Install Poetry | |
| run: | | |
| # Install specific version of Poetry directly | |
| pip install "poetry==1.5.1" | |
| echo "$(python -m site --user-base)/bin" >> $GITHUB_PATH | |
| - name: Configure Poetry | |
| run: | | |
| echo "=== Configuring Poetry ===" | |
| echo "Python executable: $(which python)" | |
| echo "Python version: $(python --version)" | |
| echo "Poetry version: $(poetry --version || echo 'Not available')" | |
| # Verify Python environment | |
| echo "\n=== Python Environment ===" | |
| python -c "import sys; print('\n'.join(f'{k}: {v}' for k, v in { | |
| 'Executable': sys.executable, | |
| 'Version': sys.version, | |
| 'Prefix': sys.prefix, | |
| 'Base Prefix': sys.base_prefix, | |
| 'Exec Prefix': sys.exec_prefix, | |
| 'Path': '\n ' + '\n '.join(sys.path) | |
| }.items()))" | |
| # Configure Poetry with error handling | |
| echo "\n=== Configuring Poetry ===" | |
| python -m poetry config virtualenvs.create true || \ | |
| { echo "Failed to set virtualenvs.create"; exit 1; } | |
| python -m poetry config virtualenvs.in-project true || \ | |
| { echo "Failed to set virtualenvs.in-project"; exit 1; } | |
| python -m poetry config virtualenvs.path .venv || \ | |
| { echo "Failed to set virtualenvs.path"; exit 1; } | |
| # Verify configuration | |
| echo "\n=== Current Poetry Configuration ===" | |
| python -m poetry config --list || \ | |
| { echo "Failed to list Poetry configuration"; exit 1; } | |
| echo "\n=== Poetry Environment ===" | |
| python -m poetry env info || \ | |
| { echo "Failed to get Poetry environment info"; exit 1; } | |
| - name: Install dependencies | |
| run: | | |
| echo "=== Installing dependencies ===" | |
| # Check if poetry.lock exists | |
| if [ -f poetry.lock ]; then | |
| echo "Using existing poetry.lock" | |
| poetry install --no-interaction --no-ansi -v | |
| else | |
| echo "No poetry.lock found, installing without lock file" | |
| poetry install --no-interaction --no-ansi -v --no-lock | |
| fi | |
| # Verify the environment | |
| echo "\n=== Environment information ===" | |
| poetry env info | |
| echo "\n=== Installed packages ===" | |
| poetry show --tree || echo "Failed to show package tree" | |
| - name: Run tests | |
| run: | | |
| poetry run pytest tests/ -v | |
| - name: Lint with flake8 | |
| run: | | |
| poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| poetry run flake8 . --count --max-complexity=10 --max-line-length=88 --statistics |