Add integration scaffolding script (#26777)
* Add integration scaffolding script * Make easier to develop * Update py.test -> pytest
This commit is contained in:
parent
5cf9ba51df
commit
8502f7c7d4
15 changed files with 425 additions and 0 deletions
47
script/scaffold/generate.py
Normal file
47
script/scaffold/generate.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
"""Generate an integration."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from .const import COMPONENT_DIR, TESTS_DIR
|
||||
from .model import Info
|
||||
|
||||
TEMPLATE_DIR = Path(__file__).parent / "templates"
|
||||
TEMPLATE_INTEGRATION = TEMPLATE_DIR / "integration"
|
||||
TEMPLATE_TESTS = TEMPLATE_DIR / "tests"
|
||||
|
||||
|
||||
def generate(info: Info) -> None:
|
||||
"""Generate an integration."""
|
||||
print(f"Generating the {info.domain} integration...")
|
||||
integration_dir = COMPONENT_DIR / info.domain
|
||||
test_dir = TESTS_DIR / info.domain
|
||||
|
||||
replaces = {
|
||||
"NEW_DOMAIN": info.domain,
|
||||
"NEW_NAME": info.name,
|
||||
"NEW_CODEOWNER": info.codeowner,
|
||||
# Special case because we need to keep the list empty if there is none.
|
||||
'"MANIFEST_NEW_REQUIREMENT"': (
|
||||
json.dumps(info.requirement) if info.requirement else ""
|
||||
),
|
||||
}
|
||||
|
||||
for src_dir, target_dir in (
|
||||
(TEMPLATE_INTEGRATION, integration_dir),
|
||||
(TEMPLATE_TESTS, test_dir),
|
||||
):
|
||||
# Guard making it for test purposes.
|
||||
if not target_dir.exists():
|
||||
target_dir.mkdir()
|
||||
|
||||
for source_file in src_dir.glob("**/*"):
|
||||
content = source_file.read_text()
|
||||
|
||||
for to_search, to_replace in replaces.items():
|
||||
content = content.replace(to_search, to_replace)
|
||||
|
||||
target_file = target_dir / source_file.relative_to(src_dir)
|
||||
print(f"Writing {target_file}")
|
||||
target_file.write_text(content)
|
||||
|
||||
print()
|
Loading…
Add table
Add a link
Reference in a new issue