mirror of
				https://github.com/home-assistant/core.git
				synced 2025-11-04 08:29:37 +00:00 
			
		
		
		
	Validate if modules in mypy config exist (#49810)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							1c0fd61075
						
					
				
				
					commit
					a0bf95d4b5
				
			@@ -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"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user