Validate if modules in mypy config exist (#49810)

pull/49841/head
Ruslan Sayfutdinov 2021-04-29 05:29:53 +01:00 committed by GitHub
parent 1c0fd61075
commit a0bf95d4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -3,6 +3,8 @@ from __future__ import annotations
import configparser
import io
import os
from pathlib import Path
from typing import Final
from .model import Config, Integration
@ -321,6 +323,22 @@ def generate_and_validate(config: Config) -> str:
if module in ignored_modules_set:
config.add_error("mypy_config", f"Module '{module}' is in ignored list")
# Validate that all modules exist.
all_modules = strict_modules + IGNORED_MODULES
for module in all_modules:
if module.endswith(".*"):
module_path = Path(module[:-2].replace(".", os.path.sep))
if not module_path.is_dir():
config.add_error("mypy_config", f"Module '{module} is not a folder")
else:
module = module.replace(".", os.path.sep)
module_path = Path(f"{module}.py")
if module_path.is_file():
continue
module_path = Path(module) / "__init__.py"
if not module_path.is_file():
config.add_error("mypy_config", f"Module '{module} doesn't exist")
mypy_config = configparser.ConfigParser()
general_section = "mypy"