Add task to install all requirements of an integration (#108262)
* Add task to install the requirements of an integration * Gather recursive requirements * Move valid_integration to util * Apply suggestions from code review Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> * Implement suggestions --------- Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>pull/108320/head
parent
c399cab427
commit
edd7feaf10
|
@ -157,6 +157,20 @@
|
|||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"label": "Install integration requirements",
|
||||
"detail": "Install all requirements of a given integration.",
|
||||
"type": "shell",
|
||||
"command": "${command:python.interpreterPath} -m script.install_integration_requirements ${input:integrationName}",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
}
|
||||
}
|
||||
],
|
||||
"inputs": [
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
"""Script constants."""
|
||||
from pathlib import Path
|
||||
|
||||
COMPONENT_DIR = Path("homeassistant/components")
|
|
@ -0,0 +1,54 @@
|
|||
"""Install requirements for a given integration."""
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from .gen_requirements_all import gather_recursive_requirements
|
||||
from .util import valid_integration
|
||||
|
||||
|
||||
def get_arguments() -> argparse.Namespace:
|
||||
"""Get parsed passed in arguments."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Install requirements for a given integration"
|
||||
)
|
||||
parser.add_argument(
|
||||
"integration", type=valid_integration, help="Integration to target."
|
||||
)
|
||||
|
||||
arguments = parser.parse_args()
|
||||
|
||||
return arguments
|
||||
|
||||
|
||||
def main() -> int | None:
|
||||
"""Install requirements for a given integration."""
|
||||
if not Path("requirements_all.txt").is_file():
|
||||
print("Run from project root")
|
||||
return 1
|
||||
|
||||
args = get_arguments()
|
||||
|
||||
requirements = gather_recursive_requirements(args.integration)
|
||||
|
||||
cmd = [
|
||||
sys.executable,
|
||||
"-m",
|
||||
"pip",
|
||||
"install",
|
||||
"-c",
|
||||
"homeassistant/package_constraints.txt",
|
||||
"-U",
|
||||
*requirements,
|
||||
]
|
||||
print(" ".join(cmd))
|
||||
subprocess.run(
|
||||
cmd,
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
|
@ -4,24 +4,15 @@ from pathlib import Path
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
from script.util import valid_integration
|
||||
|
||||
from . import docs, error, gather_info, generate
|
||||
from .const import COMPONENT_DIR
|
||||
|
||||
TEMPLATES = [
|
||||
p.name for p in (Path(__file__).parent / "templates").glob("*") if p.is_dir()
|
||||
]
|
||||
|
||||
|
||||
def valid_integration(integration):
|
||||
"""Test if it's a valid integration."""
|
||||
if not (COMPONENT_DIR / integration).exists():
|
||||
raise argparse.ArgumentTypeError(
|
||||
f"The integration {integration} does not exist."
|
||||
)
|
||||
|
||||
return integration
|
||||
|
||||
|
||||
def get_arguments() -> argparse.Namespace:
|
||||
"""Get parsed passed in arguments."""
|
||||
parser = argparse.ArgumentParser(description="Home Assistant Scaffolder")
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
"""Utility functions for the scaffold script."""
|
||||
|
||||
import argparse
|
||||
|
||||
from .const import COMPONENT_DIR
|
||||
|
||||
|
||||
def valid_integration(integration):
|
||||
"""Test if it's a valid integration."""
|
||||
if not (COMPONENT_DIR / integration).exists():
|
||||
raise argparse.ArgumentTypeError(
|
||||
f"The integration {integration} does not exist."
|
||||
)
|
||||
|
||||
return integration
|
Loading…
Reference in New Issue