Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@ jobs:
coverage:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Setup Python
run: uv python install
- name: Run tests
run: |
uv run tox -e coverage
uv run tox -e report

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox

- name: Run tests
run: |
tox -e coverage
tox -e report

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
68 changes: 0 additions & 68 deletions .github/workflows/lint-commits.yml

This file was deleted.

148 changes: 25 additions & 123 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,139 +1,41 @@
name: Linting
name: Lint

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint-flake8:
name: Linting with flake8
linting:
name: Linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Lint with flake8
run: |
flake8 --version # Verify flake8 is picking up flake8-bugbear
flake8 --max-line-length=120 . --exclude env,configuration,venv,src,scripts,.venv,e2e

lint-black:
name: Linting with black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
enable-cache: true
cache-dependency-glob: "uv.lock"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the caching parameter name

In the Install uv step, the parameter cache-dependency-glob may be incorrect. According to the astral-sh/setup-uv@v2 documentation, the correct parameter is cache-dependency-path. Please update the parameter name to ensure caching works as intended.

Apply this diff to correct the parameter name:

- cache-dependency-glob: "uv.lock"
+ cache-dependency-path: "uv.lock"

Also applies to: 35-35

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Lint with black
run: black flask_utils -l119 --check

lint-imports-order:
name: Checking imports order
run: uv python install
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the uv command for installing dependencies

The command uv python install may not be the correct way to install dependencies using uv. The standard command to install dependencies specified in pyproject.toml or uv.lock is uv install. Please update the command to ensure dependencies are installed properly.

Apply this diff to correct the command:

- run: uv python install
+ run: uv install

Also applies to: 37-37

- name: Run Ruff
run: uv run ruff check --output-format=github .
type-checking:
Comment on lines +17 to +26
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor to eliminate duplication in job steps

The steps for installing uv and setting up Python are repeated in both the linting and type-checking jobs. To adhere to the DRY (Don't Repeat Yourself) principle, consider extracting these common steps into a reusable action or a separate job that can be referenced by both jobs. This can simplify maintenance and improve readability.

Also applies to: 31-41

name: Type Checking
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- uses: actions/cache@v4
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Lint with reorder-python-imports
run: reorder-python-imports flask_utils/**/*.py tests/*.py

lint-typing:
name: Checking Typing with MyPy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install types-flask
- name: Lint with mypy
run: mypy flask_utils

lint-sphinx:
name: Checking documentation with Sphinx
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Lint with sphinx
run: sphinx-lint -i .venv -i .tox
run: uv python install
- name: Run mypy
# Using strict mode.
# Waiting for https://github.com/python/mypy/pull/17771
run: uv run mypy --strict flask_utils
18 changes: 9 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
python-version: '3.11'
- name: Install dependencies
run: |
python3.11 -m pip install --upgrade pip
python3.11 -m pip install --upgrade setuptools wheel twine build
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Setup Python
run: uv python install
- name: Create Github Release
id: create_release
uses: softprops/action-gh-release@v2
Expand All @@ -28,8 +27,9 @@ jobs:
generate_release_notes: true
- name: Build and publish on private PyPI
run: |
python3.11 -m build
# twine upload dist/*
uv build
# TODO: Uncomment when flask-utils had been freed from pypi
# uvx twine upload dist/*
- name: Upload .whl artifact to GitHub release
uses: actions/upload-release-asset@v1
env:
Expand Down
19 changes: 9 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
python-version: ${{ matrix.python-version }}
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- name: Setup Python
run: uv python install ${{ matrix.python-version }}

- name: Run tests
run: |
PYTHON_VERSION=${{ matrix.python-version }}
TOX_ENV=`tox --listenvs | grep "py${PYTHON_VERSION//./}-" | tr '\n' ','`
tox -e $TOX_ENV
export PYTHON_VERSION=${{ matrix.python-version }}
export TOX_ENV=`uv run tox --listenvs | grep "py${PYTHON_VERSION//./}-" | tr '\n' ','`
uv run tox -e $TOX_ENV
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Just a few suggestions to improve the script.

Exporting the PYTHON_VERSION environment variable based on the matrix value and using uv run tox --listenvs command to list the available environments and filter the output to get the environment name for the current Python version is a clever approach. It ensures that the correct environment is used for running the tests.

Running the tests using uv run tox -e $TOX_ENV command leverages the uv tool for managing the test environment and ensures that the tests are run in an isolated environment.

However, the static analysis tools have reported a few potential issues with the shell script:

  1. SC2155: Declare and assign separately to avoid masking return values
  2. SC2006: Use $(...) notation instead of legacy backticks ...
  3. SC2086: Double quote to prevent globbing and word splitting

To address these issues, please apply the following changes:

-        export TOX_ENV=`uv run tox --listenvs | grep "py${PYTHON_VERSION//./}-" | tr '\n' ','`
+        TOX_ENV=$(uv run tox --listenvs | grep "py${PYTHON_VERSION//./}-" | tr '\n' ',')
+        export TOX_ENV
-        uv run tox -e $TOX_ENV
+        uv run tox -e "$TOX_ENV"

These changes will:

  1. Declare and assign the TOX_ENV variable separately to avoid masking return values
  2. Use $(...) notation instead of legacy backticks ...
  3. Double quote the $TOX_ENV variable to prevent globbing and word splitting

Let me know if you have any questions or need further assistance with these changes.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export PYTHON_VERSION=${{ matrix.python-version }}
export TOX_ENV=`uv run tox --listenvs | grep "py${PYTHON_VERSION//./}-" | tr '\n' ','`
uv run tox -e $TOX_ENV
export PYTHON_VERSION=${{ matrix.python-version }}
TOX_ENV=$(uv run tox --listenvs | grep "py${PYTHON_VERSION//./}-" | tr '\n' ',')
export TOX_ENV
uv run tox -e "$TOX_ENV"

12 changes: 7 additions & 5 deletions .github/workflows/version-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
python-version: '3.11'
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Setup Python
run: uv python install
- name: Check version
run: |
pip install packaging
python scripts/check_version.py
uv run -- python scripts/check_version.py
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ target/
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
Expand Down
Loading