Skip to content

Commit

Permalink
Fix tests in CI after migrating to pyproject.toml and uv project (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle authored Feb 12, 2025
1 parent bd66f23 commit 7ebca40
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 138 deletions.
27 changes: 6 additions & 21 deletions .github/workflows/codspeed-benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,14 @@ jobs:
persist-credentials: false
fetch-depth: 0

- name: Set up Docker Buildx
if: ${{ matrix.build-docker-images }}
uses: docker/setup-buildx-action@v3
with:
driver-opts: image=moby/buildkit:v0.12.5

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

- name: UV Cache
uses: actions/cache@v4
id: cache-uv
with:
path: ~/.cache/uv
key: uvcache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements-client.txt', 'requirements.txt', 'requirements-dev.txt') }}

- name: Install packages
run: |
python -m pip install -U uv
uv pip install --upgrade --system .[dev] pytest-codspeed
uv pip uninstall --system pytest-benchmark
enable-cache: true

- name: Install the project
run: uv sync --extra dev --compile-bytecode

- name: Start server
run: |
Expand Down
91 changes: 17 additions & 74 deletions .github/workflows/python-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,26 +112,14 @@ jobs:
persist-credentials: false
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
id: setup_python
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
enable-cache: true

- name: UV Cache
# Manually cache the uv cache directory
# until setup-python supports it:
# https://github.com/actions/setup-python/issues/822
uses: actions/cache@v4
id: cache-uv
with:
path: ~/.cache/uv
key: uvcache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements-client.txt', 'requirements.txt', 'requirements-dev.txt') }}

- name: Install packages
run: |
python -m pip install -U uv
uv pip install --upgrade --system -e .[dev]
- name: Install the project
run: uv sync --extra dev --compile-bytecode

- name: Start database container
if: ${{ startsWith(matrix.database, 'postgres') }}
Expand Down Expand Up @@ -170,7 +158,7 @@ jobs:
- name: Run tests
run: |
pytest ${{ matrix.test-type.modules }} \
uv run pytest ${{ matrix.test-type.modules }} \
--numprocesses auto \
--maxprocesses 6 \
--dist worksteal \
Expand Down Expand Up @@ -218,21 +206,11 @@ jobs:
with:
driver-opts: image=moby/buildkit:v0.12.5

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
id: setup_python
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: UV Cache
# Manually cache the uv cache directory
# until setup-python supports it:
# https://github.com/actions/setup-python/issues/822
uses: actions/cache@v4
id: cache-uv
with:
path: ~/.cache/uv
key: uvcache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements-client.txt', 'requirements.txt', 'requirements-dev.txt') }}
enable-cache: true

- name: Get image tag
id: get_image_tag
Expand Down Expand Up @@ -272,10 +250,8 @@ jobs:
docker load --input /tmp/image.tar
docker run --rm prefecthq/prefect-dev:${{ steps.get_image_tag.outputs.image_tag }} prefect version
- name: Install packages
run: |
python -m pip install -U uv
uv pip install --upgrade --system -e .[dev]
- name: Install the project
run: uv sync --extra dev --compile-bytecode

- name: Start database container
if: ${{ startsWith(matrix.database, 'postgres') }}
Expand Down Expand Up @@ -322,31 +298,14 @@ jobs:
- name: Run tests
run: |
echo "Using COVERAGE_FILE=$COVERAGE_FILE"
pytest tests --ignore=tests/typesafety \
uv run pytest tests --ignore=tests/typesafety \
--numprocesses auto \
--maxprocesses 6 \
--dist worksteal \
--disable-docker-image-builds \
--only-service docker \
--durations 26 \
- name: Create and Upload failure flag
if: ${{ failure() }}
id: create_failure_flag
run: |
sanitized_name="${{ matrix.python-version }}-${{ matrix.database }}"
sanitized_name="${sanitized_name//:/-}"
echo "Failure in $sanitized_name" > "${sanitized_name}-failure.txt"
echo "artifact_name=${sanitized_name}-failure" >> $GITHUB_OUTPUT
- name: Upload failure flag
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.create_failure_flag.outputs.artifact_name }}
path: "${{ steps.create_failure_flag.outputs.artifact_name }}.txt"

- name: Check database container
# Only applicable for Postgres, but we want this to run even when tests fail
if: always()
Expand All @@ -366,28 +325,12 @@ jobs:
persist-credentials: false
fetch-depth: 0

- name: Set up Python 3.12
uses: actions/setup-python@v5
id: setup_python
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: 3.12

