Skip to content

Commit def1f2b

Browse files
authored
[CI] Enable mypy/pyright tox scripts (#32586)
This allows these scripts to run the mypy and pyright checks against any module name. This is needed to test the corehttp source code. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 509c372 commit def1f2b

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

eng/tox/run_mypy.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ci_tools.environment_exclusions import (
1717
is_check_enabled, is_typing_ignored
1818
)
19+
from ci_tools.parsing import ParsedSetup
1920
from ci_tools.variables import in_ci
2021
from gh_tools.vnext_issue_creator import create_vnext_issue
2122

@@ -39,18 +40,21 @@
3940
"--next",
4041
default=False,
4142
help="Next version of mypy is being tested.",
42-
required=False
43+
required=False
4344
)
4445

4546
args = parser.parse_args()
46-
package_name = os.path.basename(os.path.abspath(args.target_package))
47+
package_dir = os.path.abspath(args.target_package)
48+
package_name = os.path.basename(package_dir)
4749
if not args.next and in_ci():
4850
if not is_check_enabled(args.target_package, "mypy", True) or is_typing_ignored(package_name):
4951
logging.info(
5052
f"Package {package_name} opts-out of mypy check. See https://aka.ms/python/typing-guide for information."
5153
)
5254
exit(0)
5355

56+
pkg_details = ParsedSetup.from_path(package_dir)
57+
top_level_module = pkg_details.namespace.split(".")[0]
5458
commands = [
5559
sys.executable,
5660
"-m",
@@ -60,7 +64,7 @@
6064
"--show-error-codes",
6165
"--ignore-missing-imports",
6266
]
63-
src_code = [*commands, os.path.join(args.target_package, "azure")]
67+
src_code = [*commands, os.path.join(args.target_package, top_level_module)]
6468
src_code_error = None
6569
sample_code_error = None
6670
try:

eng/tox/run_pyright.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from ci_tools.environment_exclusions import (
1818
is_check_enabled, is_typing_ignored
1919
)
20+
from ci_tools.parsing import ParsedSetup
2021
from ci_tools.variables import in_ci
2122
from gh_tools.vnext_issue_creator import create_vnext_issue
2223

@@ -26,7 +27,7 @@
2627

2728

2829
def get_pyright_config_path(args):
29-
"""Give pyright an execution environment when running with tox. Otherwise
30+
"""Give pyright an execution environment when running with tox. Otherwise
3031
we use pyright's default for import resolution which doesn't work well
3132
in our monorepo.
3233
@@ -77,7 +78,8 @@ def get_pyright_config_path(args):
7778
)
7879

7980
args = parser.parse_args()
80-
package_name = os.path.basename(os.path.abspath(args.target_package))
81+
package_dir = os.path.abspath(args.target_package)
82+
package_name = os.path.basename(package_dir)
8183

8284
if not args.next and in_ci():
8385
if not is_check_enabled(args.target_package, "pyright") or is_typing_ignored(package_name):
@@ -86,8 +88,10 @@ def get_pyright_config_path(args):
8688
)
8789
exit(0)
8890

91+
pkg_details = ParsedSetup.from_path(package_dir)
92+
top_level_module = pkg_details.namespace.split(".")[0]
8993
paths = [
90-
os.path.join(args.target_package, "azure"),
94+
os.path.join(args.target_package, top_level_module),
9195
os.path.join(args.target_package, "samples"),
9296
]
9397

sdk/core/corehttp/pyproject.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
[tool.azure-sdk-build]
2-
mypy = false
3-
type_check_samples = false
4-
verifytypes = false
52
pyright = false
3+
strict_sphinx = true

0 commit comments

Comments
 (0)