Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update automated tests, pass as-is #301

Merged
merged 24 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
df2d82f
Update automated tests, pass as-is
Avasam Nov 21, 2023
ad3e286
Address PR comments
Avasam Dec 15, 2023
b5a257b
Split formatters shell script
Avasam Dec 15, 2023
c04314a
Update and fix tests to run from anywhere
Avasam Feb 14, 2024
a41f22c
Merge branch 'main' of https://github.com/microsoft/python-type-stubs…
Avasam May 3, 2024
4f103f2
Update tests
Avasam May 3, 2024
0080da4
Not installing pyright on CI
Avasam May 3, 2024
e40a34b
Not a TODO
Avasam May 3, 2024
c914c4a
Merge branch 'main' into Update-automated-tests
Avasam May 14, 2024
1b4106c
Merge branch 'main' into Update-automated-tests
Avasam Aug 11, 2024
cbdef6d
Set pyright's typeCheckingMode to standard
Avasam Aug 11, 2024
54e908f
Use Python scripts instead and check pyright against pylance-prerelease
Avasam Aug 12, 2024
6623bb3
Forgot to delete run_formatters
Avasam Aug 12, 2024
6177255
Merge branch 'main' into Update-automated-tests
Avasam Oct 20, 2024
ce6f02e
Merge branch 'main' of https://github.com/microsoft/python-type-stubs…
Avasam Oct 22, 2024
bff9310
typing_extensions goes under "Typed libraries and stubs"
Avasam Oct 22, 2024
58bd50f
Merge branch 'main' into Update-automated-tests
Avasam Nov 5, 2024
5f272bf
Bump minimum Python version to 3.9
Avasam Nov 5, 2024
36a42de
Missed mypy target version
Avasam Nov 5, 2024
d69ea81
Unpin typing_extensions
Avasam Nov 6, 2024
d2e605a
Merge branch 'main' of https://github.com/microsoft/python-type-stubs…
Avasam Nov 6, 2024
2abe8bf
post-merge fix
Avasam Nov 6, 2024
4a07a43
use docopt-ng instead of docopt
Avasam Nov 6, 2024
8309d4c
Add type-var to mypy disable
Avasam Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ jobs:
python -m pip install -r tests/requirements.txt

- name: Run pyright tests
uses: gramster/pyright-action@main
uses: jakebailey/pyright-action@v2
with:
project: tests/pyrighttestconfig.json
warn-partial: true
pylance-version: latest-prerelease

- name: Run mypy tests
run:
python -m mypy .

hygiene:
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"editor.formatOnSave": false,
"python.formatting.provider": "black",
"python.analysis.diagnosticMode": "workspace",
"python.analysis.typeCheckingMode": "strict",
"python.analysis.openFilesOnly": false
}
92 changes: 62 additions & 30 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[tool.black]
line_length = 130
target_version = ["py37"]
# Target oldest supported Python version
target_version = ["py39"]

[tool.ruff]
line-length = 130
# Target oldest supported Python version
target-version = "py39"