- name: UV Cache
# Manually cache the uv cache directory
# until setup-python supports it:
# https://github.com/actions/setup-python/issues/822
uses: actions/cache@v4
id: cache-uv
with:
path: ~/.cache/uv
key: uvcache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements-client.txt', 'requirements.txt', 'requirements-dev.txt') }}

- name: Install packages
run: |
python -m pip install -U uv
uv pip install --upgrade --system -e .[dev]
python-version: "3.12"
enable-cache: true

- name: Run tests
run: |
pytest tests/typesafety \
--disable-docker-image-builds
uv run pytest tests/typesafety --disable-docker-image-builds
45 changes: 12 additions & 33 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,14 @@ jobs:
persist-credentials: false
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
id: setup_python
with:
python-version: "3.9.18"

- name: UV Cache
# Manually cache the uv cache directory
# until setup-python supports it:
# https://github.com/actions/setup-python/issues/822
uses: actions/cache@v4
id: cache-uv
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
path: ~/.cache/uv
key: uvcache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements-client.txt', 'requirements.txt', 'requirements-dev.txt') }}
python-version: "3.9"
enable-cache: true

- name: Install packages
run: |
python -m pip install -U uv pre-commit
uv pip install --upgrade --system -e .[dev]
- name: Install the project
run: uv sync --extra dev --compile-bytecode

- name: Setup NodeJS
uses: actions/setup-node@v4
Expand All @@ -66,7 +54,7 @@ jobs:

- name: Run pre-commit
run: |
pre-commit run --show-diff-on-failure --color=always --all-files
uv run pre-commit run --show-diff-on-failure --color=always --all-files
type-checks:
name: Type Checks
Expand All @@ -82,25 +70,16 @@ jobs:
with:
python-version: "3.12"
enable-cache: true
cache-dependency-glob: "requirements**.txt"

- name: Install the project
run: uv sync --extra dev --compile-bytecode

- name: Run type completeness check
run: >-
uv tool run
--with-editable .
--with-requirements requirements-otel.txt
--with-requirements requirements-dev.txt
pyright
--ignoreexternal
--verifytypes prefect
uv run pyright --ignoreexternal --verifytypes prefect
- name: Run pyright check
run: >-
uv tool run
--with-editable .
--with-requirements requirements-otel.txt
--with-requirements requirements-dev.txt
pyright
-p pyrightconfig-ci.json
uv run pyright -p pyrightconfig-ci.json
18 changes: 8 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,19 @@ dev = [
"mkdocs-material>=9.6.4",
"mkdocstrings[python]>=0.28.0",
"mkdocs-gen-files>=0.5.0",
# Need to stay in sync with otel extra below
"opentelemetry-distro>=0.48b0,<1.0.0",
"opentelemetry-exporter-otlp>=1.27.0,<2.0.0",
"opentelemetry-instrumentation>=0.48b0,<1.0.0",
"opentelemetry-instrumentation-logging>=0.48b0,<1.0.0",
"opentelemetry-test-utils>=0.48b0,<1.0.0"
]
otel = [
"opentelemetry-distro>=0.48b0,<1.0.0",
"opentelemetry-exporter-otlp>=1.27.0,<2.0.0",
"opentelemetry-instrumentation>=0.48b0,<1.0.0",
"opentelemetry-instrumentation-logging>=0.48b0,<1.0.0",
"opentelemetry-test-utils>=0.48b0,<1.0.0"
]
# Infrastructure extras
aws = ["prefect-aws>=0.5.0"]
Expand Down Expand Up @@ -239,20 +246,12 @@ ignore_errors = true

[tool.hatch.version]
source = "vcs"
tag-pattern = "(\\d+\\.\\d+\\.\\d+(?:\\.dev\\d+)?)$"
raw-options = { git_describe_command = 'git describe --dirty --tags --long --match "[0-9]*.[0-9]*.[0-9]*"' }

[tool.hatch.build.hooks.vcs]
version-file = "src/prefect/_version.py"

[tool.vermin]
make_paths_absolute = false
backports = ["typing_extensions"]
format = "parsable"
eval_annotations = true
only_show_violations = true
targets = ["3.9-"]
exclusion_regex = "^src/prefect/_vendor/.*$|^src/prefect/utilities/compat\\.py$|^tests/workers/test_process_worker.py$|^tests/test_background_tasks.py$|^src/integrations/.*/tests/.*$"

[tool.ruff]
src = ["src"]
extend-select = ["I"]
Expand All @@ -268,7 +267,6 @@ extend-select = ["I"]
[tool.ruff.isort]
known-third-party = []


[tool.uv.sources]
prefect-aws = { path = "src/integrations/prefect-aws" }
prefect-azure = { path = "src/integrations/prefect-azure" }
Expand Down

0 comments on commit 7ebca40

Please sign in to comment.