Skip to content

Commit

Permalink
QA: integrate mypy in QA testing
Browse files Browse the repository at this point in the history
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
  • Loading branch information
Josverl committed Dec 29, 2023
1 parent e33eeac commit 95cc6f5
Show file tree
Hide file tree
Showing 55 changed files with 921 additions and 332 deletions.
6 changes: 3 additions & 3 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// https://github.com/microsoft/pyright/blob/main/docs/configuration.md
{
"include": [
"stubs",
"tests", "docs"
],
"exclude": [
// other artefacts
Expand All @@ -22,8 +22,8 @@
//
],
"ignore": [
"tests",
"docs",
// "tests",
// "docs",
// see also : https://github.com/Josverl/micropython-stubs/issues/412
// webrepl
"**/webrepl.py",
Expand Down
4 changes: 3 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
micropython-stubber

# for quality reporting
pyright==1.1.341
pytest
pyright==1.1.341
mypy
fasteners
python-dotenv
pydocstyle
loguru
mypy_gitlab_code_quality
102 changes: 21 additions & 81 deletions scripts/try_mypy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
}
],
"source": [
"# basic install with the latest local stdlib and esp32 stubs\n",
"\n",
"import shutil\n",
"\n",
"if os.path.exists(check_path / \"typings\"):\n",
Expand All @@ -76,10 +78,14 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import subprocess\n",
"import json\n",
"from mypy_gitlab_code_quality import generate_report as gitlab_report\n",
"\n",
"def mypy_patch(check_path):\n",
" if not check_path.exists():\n",
" Exception(f\"Path {check_path} not found\")\n",
Expand All @@ -95,19 +101,6 @@
" elif file.is_dir():\n",
" shutil.rmtree(file)\n",
"\n",
" # else:\n",
"\n",
" # print(f\"File {f} not found\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"import subprocess\n",
"\n",
"\n",
"def run_mypy(path: Path):\n",
" print(f\"Running mypy in {path}\")\n",
Expand All @@ -125,73 +118,10 @@
" )\n",
" return output.stdout\n",
" except subprocess.CalledProcessError as e:\n",
" print(e)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running mypy in C:\\develop\\MyPython\\micropython-stubs\\tests\\quality_tests\\check_esp32\n"
]
}
],
"source": [
"# run mypy\n",
"raw_results = run_mypy(check_path)\n",
"results = raw_results.split(\"\\n\")\n",
"# errors = []\n",
"# for i, line in enumerate(results):\n",
"# if \"error:\" in line:\n",
"# errors.append(line)\n",
"# elif \"warning\" in line:\n",
"# errors.append(line)\n",
" print(e)\n",
"\n",
"# # print results\n",
"# for line in errors:\n",
"# print(line)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# now parse to json and save\n",
"# https://github.com/python/mypy/issues/10816\n",
"\n",
"# mypy program.py | mypy-gitlab-code-quality"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# # convert from mypy to gitlab code quality format\n",
"# from mypy_gitlab_code_quality import generate_report, parse_issue\n",
"\n",
"# gitlab_report = generate_report(map(str.rstrip, results))\n",
"\n",
"# gitlab_report"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# convert from gitlab to pyright format\n",
"\n",
"import json\n",
"HEADER = \"\"\"\n",
"{\n",
" \"version\": \"\",\n",
Expand Down Expand Up @@ -245,9 +175,16 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running mypy in C:\\develop\\MyPython\\micropython-stubs\\tests\\quality_tests\\check_esp32\n"
]
},
{
"data": {
"text/plain": [
Expand All @@ -266,13 +203,16 @@
" 'timeInSec': -1}}"
]
},
"execution_count": 15,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from mypy_gitlab_code_quality import generate_report as gitlab_report\n",
"# run mypy\n",
"raw_results = run_mypy(check_path)\n",
"results = raw_results.split(\"\\n\")\n",
"\n",
"gitlab_to_pyright(gitlab_report(map(str.rstrip, results)))"
]
},
Expand Down
22 changes: 22 additions & 0 deletions tests/quality_tests/_configs/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[mypy]
platform = linux
mypy_path = typings
files = *.py
exclude = typings[\\/].*
custom_typing_module = typings/stdlib/typing.pyi
; custom_typeshed_dir = typings/stdlib/_typeshed ; not a valid typeshed dir

follow_imports = silent
follow_imports_for_stubs = True
no_site_packages = True

check_untyped_defs = True