[tool.ruff.lint]
select = [
Expand Down Expand Up @@ -61,19 +64,46 @@ extra-standard-library = [
"zoneinfo",
]

[tool.pyright]
Avasam marked this conversation as resolved.
Show resolved Hide resolved
# Target oldest supported Python version
pythonversion = "3.9"
typeCheckingMode = "standard"
# Partial stubs are acceptable
reportUnknownArgumentType = false
# Stubs-only packages are fine for testing
reportMissingModuleSource = false
# Stubs are allowed to use private variables
reportPrivateUsage = false
reportPrivateImportUsage = false
# Incompatible overrides and property type mismatches are out of our stubs' control
# as they are inherited from the implementation.
reportIncompatibleMethodOverride = false
reportIncompatibleVariableOverride = false
reportPropertyTypeMismatch = false
# Overlapping overloads are often necessary in a stub, meaning pyright's check
# (which is stricter than mypy's; see mypy issue #10143 and #10157)
# would cause many false positives and catch few bugs.
reportOverlappingOverload = false
# The name of the self/cls parameter is out of third-party stubs' control.
reportSelfClsParameterName = false

# Error reports to fix in code
reportArgumentType = "none" # TODO
reportAssertTypeFailure = "none" # TODO
reportAssignmentType = "none" # TODO
reportAttributeAccessIssue = "none" # TODO
reportFunctionMemberAccess = "none" # TODO
reportGeneralTypeIssues = "none" # TODO
reportInvalidTypeArguments = "none" # TODO
reportInvalidTypeForm = "none" # TODO
reportMissingImports = "none" # TODO
reportUndefinedVariable = "none" # TODO
reportUnusedVariable = "none" # TODO

[tool.mypy]
# Import discovery
mypy_path = "partial"
namespace_packages = false
explicit_package_bases = false
ignore_missing_imports = true
follow_imports = "normal"
follow_imports_for_stubs = false
no_site_packages = false
no_silence_site_packages = false
# Platform configuration
python_version = "3.8"
# Disallow dynamic typing
# Target oldest supported Python version
python_version = "3.9"
# Allow dynamic typing
disallow_any_unimported = false # TODO
disallow_any_expr = false # TODO
disallow_any_decorated = false # TODO
Expand All @@ -86,25 +116,27 @@ disallow_untyped_defs = false # TODO
disallow_incomplete_defs = false # TODO
check_untyped_defs = true
disallow_untyped_decorators = true
# None and Optional handling
no_implicit_optional = true
strict_optional = true
# Configuring warnings
warn_redundant_casts = true
warn_unused_ignores = false # Change from pandas
warn_no_return = true
warn_return_any = false # TODO
warn_unreachable = false # GH#27396
# Suppressing errors
show_none_errors = true
ignore_errors = false
# Miscellaneous strictness flags
allow_untyped_globals = false
allow_redefinition = false
local_partial_types = false
implicit_reexport = true
strict_equality = true
disable_error_code = [
# Not all imports in these stubs are gonna be typed
"import-untyped",
# TODO
"arg-type",
"assignment",
"attr-defined",
"import-not-found",
"misc",
"name-defined",
"no-redef",
"operator",
"override",
"return",
"truthy-function",
"valid-type",
"var-annotated",
]
# Configuring error messages
show_error_context = false
show_column_numbers = false
show_error_codes = true
show_column_numbers = true
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/matplotlib/figure_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import assert_type
from typing_extensions import assert_type

from matplotlib.axes import Axes
from matplotlib.figure import Figure
Expand Down
2 changes: 1 addition & 1 deletion tests/matplotlib/pyplot_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, assert_type
from typing_extensions import assert_type

import matplotlib.pyplot as plt
import numpy as np
Expand Down
8 changes: 0 additions & 8 deletions tests/pyrighttestconfig.json

This file was deleted.

22 changes: 19 additions & 3 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
matplotlib
mypy==0.950
# Tools used for testing
docopt-ng
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When installing the requirements on a fresh install of Python 3.10, I got the following warning:
DEPRECATION: docopt is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559

That led me to docopt/docopt#502 (comment): even docopt organization members are recommending to switch over to docopt-ng due to docopt being unmaintained in the past 6 years (last release 10 years ago)

mypy==1.13.*
pyright

# Typed libraries and stubs
matplotlib>=3.8
pytest
scipy-stubs
typing_extensions

# Untyped libraries, used to prevent "reportMissingImports" and get inferred typing
joblib
networkx
PyOpenGL
scikit-image
scikit-learn
typing_extensions==4.2.0
transformers
vispy
numpydoc
pyamg
Avasam marked this conversation as resolved.
Show resolved Hide resolved
traitlets
39 changes: 39 additions & 0 deletions tests/run_formatters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import subprocess
import sys
from pathlib import Path


def install_requirements():
print("\nInstalling requirements...")
return subprocess.run((sys.executable, "-m", "pip", "install", "--upgrade", "isort", "black"))


def run_isort():
print("\nRunning isort...")
return subprocess.run((sys.executable, "-m", "isort", "."))


def run_black():
print("\nRunning Black...")
return subprocess.run((sys.executable, "-m", "black", "."))


def main():
test_folder = Path(__file__).parent
root = test_folder.parent
os.chdir(root)

install_requirements().check_returncode()
results = (
run_isort(),
run_black(),
)
if sum([result.returncode for result in results]) > 0:
print("\nOne or more tests failed. See above for details.")
else:
print("\nAll tests passed!")


if __name__ == "__main__":
main()
3 changes: 0 additions & 3 deletions tests/run_tests.cmd
debonte marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

44 changes: 44 additions & 0 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os
import subprocess
import sys
from pathlib import Path


def install_requirements(test_folder: str):
print("\nInstalling requirements...")
return subprocess.run(
(sys.executable, "-m", "pip", "install", "--upgrade", "-r", os.path.join(test_folder, "requirements.txt"))
)


def run_pyright():
print("\nRunning Pyright...")
# https://github.com/RobertCraigie/pyright-python#keeping-pyright-and-pylance-in-sync
del os.environ["PYRIGHT_PYTHON_FORCE_VERSION"]
os.environ["PYRIGHT_PYTHON_PYLANCE_VERSION"] = "latest-prerelease"
return subprocess.run((sys.executable, "-m", "pyright"))


def run_mypy():
print("\nRunning mypy...")
return subprocess.run((sys.executable, "-m", "mypy"))


def main():
test_folder = Path(__file__).parent
root = test_folder.parent
os.chdir(root)

install_requirements(test_folder).check_returncode()
results = (
run_mypy(),
run_pyright(),
)
if sum([result.returncode for result in results]) > 0:
print("\nOne or more tests failed. See above for details.")
else:
print("\nAll tests passed!")


if __name__ == "__main__":
main()
7 changes: 0 additions & 7 deletions tests/run_tests.sh

This file was deleted.