1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-30 00:52:20 +01:00

[core] os.path -> Path (#10654)

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
This commit is contained in:
Jesse Hills
2025-09-20 00:59:48 +12:00
committed by GitHub
parent de617c85c7
commit 9ea3643b74
57 changed files with 808 additions and 938 deletions

View File

@@ -15,7 +15,7 @@ from ipaddress import (
ip_network,
)
import logging
import os
from pathlib import Path
import re
from string import ascii_letters, digits
import uuid as uuid_
@@ -1609,34 +1609,32 @@ def dimensions(value):
return dimensions([match.group(1), match.group(2)])
def directory(value):
def directory(value: object) -> Path:
value = string(value)
path = CORE.relative_config_path(value)
if not os.path.exists(path):
if not path.exists():
raise Invalid(
f"Could not find directory '{path}'. Please make sure it exists (full path: {os.path.abspath(path)})."
f"Could not find directory '{path}'. Please make sure it exists (full path: {path.resolve()})."
)
if not os.path.isdir(path):
if not path.is_dir():
raise Invalid(
f"Path '{path}' is not a directory (full path: {os.path.abspath(path)})."
f"Path '{path}' is not a directory (full path: {path.resolve()})."
)
return value
return path
def file_(value):
def file_(value: object) -> Path:
value = string(value)
path = CORE.relative_config_path(value)
if not os.path.exists(path):
if not path.exists():
raise Invalid(
f"Could not find file '{path}'. Please make sure it exists (full path: {os.path.abspath(path)})."
f"Could not find file '{path}'. Please make sure it exists (full path: {path.resolve()})."
)
if not os.path.isfile(path):
raise Invalid(
f"Path '{path}' is not a file (full path: {os.path.abspath(path)})."
)
return value
if not path.is_file():
raise Invalid(f"Path '{path}' is not a file (full path: {path.resolve()}).")
return path
ENTITY_ID_CHARACTERS = "abcdefghijklmnopqrstuvwxyz0123456789_"