; show_error_context = True
disable_error_code = no-redef,assignment

# snippets may re-use the same variable names
allow_redefinition = True

; warn_return_any = True
; warn_unused_configs = True
22 changes: 22 additions & 0 deletions tests/quality_tests/_configs/pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"include": [
"."
],
"typeshedPaths": [
"./typings"
],
"exclude": [
".*",
"__*",
"**/typings"
],
"ignore": [
"**/typings"
],
// "pythonVersion": "3.8",
"pythonPlatform": "Linux",
"verboseOutput": false,
"typeCheckingMode": "basic",
"typeshedPath": "./typings",
"reportMissingModuleSource": "none"
}
3 changes: 3 additions & 0 deletions tests/quality_tests/_configs/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# typechecker config files for tests

The files in this folder are used copied to each check_* and feat_folder to make sure the typechecker tests that are all using the same configuration.
4 changes: 2 additions & 2 deletions tests/quality_tests/check_esp32/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ follow_imports = silent
follow_imports_for_stubs = True
no_site_packages = True

check_untyped_defs=True
check_untyped_defs = True

; show_error_context = True
disable_error_code = no-redef,assignment

# sippets may re-use the same variable names
# snippets may re-use the same variable names
allow_redefinition = True

; warn_return_any = True
Expand Down
22 changes: 22 additions & 0 deletions tests/quality_tests/check_esp8266/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[mypy]
platform = linux
mypy_path = typings
files = *.py
exclude = typings[\\/].*
custom_typing_module = typings/stdlib/typing.pyi
; custom_typeshed_dir = typings/stdlib/_typeshed ; not a valid typeshed dir

follow_imports = silent
follow_imports_for_stubs = True
no_site_packages = True

check_untyped_defs = True

; show_error_context = True
disable_error_code = no-redef,assignment

# snippets may re-use the same variable names
allow_redefinition = True

; warn_return_any = True
; warn_unused_configs = True
3 changes: 1 addition & 2 deletions tests/quality_tests/check_esp8266/pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
"**/typings"
],
"ignore": [
"typings",
"**/typings"
],
"pythonVersion": "3.8",
// "pythonVersion": "3.8",
"pythonPlatform": "Linux",
"verboseOutput": false,
"typeCheckingMode": "basic",
Expand Down
22 changes: 22 additions & 0 deletions tests/quality_tests/check_rp2-nano_connect/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[mypy]
platform = linux
mypy_path = typings
files = *.py
exclude = typings[\\/].*
custom_typing_module = typings/stdlib/typing.pyi
; custom_typeshed_dir = typings/stdlib/_typeshed ; not a valid typeshed dir

follow_imports = silent
follow_imports_for_stubs = True
no_site_packages = True

check_untyped_defs = True

; show_error_context = True
disable_error_code = no-redef,assignment

# snippets may re-use the same variable names
allow_redefinition = True

; warn_return_any = True
; warn_unused_configs = True
22 changes: 22 additions & 0 deletions tests/quality_tests/check_rp2-nano_connect/pyrightconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"include": [
"."
],
"typeshedPaths": [
"./typings"
],
"exclude": [
".*",
"__*",
"**/typings"
],
"ignore": [
"**/typings"
],
// "pythonVersion": "3.8",
"pythonPlatform": "Linux",
"verboseOutput": false,
"typeCheckingMode": "basic",
"typeshedPath": "./typings",
"reportMissingModuleSource": "none"
}
3 changes: 3 additions & 0 deletions tests/quality_tests/check_rp2/check_machine/check_ds18x20.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import time

import ds18x20
import onewire
from machine import Pin

ow = onewire.OneWire(Pin(12))
ds = ds18x20.DS18X20(ow)
roms = ds.scan()
ds.convert_temp()
Expand Down
22 changes: 22 additions & 0 deletions tests/quality_tests/check_rp2/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[mypy]
platform = linux
mypy_path = typings
files = *.py
exclude = typings[\\/].*
custom_typing_module = typings/stdlib/typing.pyi
; custom_typeshed_dir = typings/stdlib/_typeshed ; not a valid typeshed dir

follow_imports = silent
follow_imports_for_stubs = True
no_site_packages = True

check_untyped_defs = True

; show_error_context = True
disable_error_code = no-redef,assignment

# snippets may re-use the same variable names
allow_redefinition = True

; warn_return_any = True
; warn_unused_configs = True
Loading

0 comments on commit 95cc6f5

Please sign in to comment.