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>
This commit is contained in:
parent
c399cab427
commit
edd7feaf10
5 changed files with 89 additions and 11 deletions
14
.vscode/tasks.json
vendored
14
.vscode/tasks.json
vendored
|
@ -157,6 +157,20 @@
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": true
|
"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": [
|
"inputs": [
|
||||||
|
|
4
script/const.py
Normal file
4
script/const.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
"""Script constants."""
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
COMPONENT_DIR = Path("homeassistant/components")
|
54
script/install_integration_requirements.py
Normal file
54
script/install_integration_requirements.py
Normal file
|
@ -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 subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from script.util import valid_integration
|
||||||
|
|
||||||
from . import docs, error, gather_info, generate
|
from . import docs, error, gather_info, generate
|
||||||
from .const import COMPONENT_DIR
|
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
p.name for p in (Path(__file__).parent / "templates").glob("*") if p.is_dir()
|
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:
|
def get_arguments() -> argparse.Namespace:
|
||||||
"""Get parsed passed in arguments."""
|
"""Get parsed passed in arguments."""
|
||||||
parser = argparse.ArgumentParser(description="Home Assistant Scaffolder")
|
parser = argparse.ArgumentParser(description="Home Assistant Scaffolder")
|
||||||
|
|
15
script/util.py
Normal file
15
script/util.py
Normal file
|
@ -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…
Add table
Reference in a new issue