Skip to content

Commit

Permalink
more mypy platforms in ci (Chia-Network#12299)
Browse files Browse the repository at this point in the history
* more mypy platforms in ci

* check not checks

* oh yeah, activate...

* add 3.11

* adjust job names

* actually use the right python version for install

* adjust for 3.7 hinting support

* exclude macos 3.7 and macos arm 3.8

* back to 3.8 for now

* major_dot_minor

* oops

* move ignore comments for 3.7

* and more
  • Loading branch information
altendky authored Apr 27, 2023
1 parent 4c7f7e7 commit 2ed75d4
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 41 deletions.
153 changes: 134 additions & 19 deletions .github/workflows/upload-pypi-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,143 @@ concurrency:
cancel-in-progress: true

jobs:
mypy:
name: ${{ matrix.os.emoji }} ${{ matrix.check.name }} - ${{ matrix.os.name }} ${{ matrix.arch.name }} ${{ matrix.python.major_dot_minor }}
runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os:
- name: Linux
matrix: linux
emoji: 🐧
runs-on:
intel: ubuntu-latest
arm: [linux, arm64]
- name: macOS
matrix: macos
emoji: 🍎
runs-on:
intel: macos-latest
arm: [macos, arm64]
- name: Windows
matrix: windows
emoji: 🪟
runs-on:
intel: windows-latest
arch:
- name: ARM64
matrix: arm
- name: Intel
matrix: intel
python:
- major_dot_minor: '3.7'
- major_dot_minor: '3.8'
- major_dot_minor: '3.9'
- major_dot_minor: '3.10'
- major_dot_minor: '3.11'
check:
- name: mypy
command: |
echo "MYPY VERSION IS: $(mypy --version)"
mypy
exclude:
- os:
matrix: macos
python:
major_dot_minor: '3.7'
- os:
matrix: macos
arch:
matrix: arm
python:
major_dot_minor: '3.8'
- os:
matrix: windows
arch:
matrix: arm

steps:
- uses: chia-network/actions/clean-workspace@main

- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive

- uses: chia-network/actions/setup-python@main
with:
python-version: ${{ matrix.python.major_dot_minor }}

- uses: ./.github/actions/install
with:
python-version: ${{ matrix.python.major_dot_minor }}
development: true

- uses: chia-network/actions/activate-venv@main

- name: Check with ${{ matrix.check.name }}
run: |
${{ matrix.check.command }}
check:
name: ${{ matrix.os.emoji }} ${{ matrix.check.name }} - ${{ matrix.os.name }} ${{ matrix.arch.name }} ${{ matrix.python.major_dot_minor }}
runs-on: ${{ matrix.os.runs-on[matrix.arch.matrix] }}
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os:
- name: Linux
matrix: linux
emoji: 🐧
runs-on:
intel: ubuntu-latest
arm: [linux, arm64]
arch:
- name: Intel
matrix: intel
python:
- major_dot_minor: '3.8'
check:
- name: black
command: black --check --diff .
- name: flake8
command: flake8 benchmarks build_scripts chia tests tools *.py
- name: pylint
command: pylint benchmarks build_scripts chia tests tools *.py

steps:
- uses: chia-network/actions/clean-workspace@main

- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive

- uses: chia-network/actions/setup-python@main
with:
python-version: ${{ matrix.python.major_dot_minor }}

- uses: ./.github/actions/install
with:
python-version: ${{ matrix.python.major_dot_minor }}
development: true

- uses: chia-network/actions/activate-venv@main

- name: Check with ${{ matrix.check.name }}
run: |
${{ matrix.check.command }}
upload_source_dist:
name: Lint and Upload source distribution
runs-on: [ubuntu-latest]
timeout-minutes: 30

needs:
- mypy
- check
steps:
- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -51,28 +183,11 @@ jobs:

- uses: ./.github/actions/install
with:
python-version: '3.8'
python-version: ${{ matrix.python.major_dot_minor }}
development: true

- uses: chia-network/actions/activate-venv@main

- name: Lint source with black
run: |
black --check --diff .
- name: Lint source with flake8
run: |
flake8 benchmarks build_scripts chia tests tools *.py
- name: Lint source with mypy
run: |
echo "MYPY VERSION IS: $(mypy --version)"
mypy
- name: Lint source with pylint
run: |
pylint benchmarks build_scripts chia tests tools *.py
- name: Build source distribution
run: |
python -m build --sdist --outdir dist .
Expand Down
4 changes: 4 additions & 0 deletions benchmarks/mempool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import asyncio
import cProfile
import sys
from contextlib import contextmanager
from dataclasses import dataclass
from subprocess import check_call
Expand All @@ -28,6 +29,9 @@

@contextmanager
def enable_profiler(profile: bool, name: str) -> Iterator[None]:
if sys.version_info < (3, 8):
raise Exception(f"Python 3.8 or higher required, running with: {sys.version}")

if not profile:
yield
return
Expand Down
3 changes: 3 additions & 0 deletions chia/util/task_timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ def get_file(frame: FrameType) -> str:


def trace_fun(frame: FrameType, event: str, arg: Any) -> None:
if sys.version_info < (3, 8):
raise Exception(f"Python 3.8 or higher required, running with: {sys.version}")

if event in ["c_call", "c_return", "c_exception"]:
return

Expand Down
24 changes: 12 additions & 12 deletions tests/generator/test_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ def test_decompress_puzzle(self) -> None:

def test_decompress_cse(self) -> None:
"""Decompress a single CSE / CoinSpendEntry"""
cse0 = binutils.assemble(
cse0 = binutils.assemble( # type: ignore[no-untyped-call]
"((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ())))"
) # type: ignore[no-untyped-call]
)
cost, out = DECOMPRESS_CSE.run_with_cost(
INFINITE_COST, [DESERIALIZE_MOD, DECOMPRESS_PUZZLE, b"\xff", b"\x80", cse0]
)
Expand All @@ -228,9 +228,9 @@ def test_decompress_cse(self) -> None:
print(out)

def test_decompress_cse_with_prefix(self) -> None:
cse0 = binutils.assemble(
cse0 = binutils.assemble( # type: ignore[no-untyped-call]
"((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ())))"
) # type: ignore[no-untyped-call]
)

start = 2 + 44
end = start + 238
Expand All @@ -246,10 +246,10 @@ def test_decompress_cse_with_prefix(self) -> None:
def test_block_program_zero(self) -> None:
"Decompress a list of CSEs"
self.maxDiff = None
cse1 = binutils.assemble(
cse1 = binutils.assemble( # type: ignore[no-untyped-call]
"(((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ()))))"
) # type: ignore[no-untyped-call]
cse2 = binutils.assemble(
)
cse2 = binutils.assemble( # type: ignore[no-untyped-call]
"""
(
((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0)
Expand All @@ -263,7 +263,7 @@ def test_block_program_zero(self) -> None:
)
"""
) # type: ignore[no-untyped-call]
)

start = 2 + 44
end = start + 238
Expand All @@ -288,10 +288,10 @@ def test_block_program_zero(self) -> None:

def test_block_program_zero_with_curry(self) -> None:
self.maxDiff = None
cse1 = binutils.assemble(
cse1 = binutils.assemble( # type: ignore[no-untyped-call]
"(((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0) (0xb081963921826355dcb6c355ccf9c2637c18adf7d38ee44d803ea9ca41587e48c913d8d46896eb830aeadfc13144a8eac3 (() (q (51 0x6b7a83babea1eec790c947db4464ab657dbe9b887fe9acc247062847b8c2a8a9 0x0186a0)) ()))))"
) # type: ignore[no-untyped-call]
cse2 = binutils.assemble(
)
cse2 = binutils.assemble( # type: ignore[no-untyped-call]
"""
(
((0x0000000000000000000000000000000000000000000000000000000000000000 0x0186a0)
Expand All @@ -305,7 +305,7 @@ def test_block_program_zero_with_curry(self) -> None:
)
"""
) # type: ignore[no-untyped-call]
)

start = 2 + 44
end = start + 238
Expand Down
8 changes: 4 additions & 4 deletions tests/generator/test_rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@
COMPILED_GENERATOR_CODE = bytes(Program.to(compile_clvm_text(GENERATOR_CODE, []))) # type: ignore[no-untyped-call]

FIRST_GENERATOR = Program.to(
binutils.assemble(
binutils.assemble( # type: ignore[no-untyped-call]
'((parent_id (c 1 (q "puzzle blob")) 50000 "solution is here" extra data for coin))'
) # type: ignore[no-untyped-call]
)
).as_bin()

SECOND_GENERATOR = Program.to(binutils.assemble("(extra data for block)")).as_bin() # type: ignore[no-untyped-call]


FIRST_GENERATOR = Program.to(
binutils.assemble(
binutils.assemble( # type: ignore[no-untyped-call]
"""
((0x0000000000000000000000000000000000000000000000000000000000000000 1 50000
((51 0x0000000000000000000000000000000000000000000000000000000000000001 500))
"extra" "data" "for" "coin" ))""" # type: ignore[no-untyped-call]
"extra" "data" "for" "coin" ))"""
)
).as_bin()

Expand Down
2 changes: 1 addition & 1 deletion tests/simulation/test_start_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def test_start_simulator(
# We can ignore this timeout as long as the subsequent tests pass
try:
await simulator_rpc_client.reorg_blocks(2) # fork point 2 blocks, now height is 5
except asyncio.exceptions.TimeoutError:
except asyncio.TimeoutError:
pass # ignore this error and hope the reorg is going ahead

# wait up to 5 mins
Expand Down
4 changes: 4 additions & 0 deletions tests/wallet/test_offer_parsing_performance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import cProfile
import sys
from contextlib import contextmanager
from typing import Iterator

Expand All @@ -17,6 +18,9 @@

@contextmanager
def enable_profiler(name: str) -> Iterator[None]:
if sys.version_info < (3, 8):
raise Exception(f"Python 3.8 or higher required, running with: {sys.version}")

if not with_profile:
yield
return
Expand Down
3 changes: 3 additions & 0 deletions tools/generate_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

@contextmanager
def enable_profiler(profile: bool, counter: int) -> Iterator[None]:
if sys.version_info < (3, 8):
raise Exception(f"Python 3.8 or higher required, running with: {sys.version}")

if not profile:
yield
return
Expand Down
4 changes: 2 additions & 2 deletions tools/manage_clvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ManageClvmError(Exception):
pass


class CacheEntry(typing.TypedDict):
class CacheEntry(typing_extensions.TypedDict):
clsp: str
hex: str
hash: str
Expand All @@ -70,7 +70,7 @@ def __init__(self, found_version: object, expected_version: CacheVersion) -> Non
super().__init__(f"Cache has wrong version, expected {expected_version!r} got: {found_version!r}")


class Cache(typing.TypedDict):
class Cache(typing_extensions.TypedDict):
entries: CacheEntries
version: CacheVersion

Expand Down
Loading

0 comments on commit 2ed75d4

Please sign in to comment.