Skip to content

Commit

Permalink
add more test runners for newer Python versions (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
haakonvt authored May 15, 2024
1 parent e3615bb commit e30fe26
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 163 deletions.
36 changes: 36 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 'Setup Python Environment'
description: 'Set up Python and install dependencies'
inputs:
python_version:
description: 'Python version to set up'
required: false
default: "3.8"
extras:
description: 'extra deps: poetry install -E whatever'
required: false
default: ""

runs:
using: 'composite'
steps:
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
cache: 'pip'

- name: Setup cache for poetry
uses: actions/cache@v3
with:
path: |
~/.cache/pypoetry
~/.poetry
!~/.cache/pypoetry/artifacts
!~/.cache/pypoetry/repositories
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}-${{ inputs.python_version }}-${{ inputs.extras }}

- name: Install dependencies
shell: bash
run: |
pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install --no-interaction --no-ansi ${{ inputs.extras }}
74 changes: 18 additions & 56 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,38 @@ on:
pull_request:
branches: [master]

env:
PYTHON_VERSION: '3.8'

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: ./.github/actions/setup
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install required dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install -E numpy
extras: '-E numpy'
- name: Linting and static code checks
run: pre-commit run --all-files

build_docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install core dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install
- uses: ./.github/actions/setup
- name: Build docs
run: cd docs && make html SPHINXOPTS="-W --keep-going"

test_core:
build_package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install core dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install
- uses: ./.github/actions/setup
- name: Build package
run: poetry build

test_core:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup
- name: Test core
run: pytest tests/tests_unit -n8 --dist loadscope --maxfail 10 -m 'not dsl' --test-deps-only-core

Expand All @@ -66,17 +46,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ['3.8', '3.11', '3.12'] # TODO: 3.9, 3.10 (requires a lot of work for FakeCogResGen for tests)
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: ./.github/actions/setup
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install full dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install -E all
python_version: ${{ matrix.python-version }}
extras: '-E all'

- name: Test full
env:
Expand All @@ -90,21 +66,7 @@ jobs:
COGNITE_CLIENT_NAME: python-sdk-integration-tests
run: pytest tests --durations=10 --cov --cov-report xml:coverage.xml -n8 --dist loadscope --reruns 2 --maxfail 20

- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.8'
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install full dependencies
run: python3 -m pip install --upgrade pip poetry

- name: Build package
run: poetry build
72 changes: 4 additions & 68 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,14 @@ on:
push:
branches: [master]

env:
PYTHON_VERSION: '3.8'

jobs:
lint:
test_full_build_and_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: ./.github/actions/setup
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install required dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install -E numpy
- name: Linting and static code checks
run: pre-commit run --all-files

test_core:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install required dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install
- name: Test core
run: pytest tests/tests_unit -n8 --dist loadscope --maxfail 10 -m 'not dsl' --test-deps-only-core

test_full:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install full dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install -E all
extras: '-E all'

- name: Test full
env:
Expand All @@ -73,26 +26,9 @@ jobs:
COGNITE_CLIENT_NAME: python-sdk-integration-tests
run: pytest tests --durations=10 --cov --cov-report xml:coverage.xml -n8 --dist loadscope --reruns 2 --maxfail 20

- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml

build:
runs-on: ubuntu-latest
needs: [lint, test_core, test_full]
environment: CD
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install full dependencies
run: |
python3 -m pip install --upgrade pip poetry
poetry config virtualenvs.create false
poetry install -E all

- name: Build package
run: poetry build
Expand Down
11 changes: 6 additions & 5 deletions cognite/client/data_classes/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ def __post_init__(self) -> None:
if not self.allow_unknown:
self._validate()
except Exception as err:
raise ValueError(
f"Could not instantiate {type(self).__name__} due to: {err}. " + self.show_example_usage()
) from err
acl_name = "ACL" if (cls := type(self)) is UnknownAcl else cls.__name__
raise ValueError(f"Could not instantiate {acl_name} due to: {err}. " + self.show_example_usage()) from err

def _validate(self) -> None:
if (capability_cls := type(self)) is UnknownAcl:
Expand Down Expand Up @@ -104,11 +103,13 @@ def load(cls, action: str, allow_unknown: bool = False) -> Self:
# Pythonistas, don't judge me, _missing_ does an isinstance check...
try:
return cls(action)
except ValueError:
except (ValueError, TypeError):
if allow_unknown:
Action = enum.Enum("Action", {action.title(): action}, type=Capability.Action) # type: ignore [misc]
return Action(action) # type: ignore [return-value]
raise

# Note: Doesn't enum raise this for us?! Not as of >=3.11 (new check on empty is done first..)
raise ValueError(f"{action!r} is not a valid {cls.__qualname__}")

@dataclass(frozen=True)
class Scope(ABC):
Expand Down
Loading

0 comments on commit e30fe26

Please sign in to comment.