mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 02:38:10 +02:00
Add integration scaffolding script (#26777)
* Add integration scaffolding script * Make easier to develop * Update py.test -> pytest
This commit is contained in:
79
script/scaffold/gather_info.py
Normal file
79
script/scaffold/gather_info.py
Normal file
@ -0,0 +1,79 @@
|
||||
"""Gather info for scaffolding."""
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from .const import COMPONENT_DIR
|
||||
from .model import Info
|
||||
from .error import ExitApp
|
||||
|
||||
|
||||
CHECK_EMPTY = ["Cannot be empty", lambda value: value]
|
||||
|
||||
|
||||
FIELDS = {
|
||||
"domain": {
|
||||
"prompt": "What is the domain?",
|
||||
"validators": [
|
||||
CHECK_EMPTY,
|
||||
[
|
||||
"Domains cannot contain spaces or special characters.",
|
||||
lambda value: value == slugify(value),
|
||||
],
|
||||
[
|
||||
"There already is an integration with this domain.",
|
||||
lambda value: not (COMPONENT_DIR / value).exists(),
|
||||
],
|
||||
],
|
||||
},
|
||||
"name": {
|
||||
"prompt": "What is the name of your integration?",
|
||||
"validators": [CHECK_EMPTY],
|
||||
},
|
||||
"codeowner": {
|
||||
"prompt": "What is your GitHub handle?",
|
||||
"validators": [
|
||||
CHECK_EMPTY,
|
||||
[
|
||||
'GitHub handles need to start with an "@"',
|
||||
lambda value: value.startswith("@"),
|
||||
],
|
||||
],
|
||||
},
|
||||
"requirement": {
|
||||
"prompt": "What PyPI package and version do you depend on? Leave blank for none.",
|
||||
"validators": [
|
||||
["Versions should be pinned using '=='.", lambda value: "==" in value]
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def gather_info() -> Info:
|
||||
"""Gather info from user."""
|
||||
answers = {}
|
||||
|
||||
for key, info in FIELDS.items():
|
||||
hint = None
|
||||
while key not in answers:
|
||||
if hint is not None:
|
||||
print()
|
||||
print(f"Error: {hint}")
|
||||
|
||||
try:
|
||||
print()
|
||||
value = input(info["prompt"] + "\n> ")
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
raise ExitApp("Interrupted!", 1)
|
||||
|
||||
value = value.strip()
|
||||
hint = None
|
||||
|
||||
for validator_hint, validator in info["validators"]:
|
||||
if not validator(value):
|
||||
hint = validator_hint
|
||||
break
|
||||
|
||||
if hint is None:
|
||||
answers[key] = value
|
||||
|
||||
print()
|
||||
return Info(**answers)
|
Reference in New Issue
Block a user