Skip to content

Commit 59d24b3

Browse files
committed
Install dev version - mypy
1 parent 46e7486 commit 59d24b3

File tree

3 files changed

+146
-6
lines changed

3 files changed

+146
-6
lines changed

.github/workflows/ci.yaml

Lines changed: 144 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ env:
3434
MYPY_CACHE_VERSION: 4
3535
HA_SHORT_VERSION: 2023.6
3636
DEFAULT_PYTHON: "3.10"
37-
ALL_PYTHON_VERSIONS: "['3.10', '3.11']"
37+
ALL_PYTHON_VERSIONS: "['3.10']"
3838
# 10.3 is the oldest supported version
3939
# - 10.3.32 is the version currently shipped with Synology (as of 17 Feb 2022)
4040
# 10.6 is the current long-term-support
@@ -55,9 +55,9 @@ env:
5555
PYTHONASYNCIODEBUG: 1
5656
HASS_CI: 1
5757

58-
concurrency:
59-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
60-
cancel-in-progress: true
58+
# concurrency:
59+
# group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
60+
# cancel-in-progress: true
6161

6262
jobs:
6363
info:
@@ -666,6 +666,11 @@ jobs:
666666
needs:
667667
- info
668668
- base
669+
env:
670+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
671+
CACHING: true
672+
REMOTE: cdce8p
673+
BRANCH: dev
669674
steps:
670675
- name: Check out code from GitHub
671676
uses: actions/checkout@v3.5.2
@@ -675,10 +680,32 @@ jobs:
675680
with:
676681
python-version: ${{ env.DEFAULT_PYTHON }}
677682
check-latest: true
683+
684+
- name: Fetch mypy version string (${{ env.BRANCH }})
685+
id: fetch-version
686+
run: |
687+
echo "Checking mypy branch: ${{ env.BRANCH }}"
688+
base=$(curl -sS \
689+
https://raw.githubusercontent.com/${{ env.REMOTE }}/mypy/${{ env.BRANCH }}/mypy/version.py | \
690+
grep -e ^__version__ | \
691+
cut -d '=' -f2 | tr -d ' "')
692+
sha=$(gh api \
693+
-H "Accept: application/vnd.github+json" \
694+
/repos/${{ env.REMOTE }}/mypy/git/ref/heads/${{ env.BRANCH }} | \
695+
jq -r '.object.sha')
696+
if [[ $base == *"+dev" ]]; then
697+
version="v$base.$sha"
698+
else
699+
version="v$base"
700+
fi
701+
echo "version=$version" >> $GITHUB_OUTPUT
702+
echo "name=(${{ env.BRANCH }} -- $version)" >> $GITHUB_OUTPUT
703+
echo "Found: $version"
704+
678705
- name: Generate partial mypy restore key
679706
id: generate-mypy-key
680707
run: |
681-
mypy_version=$(cat requirements_test.txt | grep mypy | cut -d '=' -f 3)
708+
mypy_version=${{ steps.fetch-version.outputs.version }}
682709
echo "version=$mypy_version" >> $GITHUB_OUTPUT
683710
echo "key=mypy-${{ env.MYPY_CACHE_VERSION }}-$mypy_version-${{
684711
env.HA_SHORT_VERSION }}-$(date -u '+%Y-%m-%dT%H:%M:%s')" >> $GITHUB_OUTPUT
@@ -691,8 +718,105 @@ jobs:
691718
key: >-
692719
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
693720
needs.info.outputs.python_cache_key }}
721+
722+
- name: Remove old mypy version
723+
run: |
724+
. venv/bin/activate
725+
pip uninstall -y mypy
726+
- name: Restore custom mypy version in venv ${{ steps.fetch-version.outputs.name }}
727+
id: cache-venv-mypy
728+
uses: actions/cache/restore@v3.3.1
729+
with:
730+
path: |
731+
venv/lib/python3.10/site-packages/*__mypyc.cpython-310*.so
732+
venv/lib/python3.10/site-packages/mypy*
733+
venv/bin/mypy
734+
key: >-
735+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv_mypy-${{
736+
env.CACHE_VERSION }}-${{ steps.fetch-version.outputs.version }}-compiled
737+
restore-keys: |
738+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv_mypy-${{
739+
env.CACHE_VERSION }}-${{ steps.fetch-version.outputs.version }}-compiled-custom
740+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv_mypy-${{
741+
env.CACHE_VERSION }}-${{ steps.fetch-version.outputs.version }}
742+
- name: Install compiled version if available
743+
if: steps.cache-venv-mypy.outputs.cache-hit != 'true'
744+
id: install-compiled
745+
continue-on-error: true
746+
run: |
747+
. venv/bin/activate
748+
tag=${{ steps.fetch-version.outputs.version }}
749+
echo "$tag"
750+
res=$(gh api \
751+
-H "Accept: application/vnd.github+json" \
752+
/repos/mypyc/mypy_mypyc-wheels/releases/tags/$tag)
753+
py=$(echo ${{ env.DEFAULT_PYTHON }} | tr -d '.')
754+
url=$(echo $res | jq -r \
755+
--arg search_name "$py-manylinux" \
756+
'.assets[] | select(.name | test($search_name)) .browser_download_url')
757+
if [[ -n url ]]; then
758+
echo "Found compiled version"
759+
pip install -U $url
760+
echo "status=done" >> $GITHUB_OUTPUT
761+
echo "key-suffix=-compiled" >> $GITHUB_OUTPUT
762+
exit 0
763+
fi
764+
- name: Install compiled version if available (custom)
765+
if: |
766+
steps.cache-venv-mypy.outputs.cache-hit != 'true'
767+
&& steps.install-compiled.outputs.status != 'done'
768+
&& endsWith( steps.cache-venv-mypy.outputs.cache-matched-key, '-compiled-custom' ) != true
769+
id: install-compiled-custom
770+
continue-on-error: true
771+
run: |
772+
. venv/bin/activate
773+
tag=${{ steps.fetch-version.outputs.version }}
774+
echo "$tag"
775+
res=$(gh api \
776+
-H "Accept: application/vnd.github+json" \
777+
/repos/${{ env.REMOTE }}/mypy-wheels/releases/tags/$tag)
778+
py=$(echo ${{ env.DEFAULT_PYTHON }} | tr -d '.')
779+
url=$(echo $res | jq -r \
780+
--arg search_name "$py-manylinux" \
781+
'.assets[] | select(.name | test($search_name)) .browser_download_url')
782+
if [[ -n url ]]; then
783+
echo "Found compiled version"
784+
pip install -U $url
785+
echo "status=done" >> $GITHUB_OUTPUT
786+
echo "key-suffix=-compiled-custom" >> $GITHUB_OUTPUT
787+
exit 0
788+
fi
789+
- name: Install custom dependencies
790+
if: |
791+
steps.cache-venv-mypy.outputs.cache-matched-key == ''
792+
&& steps.install-compiled.outputs.status != 'done'
793+
&& steps.install-compiled-custom.outputs.status != 'done'
794+
run: |
795+
. venv/bin/activate
796+
python --version
797+
pip install -U git+https://github.com/${{ env.REMOTE }}/mypy.git@${{ env.BRANCH }}
798+
- name: Save mypy version in venv
799+
if: |
800+
steps.cache-venv-mypy.outputs.cache-hit != 'true'
801+
&& (
802+
steps.cache-venv-mypy.outputs.cache-matched-key == ''
803+
|| steps.install-compiled.outputs.status == 'done'
804+
|| steps.install-compiled-custom.outputs.status == 'done'
805+
)
806+
uses: actions/cache/save@v3.3.1
807+
with:
808+
path: |
809+
venv/lib/python3.10/site-packages/*__mypyc.cpython-310*.so
810+
venv/lib/python3.10/site-packages/mypy*
811+
venv/bin/mypy
812+
key: >-
813+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv_mypy-${{
814+
env.CACHE_VERSION }}-${{ steps.fetch-version.outputs.version }}${{
815+
steps.install-compiled.outputs.key-suffix || steps.install-compiled-custom.outputs.key-suffix }}
816+
694817
- name: Restore mypy cache
695-
uses: actions/cache@v3.3.1
818+
if: env.CACHING != 'false'
819+
uses: actions/cache/restore@v3.3.1
696820
with:
697821
path: .mypy_cache
698822
key: >-
@@ -710,6 +834,9 @@ jobs:
710834
run: |
711835
. venv/bin/activate
712836
python --version
837+
git branch --show-current
838+
# For issues with serialize, add --cache-dir=/dev/null
839+
# To install types: --install-types --non-interactive
713840
mypy homeassistant pylint
714841
- name: Run mypy (partially)
715842
if: needs.info.outputs.test_full_suite == 'false'
@@ -718,10 +845,19 @@ jobs:
718845
. venv/bin/activate
719846
python --version
720847
mypy homeassistant/components/${{ needs.info.outputs.integrations_glob }}
848+
- name: Save mypy cache
849+
if: success() || failure()
850+
uses: actions/cache/save@v3.3.1
851+
with:
852+
path: .mypy_cache
853+
key: >-
854+
${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
855+
steps.generate-mypy-key.outputs.key }}
721856
722857
pytest:
723858
runs-on: ubuntu-22.04
724859
if: |
860+
false &&
725861
(github.event_name != 'push' || github.event.repository.full_name == 'home-assistant/core')
726862
&& github.event.inputs.lint-only != 'true'
727863
&& github.event.inputs.pylint-only != 'true'
@@ -847,6 +983,7 @@ jobs:
847983
MYSQL_ROOT_PASSWORD: password
848984
options: --health-cmd="mysqladmin ping -uroot -ppassword" --health-interval=5s --health-timeout=2s --health-retries=3
849985
if: |
986+
false &&
850987
(github.event_name != 'push' || github.event.repository.full_name == 'home-assistant/core')
851988
&& github.event.inputs.lint-only != 'true'
852989
&& github.event.inputs.pylint-only != 'true'
@@ -955,6 +1092,7 @@ jobs:
9551092
POSTGRES_PASSWORD: password
9561093
options: --health-cmd="pg_isready -hlocalhost -Upostgres" --health-interval=5s --health-timeout=2s --health-retries=3
9571094
if: |
1095+
false &&
9581096
(github.event_name != 'push' || github.event.repository.full_name == 'home-assistant/core')
9591097
&& github.event.inputs.lint-only != 'true'
9601098
&& github.event.inputs.pylint-only != 'true'

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ python_version = 3.10
77
plugins = pydantic.mypy
88
show_error_codes = true
99
follow_imports = silent
10+
show_traceback = true
1011
ignore_missing_imports = true
1112
local_partial_types = true
1213
strict_equality = true

script/hassfest/mypy_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"plugins": ", ".join(["pydantic.mypy"]),
3535
"show_error_codes": "true",
3636
"follow_imports": "silent",
37+
"show_traceback": "true",
3738
# Enable some checks globally.
3839
"ignore_missing_imports": "true",
3940
"local_partial_types": "true",

0 commit comments

Comments
 (0)