Add GitHub Actions workflow for Python package#154
Add GitHub Actions workflow for Python package#154AKB0700 wants to merge 2 commits intoDeepLcom:mainfrom
Conversation
This workflow installs Python dependencies, runs tests, and lints code with multiple Python versions.
There was a problem hiding this comment.
Pull request overview
Adds a new GitHub Actions workflow intended to run linting and tests for the Python package across multiple Python versions on pushes and pull requests to main.
Changes:
- Introduces
.github/workflows/python-package.ymlwith a Python version matrix (3.9–3.11). - Adds steps to install dependencies, run
flake8, and runpytest.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
There was a problem hiding this comment.
Lint command runs flake8 ., which will lint everything in the repo (including examples/, docs, etc.) and may diverge from existing CI behavior. The established workflow (.github/workflows/run_ci.yml) runs poetry run flake8 deepl tests; consider matching that scope here to avoid unexpected failures/noise.
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| flake8 deepl tests --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
| flake8 deepl tests --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics |
| push: | ||
| branches: [ "main" ] | ||
| pull_request: | ||
| branches: [ "main" ] |
There was a problem hiding this comment.
This workflow triggers on the same events/branches as the existing .github/workflows/run_ci.yml workflow, so it will run in parallel and potentially duplicate work/CI time. Consider consolidating these checks into the existing workflow (e.g., add a pytest job there) or adjust triggers/job naming so responsibilities are clearly separated.
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| workflow_dispatch: |
| - uses: actions/checkout@v4 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install flake8 pytest | ||
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
| - name: Lint with flake8 | ||
| run: | | ||
| # stop the build if there are Python syntax errors or undefined names | ||
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
| - name: Test with pytest | ||
| run: | | ||
| pytest |
There was a problem hiding this comment.
steps: list items are not indented under steps: (the - uses: lines are at the same indentation level). This makes the workflow YAML invalid and GitHub Actions will fail to parse it. Indent the step entries so they are children of steps:.
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v3 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install flake8 pytest | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| - name: Lint with flake8 | |
| run: | | |
| # stop the build if there are Python syntax errors or undefined names | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Test with pytest | |
| run: | | |
| pytest | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v3 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install flake8 pytest | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| - name: Lint with flake8 | |
| run: | | |
| # stop the build if there are Python syntax errors or undefined names | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Test with pytest | |
| run: | | |
| pytest |
| python -m pip install flake8 pytest | ||
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi |
There was a problem hiding this comment.
Dependency installation is effectively a no-op for this repo: it only installs flake8/pytest and then conditionally installs requirements.txt, but this repository uses pyproject.toml/poetry.lock (and has no requirements.txt). As a result, imports like requests won’t be installed and the pytest step is likely to fail. Consider installing via Poetry (consistent with .github/workflows/run_ci.yml) or otherwise installing the package + locked dependencies before lint/test.
| python -m pip install flake8 pytest | |
| if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
| python -m pip install poetry | |
| poetry config virtualenvs.create false | |
| poetry install --no-interaction --no-root | |
| python -m pip install flake8 pytest |
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python ${{ matrix.python-version }} | ||
| uses: actions/setup-python@v3 |
There was a problem hiding this comment.
This uses actions/setup-python@v3, which is quite old and may rely on deprecated Node runtimes in GitHub Actions. Update to a currently supported major version (e.g., @v5) to avoid workflow breakage as GitHub deprecates older Node versions.
| uses: actions/setup-python@v3 | |
| uses: actions/setup-python@v5 |
This workflow installs Python dependencies, runs tests, and lints code with multiple Python versions.