Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
+227
-224
@@ -10,174 +10,175 @@ import sys
|
||||
from script.hassfest.model import Integration
|
||||
|
||||
COMMENT_REQUIREMENTS = (
|
||||
'Adafruit-DHT',
|
||||
'Adafruit_BBIO',
|
||||
'avion',
|
||||
'beacontools',
|
||||
'blinkt',
|
||||
'bluepy',
|
||||
'bme680',
|
||||
'credstash',
|
||||
'decora',
|
||||
'envirophat',
|
||||
'evdev',
|
||||
'face_recognition',
|
||||
'fritzconnection',
|
||||
'i2csense',
|
||||
'opencv-python-headless',
|
||||
'py_noaa',
|
||||
'VL53L1X2',
|
||||
'pybluez',
|
||||
'pycups',
|
||||
'PySwitchbot',
|
||||
'pySwitchmate',
|
||||
'python-eq3bt',
|
||||
'python-lirc',
|
||||
'pyuserinput',
|
||||
'raspihats',
|
||||
'rpi-rf',
|
||||
'RPi.GPIO',
|
||||
'smbus-cffi',
|
||||
"Adafruit-DHT",
|
||||
"Adafruit_BBIO",
|
||||
"avion",
|
||||
"beacontools",
|
||||
"blinkt",
|
||||
"bluepy",
|
||||
"bme680",
|
||||
"credstash",
|
||||
"decora",
|
||||
"envirophat",
|
||||
"evdev",
|
||||
"face_recognition",
|
||||
"fritzconnection",
|
||||
"i2csense",
|
||||
"opencv-python-headless",
|
||||
"py_noaa",
|
||||
"VL53L1X2",
|
||||
"pybluez",
|
||||
"pycups",
|
||||
"PySwitchbot",
|
||||
"pySwitchmate",
|
||||
"python-eq3bt",
|
||||
"python-lirc",
|
||||
"pyuserinput",
|
||||
"raspihats",
|
||||
"rpi-rf",
|
||||
"RPi.GPIO",
|
||||
"smbus-cffi",
|
||||
)
|
||||
|
||||
TEST_REQUIREMENTS = (
|
||||
'adguardhome',
|
||||
'ambiclimate',
|
||||
'aioambient',
|
||||
'aioautomatic',
|
||||
'aiobotocore',
|
||||
'aioesphomeapi',
|
||||
'aiohttp_cors',
|
||||
'aiohue',
|
||||
'aionotion',
|
||||
'aiounifi',
|
||||
'aioswitcher',
|
||||
'aiowwlln',
|
||||
'apns2',
|
||||
'aprslib',
|
||||
'av',
|
||||
'axis',
|
||||
'caldav',
|
||||
'coinmarketcap',
|
||||
'defusedxml',
|
||||
'dsmr_parser',
|
||||
'eebrightbox',
|
||||
'emulated_roku',
|
||||
'enocean',
|
||||
'ephem',
|
||||
'evohomeclient',
|
||||
'feedparser-homeassistant',
|
||||
'foobot_async',
|
||||
'geojson_client',
|
||||
'geopy',
|
||||
'georss_generic_client',
|
||||
'georss_ign_sismologia_client',
|
||||
'georss_qld_bushfire_alert_client',
|
||||
'google-api-python-client',
|
||||
'gTTS-token',
|
||||
'ha-ffmpeg',
|
||||
'hangups',
|
||||
'HAP-python',
|
||||
'hass-nabucasa',
|
||||
'haversine',
|
||||
'hbmqtt',
|
||||
'hdate',
|
||||
'holidays',
|
||||
'home-assistant-frontend',
|
||||
'homekit[IP]',
|
||||
'homematicip',
|
||||
'httplib2',
|
||||
'huawei-lte-api',
|
||||
'influxdb',
|
||||
'jsonpath',
|
||||
'libpurecool',
|
||||
'libsoundtouch',
|
||||
'luftdaten',
|
||||
'pyMetno',
|
||||
'mbddns',
|
||||
'mficlient',
|
||||
'netdisco',
|
||||
'numpy',
|
||||
'oauth2client',
|
||||
'paho-mqtt',
|
||||
'pexpect',
|
||||
'pilight',
|
||||
'pmsensor',
|
||||
'prometheus_client',
|
||||
'ptvsd',
|
||||
'pushbullet.py',
|
||||
'py-canary',
|
||||
'pyblackbird',
|
||||
'pydeconz',
|
||||
'pydispatcher',
|
||||
'pyheos',
|
||||
'pyhomematic',
|
||||
'pyiqvia',
|
||||
'pylitejet',
|
||||
'pymfy',
|
||||
'pymonoprice',
|
||||
'pynx584',
|
||||
'pyopenuv',
|
||||
'pyotp',
|
||||
'pyps4-homeassistant',
|
||||
'pysmartapp',
|
||||
'pysmartthings',
|
||||
'pysonos',
|
||||
'pyqwikswitch',
|
||||
'PyRMVtransport',
|
||||
'PyTransportNSW',
|
||||
'pyspcwebgw',
|
||||
'python-forecastio',
|
||||
'python-nest',
|
||||
'python_awair',
|
||||
'python-velbus',
|
||||
'pytradfri[async]',
|
||||
'pyunifi',
|
||||
'pyupnp-async',
|
||||
'pyvesync',
|
||||
'pywebpush',
|
||||
'pyHS100',
|
||||
'PyNaCl',
|
||||
'regenmaschine',
|
||||
'restrictedpython',
|
||||
'rflink',
|
||||
'ring_doorbell',
|
||||
'rxv',
|
||||
'simplisafe-python',
|
||||
'sleepyq',
|
||||
'smhi-pkg',
|
||||
'somecomfort',
|
||||
'sqlalchemy',
|
||||
'srpenergy',
|
||||
'statsd',
|
||||
'toonapilib',
|
||||
'twentemilieu',
|
||||
'uvcclient',
|
||||
'vsure',
|
||||
'warrant',
|
||||
'pythonwhois',
|
||||
'wakeonlan',
|
||||
'vultr',
|
||||
'YesssSMS',
|
||||
'ruamel.yaml',
|
||||
'zeroconf',
|
||||
'zigpy-homeassistant',
|
||||
'bellows-homeassistant',
|
||||
'py17track',
|
||||
"adguardhome",
|
||||
"ambiclimate",
|
||||
"aioambient",
|
||||
"aioautomatic",
|
||||
"aiobotocore",
|
||||
"aioesphomeapi",
|
||||
"aiohttp_cors",
|
||||
"aiohue",
|
||||
"aionotion",
|
||||
"aiounifi",
|
||||
"aioswitcher",
|
||||
"aiowwlln",
|
||||
"apns2",
|
||||
"aprslib",
|
||||
"av",
|
||||
"axis",
|
||||
"caldav",
|
||||
"coinmarketcap",
|
||||
"defusedxml",
|
||||
"dsmr_parser",
|
||||
"eebrightbox",
|
||||
"emulated_roku",
|
||||
"enocean",
|
||||
"ephem",
|
||||
"evohomeclient",
|
||||
"feedparser-homeassistant",
|
||||
"foobot_async",
|
||||
"geojson_client",
|
||||
"geopy",
|
||||
"georss_generic_client",
|
||||
"georss_ign_sismologia_client",
|
||||
"georss_qld_bushfire_alert_client",
|
||||
"google-api-python-client",
|
||||
"gTTS-token",
|
||||
"ha-ffmpeg",
|
||||
"hangups",
|
||||
"HAP-python",
|
||||
"hass-nabucasa",
|
||||
"haversine",
|
||||
"hbmqtt",
|
||||
"hdate",
|
||||
"holidays",
|
||||
"home-assistant-frontend",
|
||||
"homekit[IP]",
|
||||
"homematicip",
|
||||
"httplib2",
|
||||
"huawei-lte-api",
|
||||
"influxdb",
|
||||
"jsonpath",
|
||||
"libpurecool",
|
||||
"libsoundtouch",
|
||||
"luftdaten",
|
||||
"pyMetno",
|
||||
"mbddns",
|
||||
"mficlient",
|
||||
"netdisco",
|
||||
"numpy",
|
||||
"oauth2client",
|
||||
"paho-mqtt",
|
||||
"pexpect",
|
||||
"pilight",
|
||||
"pmsensor",
|
||||
"prometheus_client",
|
||||
"ptvsd",
|
||||
"pushbullet.py",
|
||||
"py-canary",
|
||||
"pyblackbird",
|
||||
"pydeconz",
|
||||
"pydispatcher",
|
||||
"pyheos",
|
||||
"pyhomematic",
|
||||
"pyiqvia",
|
||||
"pylitejet",
|
||||
"pymfy",
|
||||
"pymonoprice",
|
||||
"pynx584",
|
||||
"pyopenuv",
|
||||
"pyotp",
|
||||
"pyps4-homeassistant",
|
||||
"pysmartapp",
|
||||
"pysmartthings",
|
||||
"pysonos",
|
||||
"pyqwikswitch",
|
||||
"PyRMVtransport",
|
||||
"PyTransportNSW",
|
||||
"pyspcwebgw",
|
||||
"python-forecastio",
|
||||
"python-nest",
|
||||
"python_awair",
|
||||
"python-velbus",
|
||||
"pytradfri[async]",
|
||||
"pyunifi",
|
||||
"pyupnp-async",
|
||||
"pyvesync",
|
||||
"pywebpush",
|
||||
"pyHS100",
|
||||
"PyNaCl",
|
||||
"regenmaschine",
|
||||
"restrictedpython",
|
||||
"rflink",
|
||||
"ring_doorbell",
|
||||
"rxv",
|
||||
"simplisafe-python",
|
||||
"sleepyq",
|
||||
"smhi-pkg",
|
||||
"somecomfort",
|
||||
"sqlalchemy",
|
||||
"srpenergy",
|
||||
"statsd",
|
||||
"toonapilib",
|
||||
"twentemilieu",
|
||||
"uvcclient",
|
||||
"vsure",
|
||||
"warrant",
|
||||
"pythonwhois",
|
||||
"wakeonlan",
|
||||
"vultr",
|
||||
"YesssSMS",
|
||||
"ruamel.yaml",
|
||||
"zeroconf",
|
||||
"zigpy-homeassistant",
|
||||
"bellows-homeassistant",
|
||||
"py17track",
|
||||
)
|
||||
|
||||
IGNORE_PIN = ('colorlog>2.1,<3', 'keyring>=9.3,<10.0', 'urllib3')
|
||||
IGNORE_PIN = ("colorlog>2.1,<3", "keyring>=9.3,<10.0", "urllib3")
|
||||
|
||||
IGNORE_REQ = (
|
||||
'colorama<=1', # Windows only requirement in check_config
|
||||
IGNORE_REQ = ("colorama<=1",) # Windows only requirement in check_config
|
||||
|
||||
URL_PIN = (
|
||||
"https://developers.home-assistant.io/docs/"
|
||||
"creating_platform_code_review.html#1-requirements"
|
||||
)
|
||||
|
||||
URL_PIN = ('https://developers.home-assistant.io/docs/'
|
||||
'creating_platform_code_review.html#1-requirements')
|
||||
|
||||
|
||||
CONSTRAINT_PATH = os.path.join(os.path.dirname(__file__),
|
||||
'../homeassistant/package_constraints.txt')
|
||||
CONSTRAINT_PATH = os.path.join(
|
||||
os.path.dirname(__file__), "../homeassistant/package_constraints.txt"
|
||||
)
|
||||
CONSTRAINT_BASE = """
|
||||
pycryptodome>=3.6.6
|
||||
|
||||
@@ -198,10 +199,10 @@ def explore_module(package, explore_children):
|
||||
|
||||
found = []
|
||||
|
||||
if not hasattr(module, '__path__'):
|
||||
if not hasattr(module, "__path__"):
|
||||
return found
|
||||
|
||||
for _, name, _ in pkgutil.iter_modules(module.__path__, package + '.'):
|
||||
for _, name, _ in pkgutil.iter_modules(module.__path__, package + "."):
|
||||
found.append(name)
|
||||
|
||||
if explore_children:
|
||||
@@ -212,9 +213,8 @@ def explore_module(package, explore_children):
|
||||
|
||||
def core_requirements():
|
||||
"""Gather core requirements out of setup.py."""
|
||||
with open('setup.py') as inp:
|
||||
reqs_raw = re.search(
|
||||
r'REQUIRES = \[(.*?)\]', inp.read(), re.S).group(1)
|
||||
with open("setup.py") as inp:
|
||||
reqs_raw = re.search(r"REQUIRES = \[(.*?)\]", inp.read(), re.S).group(1)
|
||||
return re.findall(r"'(.*?)'", reqs_raw)
|
||||
|
||||
|
||||
@@ -224,12 +224,12 @@ def gather_recursive_requirements(domain, seen=None):
|
||||
seen = set()
|
||||
|
||||
seen.add(domain)
|
||||
integration = Integration(pathlib.Path(
|
||||
'homeassistant/components/{}'.format(domain)
|
||||
))
|
||||
integration = Integration(
|
||||
pathlib.Path("homeassistant/components/{}".format(domain))
|
||||
)
|
||||
integration.load_manifest()
|
||||
reqs = set(integration.manifest['requirements'])
|
||||
for dep_domain in integration.manifest['dependencies']:
|
||||
reqs = set(integration.manifest["requirements"])
|
||||
for dep_domain in integration.manifest["dependencies"]:
|
||||
reqs.update(gather_recursive_requirements(dep_domain, seen))
|
||||
return reqs
|
||||
|
||||
@@ -249,12 +249,11 @@ def gather_modules():
|
||||
gather_requirements_from_modules(errors, reqs)
|
||||
|
||||
for key in reqs:
|
||||
reqs[key] = sorted(reqs[key],
|
||||
key=lambda name: (len(name.split('.')), name))
|
||||
reqs[key] = sorted(reqs[key], key=lambda name: (len(name.split(".")), name))
|
||||
|
||||
if errors:
|
||||
print("******* ERROR")
|
||||
print("Errors while importing: ", ', '.join(errors))
|
||||
print("Errors while importing: ", ", ".join(errors))
|
||||
return None
|
||||
|
||||
return reqs
|
||||
@@ -262,39 +261,36 @@ def gather_modules():
|
||||
|
||||
def gather_requirements_from_manifests(errors, reqs):
|
||||
"""Gather all of the requirements from manifests."""
|
||||
integrations = Integration.load_dir(pathlib.Path(
|
||||
'homeassistant/components'
|
||||
))
|
||||
integrations = Integration.load_dir(pathlib.Path("homeassistant/components"))
|
||||
for domain in sorted(integrations):
|
||||
integration = integrations[domain]
|
||||
|
||||
if not integration.manifest:
|
||||
errors.append(
|
||||
'The manifest for integration {} is invalid.'.format(domain)
|
||||
)
|
||||
errors.append("The manifest for integration {} is invalid.".format(domain))
|
||||
continue
|
||||
|
||||
process_requirements(
|
||||
errors,
|
||||
integration.manifest['requirements'],
|
||||
'homeassistant.components.{}'.format(domain),
|
||||
reqs
|
||||
integration.manifest["requirements"],
|
||||
"homeassistant.components.{}".format(domain),
|
||||
reqs,
|
||||
)
|
||||
|
||||
|
||||
def gather_requirements_from_modules(errors, reqs):
|
||||
"""Collect the requirements from the modules directly."""
|
||||
for package in sorted(
|
||||
explore_module('homeassistant.scripts', True) +
|
||||
explore_module('homeassistant.auth', True)):
|
||||
explore_module("homeassistant.scripts", True)
|
||||
+ explore_module("homeassistant.auth", True)
|
||||
):
|
||||
try:
|
||||
module = importlib.import_module(package)
|
||||
except ImportError as err:
|
||||
print("{}: {}".format(package.replace('.', '/') + '.py', err))
|
||||
print("{}: {}".format(package.replace(".", "/") + ".py", err))
|
||||
errors.append(package)
|
||||
continue
|
||||
|
||||
if getattr(module, 'REQUIREMENTS', None):
|
||||
if getattr(module, "REQUIREMENTS", None):
|
||||
process_requirements(errors, module.REQUIREMENTS, package, reqs)
|
||||
|
||||
|
||||
@@ -303,14 +299,14 @@ def process_requirements(errors, module_requirements, package, reqs):
|
||||
for req in module_requirements:
|
||||
if req in IGNORE_REQ:
|
||||
continue
|
||||
if '://' in req:
|
||||
if "://" in req:
|
||||
errors.append(
|
||||
"{}[Only pypi dependencies are allowed: {}]".format(
|
||||
package, req))
|
||||
if req.partition('==')[1] == '' and req not in IGNORE_PIN:
|
||||
"{}[Only pypi dependencies are allowed: {}]".format(package, req)
|
||||
)
|
||||
if req.partition("==")[1] == "" and req not in IGNORE_PIN:
|
||||
errors.append(
|
||||
"{}[Please pin requirement {}, see {}]".format(
|
||||
package, req, URL_PIN))
|
||||
"{}[Please pin requirement {}, see {}]".format(package, req, URL_PIN)
|
||||
)
|
||||
reqs.setdefault(req, []).append(package)
|
||||
|
||||
|
||||
@@ -319,90 +315,98 @@ def generate_requirements_list(reqs):
|
||||
output = []
|
||||
for pkg, requirements in sorted(reqs.items(), key=lambda item: item[0]):
|
||||
for req in sorted(requirements):
|
||||
output.append('\n# {}'.format(req))
|
||||
output.append("\n# {}".format(req))
|
||||
|
||||
if comment_requirement(pkg):
|
||||
output.append('\n# {}\n'.format(pkg))
|
||||
output.append("\n# {}\n".format(pkg))
|
||||
else:
|
||||
output.append('\n{}\n'.format(pkg))
|
||||
return ''.join(output)
|
||||
output.append("\n{}\n".format(pkg))
|
||||
return "".join(output)
|
||||
|
||||
|
||||
def requirements_all_output(reqs):
|
||||
"""Generate output for requirements_all."""
|
||||
output = []
|
||||
output.append('# Home Assistant core')
|
||||
output.append('\n')
|
||||
output.append('\n'.join(core_requirements()))
|
||||
output.append('\n')
|
||||
output.append("# Home Assistant core")
|
||||
output.append("\n")
|
||||
output.append("\n".join(core_requirements()))
|
||||
output.append("\n")
|
||||
output.append(generate_requirements_list(reqs))
|
||||
|
||||
return ''.join(output)
|
||||
return "".join(output)
|
||||
|
||||
|
||||
def requirements_test_output(reqs):
|
||||
"""Generate output for test_requirements."""
|
||||
output = []
|
||||
output.append('# Home Assistant test')
|
||||
output.append('\n')
|
||||
with open('requirements_test.txt') as test_file:
|
||||
output.append("# Home Assistant test")
|
||||
output.append("\n")
|
||||
with open("requirements_test.txt") as test_file:
|
||||
output.append(test_file.read())
|
||||
output.append('\n')
|
||||
filtered = {key: value for key, value in reqs.items()
|
||||
if any(
|
||||
re.search(r'(^|#){}($|[=><])'.format(re.escape(ign)),
|
||||
key) is not None for ign in TEST_REQUIREMENTS)}
|
||||
output.append("\n")
|
||||
filtered = {
|
||||
key: value
|
||||
for key, value in reqs.items()
|
||||
if any(
|
||||
re.search(r"(^|#){}($|[=><])".format(re.escape(ign)), key) is not None
|
||||
for ign in TEST_REQUIREMENTS
|
||||
)
|
||||
}
|
||||
output.append(generate_requirements_list(filtered))
|
||||
|
||||
return ''.join(output)
|
||||
return "".join(output)
|
||||
|
||||
|
||||
def gather_constraints():
|
||||
"""Construct output for constraint file."""
|
||||
return '\n'.join(sorted(core_requirements() + list(
|
||||
gather_recursive_requirements('default_config'))) + [''])
|
||||
return "\n".join(
|
||||
sorted(
|
||||
core_requirements() + list(gather_recursive_requirements("default_config"))
|
||||
)
|
||||
+ [""]
|
||||
)
|
||||
|
||||
|
||||
def write_requirements_file(data):
|
||||
"""Write the modules to the requirements_all.txt."""
|
||||
with open('requirements_all.txt', 'w+', newline="\n") as req_file:
|
||||
with open("requirements_all.txt", "w+", newline="\n") as req_file:
|
||||
req_file.write(data)
|
||||
|
||||
|
||||
def write_test_requirements_file(data):
|
||||
"""Write the modules to the requirements_test_all.txt."""
|
||||
with open('requirements_test_all.txt', 'w+', newline="\n") as req_file:
|
||||
with open("requirements_test_all.txt", "w+", newline="\n") as req_file:
|
||||
req_file.write(data)
|
||||
|
||||
|
||||
def write_constraints_file(data):
|
||||
"""Write constraints to a file."""
|
||||
with open(CONSTRAINT_PATH, 'w+', newline="\n") as req_file:
|
||||
with open(CONSTRAINT_PATH, "w+", newline="\n") as req_file:
|
||||
req_file.write(data + CONSTRAINT_BASE)
|
||||
|
||||
|
||||
def validate_requirements_file(data):
|
||||
"""Validate if requirements_all.txt is up to date."""
|
||||
with open('requirements_all.txt', 'r') as req_file:
|
||||
with open("requirements_all.txt", "r") as req_file:
|
||||
return data == req_file.read()
|
||||
|
||||
|
||||
def validate_requirements_test_file(data):
|
||||
"""Validate if requirements_test_all.txt is up to date."""
|
||||
with open('requirements_test_all.txt', 'r') as req_file:
|
||||
with open("requirements_test_all.txt", "r") as req_file:
|
||||
return data == req_file.read()
|
||||
|
||||
|
||||
def validate_constraints_file(data):
|
||||
"""Validate if constraints is up to date."""
|
||||
with open(CONSTRAINT_PATH, 'r') as req_file:
|
||||
with open(CONSTRAINT_PATH, "r") as req_file:
|
||||
return data + CONSTRAINT_BASE == req_file.read()
|
||||
|
||||
|
||||
def main(validate):
|
||||
"""Run the script."""
|
||||
if not os.path.isfile('requirements_all.txt'):
|
||||
print('Run this from HA root dir')
|
||||
if not os.path.isfile("requirements_all.txt"):
|
||||
print("Run this from HA root dir")
|
||||
return 1
|
||||
|
||||
data = gather_modules()
|
||||
@@ -424,12 +428,11 @@ def main(validate):
|
||||
errors.append("requirements_test_all.txt is not up to date")
|
||||
|
||||
if not validate_constraints_file(constraints):
|
||||
errors.append(
|
||||
"home-assistant/package_constraints.txt is not up to date")
|
||||
errors.append("home-assistant/package_constraints.txt is not up to date")
|
||||
|
||||
if errors:
|
||||
print("******* ERROR")
|
||||
print('\n'.join(errors))
|
||||
print("\n".join(errors))
|
||||
print("Please run script/gen_requirements_all.py")
|
||||
return 1
|
||||
|
||||
@@ -441,6 +444,6 @@ def main(validate):
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
_VAL = sys.argv[-1] == 'validate'
|
||||
if __name__ == "__main__":
|
||||
_VAL = sys.argv[-1] == "validate"
|
||||
sys.exit(main(_VAL))
|
||||
+12
-31
@@ -3,35 +3,19 @@ import pathlib
|
||||
import sys
|
||||
|
||||
from .model import Integration, Config
|
||||
from . import (
|
||||
codeowners,
|
||||
config_flow,
|
||||
dependencies,
|
||||
manifest,
|
||||
services,
|
||||
ssdp,
|
||||
zeroconf,
|
||||
)
|
||||
from . import codeowners, config_flow, dependencies, manifest, services, ssdp, zeroconf
|
||||
|
||||
PLUGINS = [
|
||||
codeowners,
|
||||
config_flow,
|
||||
dependencies,
|
||||
manifest,
|
||||
services,
|
||||
ssdp,
|
||||
zeroconf,
|
||||
]
|
||||
PLUGINS = [codeowners, config_flow, dependencies, manifest, services, ssdp, zeroconf]
|
||||
|
||||
|
||||
def get_config() -> Config:
|
||||
"""Return config."""
|
||||
if not pathlib.Path('requirements_all.txt').is_file():
|
||||
if not pathlib.Path("requirements_all.txt").is_file():
|
||||
raise RuntimeError("Run from project root")
|
||||
|
||||
return Config(
|
||||
root=pathlib.Path('.').absolute(),
|
||||
action='validate' if sys.argv[-1] == 'validate' else 'generate',
|
||||
root=pathlib.Path(".").absolute(),
|
||||
action="validate" if sys.argv[-1] == "validate" else "generate",
|
||||
)
|
||||
|
||||
|
||||
@@ -43,22 +27,19 @@ def main():
|
||||
print(err)
|
||||
return 1
|
||||
|
||||
integrations = Integration.load_dir(
|
||||
pathlib.Path('homeassistant/components')
|
||||
)
|
||||
integrations = Integration.load_dir(pathlib.Path("homeassistant/components"))
|
||||
|
||||
for plugin in PLUGINS:
|
||||
plugin.validate(integrations, config)
|
||||
|
||||
# When we generate, all errors that are fixable will be ignored,
|
||||
# as generating them will be fixed.
|
||||
if config.action == 'generate':
|
||||
if config.action == "generate":
|
||||
general_errors = [err for err in config.errors if not err.fixable]
|
||||
invalid_itg = [
|
||||
itg for itg in integrations.values()
|
||||
if any(
|
||||
not error.fixable for error in itg.errors
|
||||
)
|
||||
itg
|
||||
for itg in integrations.values()
|
||||
if any(not error.fixable for error in itg.errors)
|
||||
]
|
||||
else:
|
||||
# action == validate
|
||||
@@ -70,13 +51,13 @@ def main():
|
||||
|
||||
if not invalid_itg and not general_errors:
|
||||
for plugin in PLUGINS:
|
||||
if hasattr(plugin, 'generate'):
|
||||
if hasattr(plugin, "generate"):
|
||||
plugin.generate(integrations, config)
|
||||
|
||||
return 0
|
||||
|
||||
print()
|
||||
if config.action == 'generate':
|
||||
if config.action == "generate":
|
||||
print("Found errors. Generating files canceled.")
|
||||
print()
|
||||
|
||||
|
||||
@@ -41,44 +41,43 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
if not integration.manifest:
|
||||
continue
|
||||
|
||||
codeowners = integration.manifest['codeowners']
|
||||
codeowners = integration.manifest["codeowners"]
|
||||
|
||||
if not codeowners:
|
||||
continue
|
||||
|
||||
for owner in codeowners:
|
||||
if not owner.startswith('@'):
|
||||
if not owner.startswith("@"):
|
||||
integration.add_error(
|
||||
'codeowners',
|
||||
'Code owners need to be valid GitHub handles.',
|
||||
"codeowners", "Code owners need to be valid GitHub handles."
|
||||
)
|
||||
|
||||
parts.append("homeassistant/components/{}/* {}".format(
|
||||
domain, ' '.join(codeowners)))
|
||||
parts.append(
|
||||
"homeassistant/components/{}/* {}".format(domain, " ".join(codeowners))
|
||||
)
|
||||
|
||||
parts.append('\n' + INDIVIDUAL_FILES.strip())
|
||||
parts.append("\n" + INDIVIDUAL_FILES.strip())
|
||||
|
||||
return '\n'.join(parts)
|
||||
return "\n".join(parts)
|
||||
|
||||
|
||||
def validate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Validate CODEOWNERS."""
|
||||
codeowners_path = config.root / 'CODEOWNERS'
|
||||
config.cache['codeowners'] = content = generate_and_validate(integrations)
|
||||
codeowners_path = config.root / "CODEOWNERS"
|
||||
config.cache["codeowners"] = content = generate_and_validate(integrations)
|
||||
|
||||
with open(str(codeowners_path), 'r') as fp:
|
||||
with open(str(codeowners_path), "r") as fp:
|
||||
if fp.read().strip() != content:
|
||||
config.add_error(
|
||||
"codeowners",
|
||||
"File CODEOWNERS is not up to date. "
|
||||
"Run python3 -m script.hassfest",
|
||||
fixable=True
|
||||
"File CODEOWNERS is not up to date. " "Run python3 -m script.hassfest",
|
||||
fixable=True,
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
def generate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Generate CODEOWNERS."""
|
||||
codeowners_path = config.root / 'CODEOWNERS'
|
||||
with open(str(codeowners_path), 'w') as fp:
|
||||
fp.write(config.cache['codeowners'] + '\n')
|
||||
codeowners_path = config.root / "CODEOWNERS"
|
||||
with open(str(codeowners_path), "w") as fp:
|
||||
fp.write(config.cache["codeowners"] + "\n")
|
||||
@@ -19,8 +19,8 @@ def validate_integration(integration: Integration):
|
||||
"""Validate we can load config flow without installing requirements."""
|
||||
if not (integration.path / "config_flow.py").is_file():
|
||||
integration.add_error(
|
||||
'config_flow',
|
||||
"Config flows need to be defined in the file config_flow.py")
|
||||
"config_flow", "Config flows need to be defined in the file config_flow.py"
|
||||
)
|
||||
|
||||
# Currently not require being able to load config flow without
|
||||
# installing requirements.
|
||||
@@ -50,7 +50,7 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
if not integration.manifest:
|
||||
continue
|
||||
|
||||
config_flow = integration.manifest.get('config_flow')
|
||||
config_flow = integration.manifest.get("config_flow")
|
||||
|
||||
if not config_flow:
|
||||
continue
|
||||
@@ -64,22 +64,22 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
|
||||
def validate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Validate config flow file."""
|
||||
config_flow_path = config.root / 'homeassistant/generated/config_flows.py'
|
||||
config.cache['config_flow'] = content = generate_and_validate(integrations)
|
||||
config_flow_path = config.root / "homeassistant/generated/config_flows.py"
|
||||
config.cache["config_flow"] = content = generate_and_validate(integrations)
|
||||
|
||||
with open(str(config_flow_path), 'r') as fp:
|
||||
with open(str(config_flow_path), "r") as fp:
|
||||
if fp.read().strip() != content:
|
||||
config.add_error(
|
||||
"config_flow",
|
||||
"File config_flows.py is not up to date. "
|
||||
"Run python3 -m script.hassfest",
|
||||
fixable=True
|
||||
fixable=True,
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
def generate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Generate config flow file."""
|
||||
config_flow_path = config.root / 'homeassistant/generated/config_flows.py'
|
||||
with open(str(config_flow_path), 'w') as fp:
|
||||
fp.write(config.cache['config_flow'] + '\n')
|
||||
config_flow_path = config.root / "homeassistant/generated/config_flows.py"
|
||||
with open(str(config_flow_path), "w") as fp:
|
||||
fp.write(config.cache["config_flow"] + "\n")
|
||||
@@ -6,8 +6,7 @@ from typing import Set, Dict
|
||||
from .model import Integration
|
||||
|
||||
|
||||
def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) \
|
||||
-> Set[str]:
|
||||
def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) -> Set[str]:
|
||||
"""Recursively go through a dir and it's children and find the regex."""
|
||||
pattern = re.compile(search_pattern)
|
||||
found = set()
|
||||
@@ -24,29 +23,30 @@ def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) \
|
||||
|
||||
ALLOWED_USED_COMPONENTS = {
|
||||
# This component will always be set up
|
||||
'persistent_notification',
|
||||
"persistent_notification",
|
||||
# These allow to register things without being set up
|
||||
'conversation',
|
||||
'frontend',
|
||||
'hassio',
|
||||
'system_health',
|
||||
'websocket_api',
|
||||
"conversation",
|
||||
"frontend",
|
||||
"hassio",
|
||||
"system_health",
|
||||
"websocket_api",
|
||||
}
|
||||
|
||||
|
||||
def validate_dependencies(integration: Integration):
|
||||
"""Validate all dependencies."""
|
||||
# Find usage of hass.components
|
||||
referenced = grep_dir(integration.path, "**/*.py",
|
||||
r"hass\.components\.(\w+)")
|
||||
referenced = grep_dir(integration.path, "**/*.py", r"hass\.components\.(\w+)")
|
||||
referenced -= ALLOWED_USED_COMPONENTS
|
||||
referenced -= set(integration.manifest['dependencies'])
|
||||
referenced -= set(integration.manifest.get('after_dependencies', []))
|
||||
referenced -= set(integration.manifest["dependencies"])
|
||||
referenced -= set(integration.manifest.get("after_dependencies", []))
|
||||
|
||||
if referenced:
|
||||
for domain in sorted(referenced):
|
||||
print("Warning: {} references integration {} but it's not a "
|
||||
"dependency".format(integration.domain, domain))
|
||||
print(
|
||||
"Warning: {} references integration {} but it's not a "
|
||||
"dependency".format(integration.domain, domain)
|
||||
)
|
||||
# Not enforced yet.
|
||||
# integration.add_error(
|
||||
# 'dependencies',
|
||||
@@ -64,9 +64,8 @@ def validate(integrations: Dict[str, Integration], config):
|
||||
validate_dependencies(integration)
|
||||
|
||||
# check that all referenced dependencies exist
|
||||
for dep in integration.manifest['dependencies']:
|
||||
for dep in integration.manifest["dependencies"]:
|
||||
if dep not in integrations:
|
||||
integration.add_error(
|
||||
'dependencies',
|
||||
"Dependency {} does not exist".format(dep)
|
||||
"dependencies", "Dependency {} does not exist".format(dep)
|
||||
)
|
||||
+26
-24
@@ -7,25 +7,27 @@ from voluptuous.humanize import humanize_error
|
||||
from .model import Integration
|
||||
|
||||
|
||||
MANIFEST_SCHEMA = vol.Schema({
|
||||
vol.Required('domain'): str,
|
||||
vol.Required('name'): str,
|
||||
vol.Optional('config_flow'): bool,
|
||||
vol.Optional('zeroconf'): [str],
|
||||
vol.Optional('ssdp'): vol.Schema({
|
||||
vol.Optional('st'): [str],
|
||||
vol.Optional('manufacturer'): [str],
|
||||
vol.Optional('device_type'): [str],
|
||||
}),
|
||||
vol.Optional('homekit'): vol.Schema({
|
||||
vol.Optional('models'): [str],
|
||||
}),
|
||||
vol.Required('documentation'): str,
|
||||
vol.Required('requirements'): [str],
|
||||
vol.Required('dependencies'): [str],
|
||||
vol.Optional('after_dependencies'): [str],
|
||||
vol.Required('codeowners'): [str],
|
||||
})
|
||||
MANIFEST_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required("domain"): str,
|
||||
vol.Required("name"): str,
|
||||
vol.Optional("config_flow"): bool,
|
||||
vol.Optional("zeroconf"): [str],
|
||||
vol.Optional("ssdp"): vol.Schema(
|
||||
{
|
||||
vol.Optional("st"): [str],
|
||||
vol.Optional("manufacturer"): [str],
|
||||
vol.Optional("device_type"): [str],
|
||||
}
|
||||
),
|
||||
vol.Optional("homekit"): vol.Schema({vol.Optional("models"): [str]}),
|
||||
vol.Required("documentation"): str,
|
||||
vol.Required("requirements"): [str],
|
||||
vol.Required("dependencies"): [str],
|
||||
vol.Optional("after_dependencies"): [str],
|
||||
vol.Required("codeowners"): [str],
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def validate_manifest(integration: Integration):
|
||||
@@ -34,14 +36,14 @@ def validate_manifest(integration: Integration):
|
||||
MANIFEST_SCHEMA(integration.manifest)
|
||||
except vol.Invalid as err:
|
||||
integration.add_error(
|
||||
'manifest',
|
||||
"Invalid manifest: {}".format(
|
||||
humanize_error(integration.manifest, err)))
|
||||
"manifest",
|
||||
"Invalid manifest: {}".format(humanize_error(integration.manifest, err)),
|
||||
)
|
||||
integration.manifest = None
|
||||
return
|
||||
|
||||
if integration.manifest['domain'] != integration.path.name:
|
||||
integration.add_error('manifest', 'Domain does not match dir name')
|
||||
if integration.manifest["domain"] != integration.path.name:
|
||||
integration.add_error("manifest", "Domain does not match dir name")
|
||||
|
||||
|
||||
def validate(integrations: Dict[str, Integration], config):
|
||||
|
||||
@@ -3,13 +3,12 @@ import json
|
||||
import pathlib
|
||||
|
||||
|
||||
component_dir = pathlib.Path('homeassistant/components')
|
||||
component_dir = pathlib.Path("homeassistant/components")
|
||||
|
||||
|
||||
def iter_manifests():
|
||||
"""Iterate over all available manifests."""
|
||||
manifests = [
|
||||
json.loads(fil.read_text())
|
||||
for fil in component_dir.glob('*/manifest.json')
|
||||
json.loads(fil.read_text()) for fil in component_dir.glob("*/manifest.json")
|
||||
]
|
||||
return sorted(manifests, key=lambda man: man['domain'])
|
||||
return sorted(manifests, key=lambda man: man["domain"])
|
||||
+10
-14
@@ -44,14 +44,16 @@ class Integration:
|
||||
assert path.is_dir()
|
||||
integrations = {}
|
||||
for fil in path.iterdir():
|
||||
if fil.is_file() or fil.name == '__pycache__':
|
||||
if fil.is_file() or fil.name == "__pycache__":
|
||||
continue
|
||||
|
||||
init = fil / '__init__.py'
|
||||
init = fil / "__init__.py"
|
||||
if not init.exists():
|
||||
print("Warning: {} missing, skipping directory. "
|
||||
"If this is your development environment, "
|
||||
"you can safely delete this folder.".format(init))
|
||||
print(
|
||||
"Warning: {} missing, skipping directory. "
|
||||
"If this is your development environment, "
|
||||
"you can safely delete this folder.".format(init)
|
||||
)
|
||||
continue
|
||||
|
||||
integration = cls(fil)
|
||||
@@ -75,21 +77,15 @@ class Integration:
|
||||
|
||||
def load_manifest(self) -> None:
|
||||
"""Load manifest."""
|
||||
manifest_path = self.path / 'manifest.json'
|
||||
manifest_path = self.path / "manifest.json"
|
||||
if not manifest_path.is_file():
|
||||
self.add_error(
|
||||
'model',
|
||||
"Manifest file {} not found".format(manifest_path)
|
||||
)
|
||||
self.add_error("model", "Manifest file {} not found".format(manifest_path))
|
||||
return
|
||||
|
||||
try:
|
||||
manifest = json.loads(manifest_path.read_text())
|
||||
except ValueError as err:
|
||||
self.add_error(
|
||||
'model',
|
||||
"Manifest contains invalid JSON: {}".format(err)
|
||||
)
|
||||
self.add_error("model", "Manifest contains invalid JSON: {}".format(err))
|
||||
return
|
||||
|
||||
self.manifest = manifest
|
||||
|
||||
+26
-26
@@ -20,28 +20,27 @@ def exists(value):
|
||||
return value
|
||||
|
||||
|
||||
FIELD_SCHEMA = vol.Schema({
|
||||
vol.Required('description'): str,
|
||||
vol.Optional('example'): exists,
|
||||
vol.Optional('default'): exists,
|
||||
vol.Optional('values'): exists,
|
||||
vol.Optional('required'): bool,
|
||||
})
|
||||
FIELD_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required("description"): str,
|
||||
vol.Optional("example"): exists,
|
||||
vol.Optional("default"): exists,
|
||||
vol.Optional("values"): exists,
|
||||
vol.Optional("required"): bool,
|
||||
}
|
||||
)
|
||||
|
||||
SERVICE_SCHEMA = vol.Schema({
|
||||
vol.Required('description'): str,
|
||||
vol.Optional('fields'): vol.Schema({
|
||||
str: FIELD_SCHEMA
|
||||
})
|
||||
})
|
||||
SERVICE_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required("description"): str,
|
||||
vol.Optional("fields"): vol.Schema({str: FIELD_SCHEMA}),
|
||||
}
|
||||
)
|
||||
|
||||
SERVICES_SCHEMA = vol.Schema({
|
||||
cv.slug: SERVICE_SCHEMA
|
||||
})
|
||||
SERVICES_SCHEMA = vol.Schema({cv.slug: SERVICE_SCHEMA})
|
||||
|
||||
|
||||
def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) \
|
||||
-> bool:
|
||||
def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) -> bool:
|
||||
"""Recursively go through a dir and it's children and find the regex."""
|
||||
pattern = re.compile(search_pattern)
|
||||
|
||||
@@ -58,29 +57,30 @@ def grep_dir(path: pathlib.Path, glob_pattern: str, search_pattern: str) \
|
||||
def validate_services(integration: Integration):
|
||||
"""Validate services."""
|
||||
# Find if integration uses services
|
||||
has_services = grep_dir(integration.path, "**/*.py",
|
||||
r"hass\.services\.(register|async_register)")
|
||||
has_services = grep_dir(
|
||||
integration.path, "**/*.py", r"hass\.services\.(register|async_register)"
|
||||
)
|
||||
|
||||
if not has_services:
|
||||
return
|
||||
|
||||
try:
|
||||
data = load_yaml(str(integration.path / 'services.yaml'))
|
||||
data = load_yaml(str(integration.path / "services.yaml"))
|
||||
except FileNotFoundError:
|
||||
integration.add_error(
|
||||
'services', 'Registers services but has no services.yaml')
|
||||
integration.add_error("services", "Registers services but has no services.yaml")
|
||||
return
|
||||
except HomeAssistantError:
|
||||
integration.add_error(
|
||||
'services', 'Registers services but unable to load services.yaml')
|
||||
"services", "Registers services but unable to load services.yaml"
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
SERVICES_SCHEMA(data)
|
||||
except vol.Invalid as err:
|
||||
integration.add_error(
|
||||
'services',
|
||||
"Invalid services.yaml: {}".format(humanize_error(data, err)))
|
||||
"services", "Invalid services.yaml: {}".format(humanize_error(data, err))
|
||||
)
|
||||
|
||||
|
||||
def validate(integrations: Dict[str, Integration], config):
|
||||
|
||||
+20
-22
@@ -18,16 +18,15 @@ SSDP = {}
|
||||
|
||||
def sort_dict(value):
|
||||
"""Sort a dictionary."""
|
||||
return OrderedDict((key, value[key])
|
||||
for key in sorted(value))
|
||||
return OrderedDict((key, value[key]) for key in sorted(value))
|
||||
|
||||
|
||||
def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
"""Validate and generate ssdp data."""
|
||||
data = {
|
||||
'st': defaultdict(list),
|
||||
'manufacturer': defaultdict(list),
|
||||
'device_type': defaultdict(list),
|
||||
"st": defaultdict(list),
|
||||
"manufacturer": defaultdict(list),
|
||||
"device_type": defaultdict(list),
|
||||
}
|
||||
|
||||
for domain in sorted(integrations):
|
||||
@@ -36,7 +35,7 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
if not integration.manifest:
|
||||
continue
|
||||
|
||||
ssdp = integration.manifest.get('ssdp')
|
||||
ssdp = integration.manifest.get("ssdp")
|
||||
|
||||
if not ssdp:
|
||||
continue
|
||||
@@ -44,19 +43,19 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
try:
|
||||
with open(str(integration.path / "config_flow.py")) as fp:
|
||||
content = fp.read()
|
||||
if (' async_step_ssdp' not in content and
|
||||
'register_discovery_flow' not in content):
|
||||
integration.add_error(
|
||||
'ssdp', 'Config flow has no async_step_ssdp')
|
||||
if (
|
||||
" async_step_ssdp" not in content
|
||||
and "register_discovery_flow" not in content
|
||||
):
|
||||
integration.add_error("ssdp", "Config flow has no async_step_ssdp")
|
||||
continue
|
||||
except FileNotFoundError:
|
||||
integration.add_error(
|
||||
'ssdp',
|
||||
'SSDP info in a manifest requires a config flow to exist'
|
||||
"ssdp", "SSDP info in a manifest requires a config flow to exist"
|
||||
)
|
||||
continue
|
||||
|
||||
for key in 'st', 'manufacturer', 'device_type':
|
||||
for key in "st", "manufacturer", "device_type":
|
||||
if key not in ssdp:
|
||||
continue
|
||||
|
||||
@@ -69,22 +68,21 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
|
||||
def validate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Validate ssdp file."""
|
||||
ssdp_path = config.root / 'homeassistant/generated/ssdp.py'
|
||||
config.cache['ssdp'] = content = generate_and_validate(integrations)
|
||||
ssdp_path = config.root / "homeassistant/generated/ssdp.py"
|
||||
config.cache["ssdp"] = content = generate_and_validate(integrations)
|
||||
|
||||
with open(str(ssdp_path), 'r') as fp:
|
||||
with open(str(ssdp_path), "r") as fp:
|
||||
if fp.read().strip() != content:
|
||||
config.add_error(
|
||||
"ssdp",
|
||||
"File ssdp.py is not up to date. "
|
||||
"Run python3 -m script.hassfest",
|
||||
fixable=True
|
||||
"File ssdp.py is not up to date. " "Run python3 -m script.hassfest",
|
||||
fixable=True,
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
def generate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Generate ssdp file."""
|
||||
ssdp_path = config.root / 'homeassistant/generated/ssdp.py'
|
||||
with open(str(ssdp_path), 'w') as fp:
|
||||
fp.write(config.cache['ssdp'] + '\n')
|
||||
ssdp_path = config.root / "homeassistant/generated/ssdp.py"
|
||||
with open(str(ssdp_path), "w") as fp:
|
||||
fp.write(config.cache["ssdp"] + "\n")
|
||||
+41
-35
@@ -29,9 +29,9 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
if not integration.manifest:
|
||||
continue
|
||||
|
||||
service_types = integration.manifest.get('zeroconf', [])
|
||||
homekit = integration.manifest.get('homekit', {})
|
||||
homekit_models = homekit.get('models', [])
|
||||
service_types = integration.manifest.get("zeroconf", [])
|
||||
homekit = integration.manifest.get("homekit", {})
|
||||
homekit_models = homekit.get("models", [])
|
||||
|
||||
if not service_types and not homekit_models:
|
||||
continue
|
||||
@@ -39,24 +39,32 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
try:
|
||||
with open(str(integration.path / "config_flow.py")) as fp:
|
||||
content = fp.read()
|
||||
uses_discovery_flow = 'register_discovery_flow' in content
|
||||
uses_discovery_flow = "register_discovery_flow" in content
|
||||
|
||||
if (service_types and not uses_discovery_flow and
|
||||
' async_step_zeroconf' not in content):
|
||||
if (
|
||||
service_types
|
||||
and not uses_discovery_flow
|
||||
and " async_step_zeroconf" not in content
|
||||
):
|
||||
integration.add_error(
|
||||
'zeroconf', 'Config flow has no async_step_zeroconf')
|
||||
"zeroconf", "Config flow has no async_step_zeroconf"
|
||||
)
|
||||
continue
|
||||
|
||||
if (homekit_models and not uses_discovery_flow and
|
||||
' async_step_homekit' not in content):
|
||||
if (
|
||||
homekit_models
|
||||
and not uses_discovery_flow
|
||||
and " async_step_homekit" not in content
|
||||
):
|
||||
integration.add_error(
|
||||
'zeroconf', 'Config flow has no async_step_homekit')
|
||||
"zeroconf", "Config flow has no async_step_homekit"
|
||||
)
|
||||
continue
|
||||
|
||||
except FileNotFoundError:
|
||||
integration.add_error(
|
||||
'zeroconf',
|
||||
'Zeroconf info in a manifest requires a config flow to exist'
|
||||
"zeroconf",
|
||||
"Zeroconf info in a manifest requires a config flow to exist",
|
||||
)
|
||||
continue
|
||||
|
||||
@@ -66,9 +74,10 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
for model in homekit_models:
|
||||
if model in homekit_dict:
|
||||
integration.add_error(
|
||||
'zeroconf',
|
||||
'Integrations {} and {} have overlapping HomeKit '
|
||||
'models'.format(domain, homekit_dict[model]))
|
||||
"zeroconf",
|
||||
"Integrations {} and {} have overlapping HomeKit "
|
||||
"models".format(domain, homekit_dict[model]),
|
||||
)
|
||||
break
|
||||
|
||||
homekit_dict[model] = domain
|
||||
@@ -86,43 +95,40 @@ def generate_and_validate(integrations: Dict[str, Integration]):
|
||||
|
||||
if key.startswith(key_2) or key_2.startswith(key):
|
||||
integration.add_error(
|
||||
'zeroconf',
|
||||
'Integrations {} and {} have overlapping HomeKit '
|
||||
'models'.format(homekit_dict[key], homekit_dict[key_2]))
|
||||
"zeroconf",
|
||||
"Integrations {} and {} have overlapping HomeKit "
|
||||
"models".format(homekit_dict[key], homekit_dict[key_2]),
|
||||
)
|
||||
warned.add(key)
|
||||
warned.add(key_2)
|
||||
break
|
||||
|
||||
zeroconf = OrderedDict((key, service_type_dict[key])
|
||||
for key in sorted(service_type_dict))
|
||||
homekit = OrderedDict((key, homekit_dict[key])
|
||||
for key in sorted(homekit_dict))
|
||||
|
||||
return BASE.format(
|
||||
json.dumps(zeroconf, indent=4),
|
||||
json.dumps(homekit, indent=4),
|
||||
zeroconf = OrderedDict(
|
||||
(key, service_type_dict[key]) for key in sorted(service_type_dict)
|
||||
)
|
||||
homekit = OrderedDict((key, homekit_dict[key]) for key in sorted(homekit_dict))
|
||||
|
||||
return BASE.format(json.dumps(zeroconf, indent=4), json.dumps(homekit, indent=4))
|
||||
|
||||
|
||||
def validate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Validate zeroconf file."""
|
||||
zeroconf_path = config.root / 'homeassistant/generated/zeroconf.py'
|
||||
config.cache['zeroconf'] = content = generate_and_validate(integrations)
|
||||
zeroconf_path = config.root / "homeassistant/generated/zeroconf.py"
|
||||
config.cache["zeroconf"] = content = generate_and_validate(integrations)
|
||||
|
||||
with open(str(zeroconf_path), 'r') as fp:
|
||||
with open(str(zeroconf_path), "r") as fp:
|
||||
current = fp.read().strip()
|
||||
if current != content:
|
||||
config.add_error(
|
||||
"zeroconf",
|
||||
"File zeroconf.py is not up to date. "
|
||||
"Run python3 -m script.hassfest",
|
||||
fixable=True
|
||||
"File zeroconf.py is not up to date. " "Run python3 -m script.hassfest",
|
||||
fixable=True,
|
||||
)
|
||||
return
|
||||
|
||||
|
||||
def generate(integrations: Dict[str, Integration], config: Config):
|
||||
"""Generate zeroconf file."""
|
||||
zeroconf_path = config.root / 'homeassistant/generated/zeroconf.py'
|
||||
with open(str(zeroconf_path), 'w') as fp:
|
||||
fp.write(config.cache['zeroconf'] + '\n')
|
||||
zeroconf_path = config.root / "homeassistant/generated/zeroconf.py"
|
||||
with open(str(zeroconf_path), "w") as fp:
|
||||
fp.write(config.cache["zeroconf"] + "\n")
|
||||
+22
-17
@@ -11,16 +11,16 @@ from homeassistant.scripts.check_config import color
|
||||
def explore_module(package):
|
||||
"""Explore the modules."""
|
||||
module = importlib.import_module(package)
|
||||
if not hasattr(module, '__path__'):
|
||||
if not hasattr(module, "__path__"):
|
||||
return []
|
||||
for _, name, _ in pkgutil.iter_modules(module.__path__, package + '.'):
|
||||
for _, name, _ in pkgutil.iter_modules(module.__path__, package + "."):
|
||||
yield name
|
||||
|
||||
|
||||
def main():
|
||||
"""Run the script."""
|
||||
if not os.path.isfile('requirements_all.txt'):
|
||||
print('Run this from HA root dir')
|
||||
if not os.path.isfile("requirements_all.txt"):
|
||||
print("Run this from HA root dir")
|
||||
return
|
||||
|
||||
msg = {}
|
||||
@@ -31,29 +31,34 @@ def main():
|
||||
msg[key] = []
|
||||
msg[key].append(item)
|
||||
|
||||
for package in explore_module('homeassistant.components'):
|
||||
for package in explore_module("homeassistant.components"):
|
||||
module = importlib.import_module(package)
|
||||
module_name = getattr(module, 'DOMAIN', module.__name__)
|
||||
module_name = getattr(module, "DOMAIN", module.__name__)
|
||||
|
||||
if hasattr(module, 'PLATFORM_SCHEMA'):
|
||||
if hasattr(module, 'CONFIG_SCHEMA'):
|
||||
add_msg('WARNING', "Module {} contains PLATFORM and CONFIG "
|
||||
"schemas".format(module_name))
|
||||
add_msg('PLATFORM SCHEMA', module_name)
|
||||
if hasattr(module, "PLATFORM_SCHEMA"):
|
||||
if hasattr(module, "CONFIG_SCHEMA"):
|
||||
add_msg(
|
||||
"WARNING",
|
||||
"Module {} contains PLATFORM and CONFIG "
|
||||
"schemas".format(module_name),
|
||||
)
|
||||
add_msg("PLATFORM SCHEMA", module_name)
|
||||
continue
|
||||
|
||||
if not hasattr(module, 'CONFIG_SCHEMA'):
|
||||
add_msg('NO SCHEMA', module_name)
|
||||
if not hasattr(module, "CONFIG_SCHEMA"):
|
||||
add_msg("NO SCHEMA", module_name)
|
||||
continue
|
||||
|
||||
schema_type, schema = _identify_config_schema(module)
|
||||
|
||||
add_msg("CONFIG_SCHEMA " + str(schema_type), module_name + ' ' +
|
||||
color('cyan', str(schema)[:60]))
|
||||
add_msg(
|
||||
"CONFIG_SCHEMA " + str(schema_type),
|
||||
module_name + " " + color("cyan", str(schema)[:60]),
|
||||
)
|
||||
|
||||
for key in sorted(msg):
|
||||
print("\n{}\n - {}".format(key, '\n - '.join(msg[key])))
|
||||
print("\n{}\n - {}".format(key, "\n - ".join(msg[key])))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+55
-44
@@ -18,20 +18,20 @@ except ImportError:
|
||||
|
||||
|
||||
RE_ASCII = re.compile(r"\033\[[^m]*m")
|
||||
Error = namedtuple('Error', ['file', 'line', 'col', 'msg', 'skip'])
|
||||
Error = namedtuple("Error", ["file", "line", "col", "msg", "skip"])
|
||||
|
||||
PASS = 'green'
|
||||
FAIL = 'bold_red'
|
||||
PASS = "green"
|
||||
FAIL = "bold_red"
|
||||
|
||||
|
||||
def printc(the_color, *args):
|
||||
"""Color print helper."""
|
||||
msg = ' '.join(args)
|
||||
msg = " ".join(args)
|
||||
if not escape_codes:
|
||||
print(msg)
|
||||
return
|
||||
try:
|
||||
print(escape_codes[the_color] + msg + escape_codes['reset'])
|
||||
print(escape_codes[the_color] + msg + escape_codes["reset"])
|
||||
except KeyError:
|
||||
print(msg)
|
||||
raise ValueError("Invalid color {}".format(the_color))
|
||||
@@ -40,6 +40,7 @@ def printc(the_color, *args):
|
||||
def validate_requirements_ok():
|
||||
"""Validate requirements, returns True of ok."""
|
||||
from gen_requirements_all import main as req_main
|
||||
|
||||
return req_main(True) == 0
|
||||
|
||||
|
||||
@@ -52,7 +53,7 @@ async def read_stream(stream, display):
|
||||
break
|
||||
output.append(line)
|
||||
display(line.decode()) # assume it doesn't block
|
||||
return b''.join(output)
|
||||
return b"".join(output)
|
||||
|
||||
|
||||
async def async_exec(*args, display=False):
|
||||
@@ -63,16 +64,21 @@ async def async_exec(*args, display=False):
|
||||
argsp.append("\\\n {}".format(shlex.quote(arg)))
|
||||
else:
|
||||
argsp.append(shlex.quote(arg))
|
||||
printc('cyan', *argsp)
|
||||
printc("cyan", *argsp)
|
||||
try:
|
||||
kwargs = {'loop': LOOP, 'stdout': asyncio.subprocess.PIPE,
|
||||
'stderr': asyncio.subprocess.STDOUT}
|
||||
kwargs = {
|
||||
"loop": LOOP,
|
||||
"stdout": asyncio.subprocess.PIPE,
|
||||
"stderr": asyncio.subprocess.STDOUT,
|
||||
}
|
||||
if display:
|
||||
kwargs['stderr'] = asyncio.subprocess.PIPE
|
||||
kwargs["stderr"] = asyncio.subprocess.PIPE
|
||||
proc = await asyncio.create_subprocess_exec(*args, **kwargs)
|
||||
except FileNotFoundError as err:
|
||||
printc(FAIL, "Could not execute {}. Did you install test requirements?"
|
||||
.format(args[0]))
|
||||
printc(
|
||||
FAIL,
|
||||
"Could not execute {}. Did you install test requirements?".format(args[0]),
|
||||
)
|
||||
raise err
|
||||
|
||||
if not display:
|
||||
@@ -82,46 +88,45 @@ async def async_exec(*args, display=False):
|
||||
# read child's stdout/stderr concurrently (capture and display)
|
||||
stdout, _ = await asyncio.gather(
|
||||
read_stream(proc.stdout, sys.stdout.write),
|
||||
read_stream(proc.stderr, sys.stderr.write))
|
||||
read_stream(proc.stderr, sys.stderr.write),
|
||||
)
|
||||
exit_code = await proc.wait()
|
||||
stdout = stdout.decode('utf-8')
|
||||
stdout = stdout.decode("utf-8")
|
||||
return exit_code, stdout
|
||||
|
||||
|
||||
async def git():
|
||||
"""Exec git."""
|
||||
if len(sys.argv) > 2 and sys.argv[1] == '--':
|
||||
if len(sys.argv) > 2 and sys.argv[1] == "--":
|
||||
return sys.argv[2:]
|
||||
_, log = await async_exec('git', 'merge-base', 'upstream/dev', 'HEAD')
|
||||
_, log = await async_exec("git", "merge-base", "upstream/dev", "HEAD")
|
||||
merge_base = log.splitlines()[0]
|
||||
_, log = await async_exec('git', 'diff', merge_base, '--name-only')
|
||||
_, log = await async_exec("git", "diff", merge_base, "--name-only")
|
||||
return log.splitlines()
|
||||
|
||||
|
||||
async def pylint(files):
|
||||
"""Exec pylint."""
|
||||
_, log = await async_exec('pylint', '-f', 'parseable', '--persistent=n',
|
||||
*files)
|
||||
_, log = await async_exec("pylint", "-f", "parseable", "--persistent=n", *files)
|
||||
res = []
|
||||
for line in log.splitlines():
|
||||
line = line.split(':')
|
||||
line = line.split(":")
|
||||
if len(line) < 3:
|
||||
continue
|
||||
_fn = line[0].replace('\\', '/')
|
||||
res.append(Error(
|
||||
_fn, line[1], '', line[2].strip(), _fn.startswith('tests/')))
|
||||
_fn = line[0].replace("\\", "/")
|
||||
res.append(Error(_fn, line[1], "", line[2].strip(), _fn.startswith("tests/")))
|
||||
return res
|
||||
|
||||
|
||||
async def flake8(files):
|
||||
"""Exec flake8."""
|
||||
_, log = await async_exec('flake8', '--doctests', *files)
|
||||
_, log = await async_exec("flake8", "--doctests", *files)
|
||||
res = []
|
||||
for line in log.splitlines():
|
||||
line = line.split(':')
|
||||
line = line.split(":")
|
||||
if len(line) < 4:
|
||||
continue
|
||||
_fn = line[0].replace('\\', '/')
|
||||
_fn = line[0].replace("\\", "/")
|
||||
res.append(Error(_fn, line[1], line[2], line[3].strip(), False))
|
||||
return res
|
||||
|
||||
@@ -159,18 +164,20 @@ async def main():
|
||||
|
||||
files = await git()
|
||||
if not files:
|
||||
print("No changed files found. Please ensure you have added your "
|
||||
"changes with git add & git commit")
|
||||
print(
|
||||
"No changed files found. Please ensure you have added your "
|
||||
"changes with git add & git commit"
|
||||
)
|
||||
return
|
||||
|
||||
pyfile = re.compile(r".+\.py$")
|
||||
pyfiles = [file for file in files if pyfile.match(file)]
|
||||
|
||||
print("=============================")
|
||||
printc('bold', "CHANGED FILES:\n", '\n '.join(pyfiles))
|
||||
printc("bold", "CHANGED FILES:\n", "\n ".join(pyfiles))
|
||||
print("=============================")
|
||||
|
||||
skip_lint = len(sys.argv) > 1 and sys.argv[1] == '--skiplint'
|
||||
skip_lint = len(sys.argv) > 1 and sys.argv[1] == "--skiplint"
|
||||
if skip_lint:
|
||||
printc(FAIL, "LINT DISABLED")
|
||||
elif not await lint(pyfiles):
|
||||
@@ -180,23 +187,23 @@ async def main():
|
||||
test_files = set()
|
||||
gen_req = False
|
||||
for fname in pyfiles:
|
||||
if fname.startswith('homeassistant/components/'):
|
||||
if fname.startswith("homeassistant/components/"):
|
||||
gen_req = True # requirements script for components
|
||||
# Find test files...
|
||||
if fname.startswith('tests/'):
|
||||
if '/test_' in fname and os.path.isfile(fname):
|
||||
if fname.startswith("tests/"):
|
||||
if "/test_" in fname and os.path.isfile(fname):
|
||||
# All test helpers should be excluded
|
||||
test_files.add(fname)
|
||||
else:
|
||||
parts = fname.split('/')
|
||||
parts[0] = 'tests'
|
||||
if parts[-1] == '__init__.py':
|
||||
parts[-1] = 'test_init.py'
|
||||
elif parts[-1] == '__main__.py':
|
||||
parts[-1] = 'test_main.py'
|
||||
parts = fname.split("/")
|
||||
parts[0] = "tests"
|
||||
if parts[-1] == "__init__.py":
|
||||
parts[-1] = "test_init.py"
|
||||
elif parts[-1] == "__main__.py":
|
||||
parts[-1] = "test_main.py"
|
||||
else:
|
||||
parts[-1] = 'test_' + parts[-1]
|
||||
fname = '/'.join(parts)
|
||||
parts[-1] = "test_" + parts[-1]
|
||||
fname = "/".join(parts)
|
||||
if os.path.isfile(fname):
|
||||
test_files.add(fname)
|
||||
|
||||
@@ -214,7 +221,8 @@ async def main():
|
||||
return
|
||||
|
||||
code, _ = await async_exec(
|
||||
'pytest', '-vv', '--force-sugar', '--', *test_files, display=True)
|
||||
"pytest", "-vv", "--force-sugar", "--", *test_files, display=True
|
||||
)
|
||||
print("=============================")
|
||||
|
||||
if code == 0:
|
||||
@@ -226,9 +234,12 @@ async def main():
|
||||
printc(FAIL, "LINT DISABLED")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
LOOP = asyncio.ProactorEventLoop() if sys.platform == 'win32' \
|
||||
if __name__ == "__main__":
|
||||
LOOP = (
|
||||
asyncio.ProactorEventLoop()
|
||||
if sys.platform == "win32"
|
||||
else asyncio.get_event_loop()
|
||||
)
|
||||
|
||||
try:
|
||||
LOOP.run_until_complete(main())
|
||||
|
||||
@@ -6,16 +6,15 @@ import os
|
||||
import re
|
||||
from typing import Union, List, Dict
|
||||
|
||||
FILENAME_FORMAT = re.compile(r'strings\.(?P<suffix>\w+)\.json')
|
||||
FILENAME_FORMAT = re.compile(r"strings\.(?P<suffix>\w+)\.json")
|
||||
|
||||
|
||||
def load_json(filename: str) \
|
||||
-> Union[List, Dict]:
|
||||
def load_json(filename: str) -> Union[List, Dict]:
|
||||
"""Load JSON data from a file and return as dict or list.
|
||||
|
||||
Defaults to returning empty dict if file is not found.
|
||||
"""
|
||||
with open(filename, encoding='utf-8') as fdesc:
|
||||
with open(filename, encoding="utf-8") as fdesc:
|
||||
return json.loads(fdesc.read())
|
||||
return {}
|
||||
|
||||
@@ -26,7 +25,7 @@ def save_json(filename: str, data: Union[List, Dict]):
|
||||
Returns True on success.
|
||||
"""
|
||||
data = json.dumps(data, sort_keys=True, indent=4)
|
||||
with open(filename, 'w', encoding='utf-8') as fdesc:
|
||||
with open(filename, "w", encoding="utf-8") as fdesc:
|
||||
fdesc.write(data)
|
||||
return True
|
||||
return False
|
||||
@@ -41,38 +40,53 @@ def get_component_path(lang, component):
|
||||
"""Get the component translation path."""
|
||||
if os.path.isdir(os.path.join("homeassistant", "components", component)):
|
||||
return os.path.join(
|
||||
"homeassistant", "components", component, ".translations",
|
||||
"{}.json".format(lang))
|
||||
"homeassistant",
|
||||
"components",
|
||||
component,
|
||||
".translations",
|
||||
"{}.json".format(lang),
|
||||
)
|
||||
else:
|
||||
return os.path.join(
|
||||
"homeassistant", "components", ".translations",
|
||||
"{}.{}.json".format(component, lang))
|
||||
"homeassistant",
|
||||
"components",
|
||||
".translations",
|
||||
"{}.{}.json".format(component, lang),
|
||||
)
|
||||
|
||||
|
||||
def get_platform_path(lang, component, platform):
|
||||
"""Get the platform translation path."""
|
||||
if os.path.isdir(os.path.join(
|
||||
"homeassistant", "components", component, platform)):
|
||||
if os.path.isdir(os.path.join("homeassistant", "components", component, platform)):
|
||||
return os.path.join(
|
||||
"homeassistant", "components", component, platform,
|
||||
".translations", "{}.json".format(lang))
|
||||
"homeassistant",
|
||||
"components",
|
||||
component,
|
||||
platform,
|
||||
".translations",
|
||||
"{}.json".format(lang),
|
||||
)
|
||||
else:
|
||||
return os.path.join(
|
||||
"homeassistant", "components", component, ".translations",
|
||||
"{}.{}.json".format(platform, lang))
|
||||
"homeassistant",
|
||||
"components",
|
||||
component,
|
||||
".translations",
|
||||
"{}.{}.json".format(platform, lang),
|
||||
)
|
||||
|
||||
|
||||
def get_component_translations(translations):
|
||||
"""Get the component level translations."""
|
||||
translations = translations.copy()
|
||||
translations.pop('platform', None)
|
||||
translations.pop("platform", None)
|
||||
|
||||
return translations
|
||||
|
||||
|
||||
def save_language_translations(lang, translations):
|
||||
"""Distribute the translations for this language."""
|
||||
components = translations.get('component', {})
|
||||
components = translations.get("component", {})
|
||||
for component, component_translations in components.items():
|
||||
base_translations = get_component_translations(component_translations)
|
||||
if base_translations:
|
||||
@@ -81,7 +95,8 @@ def save_language_translations(lang, translations):
|
||||
save_json(path, base_translations)
|
||||
|
||||
for platform, platform_translations in component_translations.get(
|
||||
'platform', {}).items():
|
||||
"platform", {}
|
||||
).items():
|
||||
path = get_platform_path(lang, component, platform)
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
save_json(path, platform_translations)
|
||||
@@ -100,5 +115,5 @@ def main():
|
||||
save_language_translations(lang, translations)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -7,16 +7,15 @@ import os
|
||||
import re
|
||||
from typing import Union, List, Dict
|
||||
|
||||
FILENAME_FORMAT = re.compile(r'strings\.(?P<suffix>\w+)\.json')
|
||||
FILENAME_FORMAT = re.compile(r"strings\.(?P<suffix>\w+)\.json")
|
||||
|
||||
|
||||
def load_json(filename: str) \
|
||||
-> Union[List, Dict]:
|
||||
def load_json(filename: str) -> Union[List, Dict]:
|
||||
"""Load JSON data from a file and return as dict or list.
|
||||
|
||||
Defaults to returning empty dict if file is not found.
|
||||
"""
|
||||
with open(filename, encoding='utf-8') as fdesc:
|
||||
with open(filename, encoding="utf-8") as fdesc:
|
||||
return json.loads(fdesc.read())
|
||||
return {}
|
||||
|
||||
@@ -27,7 +26,7 @@ def save_json(filename: str, data: Union[List, Dict]):
|
||||
Returns True on success.
|
||||
"""
|
||||
data = json.dumps(data, sort_keys=True, indent=4)
|
||||
with open(filename, 'w', encoding='utf-8') as fdesc:
|
||||
with open(filename, "w", encoding="utf-8") as fdesc:
|
||||
fdesc.write(data)
|
||||
return True
|
||||
return False
|
||||
@@ -36,8 +35,7 @@ def save_json(filename: str, data: Union[List, Dict]):
|
||||
def find_strings_files():
|
||||
"""Return the paths of the strings source files."""
|
||||
return itertools.chain(
|
||||
glob.iglob("strings*.json"),
|
||||
glob.iglob("*{}strings*.json".format(os.sep)),
|
||||
glob.iglob("strings*.json"), glob.iglob("*{}strings*.json".format(os.sep))
|
||||
)
|
||||
|
||||
|
||||
@@ -45,7 +43,7 @@ def get_component_platform(path):
|
||||
"""Get the component and platform name from the path."""
|
||||
directory, filename = os.path.split(path)
|
||||
match = FILENAME_FORMAT.search(filename)
|
||||
suffix = match.group('suffix') if match else None
|
||||
suffix = match.group("suffix") if match else None
|
||||
if directory:
|
||||
return directory, suffix
|
||||
else:
|
||||
@@ -55,21 +53,21 @@ def get_component_platform(path):
|
||||
def get_translation_dict(translations, component, platform):
|
||||
"""Return the dict to hold component translations."""
|
||||
if not component:
|
||||
return translations['component']
|
||||
return translations["component"]
|
||||
|
||||
if component not in translations['component']:
|
||||
translations['component'][component] = {}
|
||||
if component not in translations["component"]:
|
||||
translations["component"][component] = {}
|
||||
|
||||
if not platform:
|
||||
return translations['component'][component]
|
||||
return translations["component"][component]
|
||||
|
||||
if 'platform' not in translations['component'][component]:
|
||||
translations['component'][component]['platform'] = {}
|
||||
if "platform" not in translations["component"][component]:
|
||||
translations["component"][component]["platform"] = {}
|
||||
|
||||
if platform not in translations['component'][component]['platform']:
|
||||
translations['component'][component]['platform'][platform] = {}
|
||||
if platform not in translations["component"][component]["platform"]:
|
||||
translations["component"][component]["platform"][platform] = {}
|
||||
|
||||
return translations['component'][component]['platform'][platform]
|
||||
return translations["component"][component]["platform"][platform]
|
||||
|
||||
|
||||
def main():
|
||||
@@ -81,9 +79,7 @@ def main():
|
||||
root = os.getcwd()
|
||||
os.chdir(os.path.join("homeassistant", "components"))
|
||||
|
||||
translations = {
|
||||
'component': {}
|
||||
}
|
||||
translations = {"component": {}}
|
||||
|
||||
paths = find_strings_files()
|
||||
for path in paths:
|
||||
@@ -96,9 +92,8 @@ def main():
|
||||
|
||||
os.makedirs("build", exist_ok=True)
|
||||
|
||||
save_json(
|
||||
os.path.join("build", "translations-upload.json"), translations)
|
||||
save_json(os.path.join("build", "translations-upload.json"), translations)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+62
-74
@@ -13,9 +13,9 @@ def _bump_release(release, bump_type):
|
||||
"""Bump a release tuple consisting of 3 numbers."""
|
||||
major, minor, patch = release
|
||||
|
||||
if bump_type == 'patch':
|
||||
if bump_type == "patch":
|
||||
patch += 1
|
||||
elif bump_type == 'minor':
|
||||
elif bump_type == "minor":
|
||||
minor += 1
|
||||
patch = 0
|
||||
|
||||
@@ -26,145 +26,133 @@ def bump_version(version, bump_type):
|
||||
"""Return a new version given a current version and action."""
|
||||
to_change = {}
|
||||
|
||||
if bump_type == 'minor':
|
||||
if bump_type == "minor":
|
||||
# Convert 0.67.3 to 0.68.0
|
||||
# Convert 0.67.3.b5 to 0.68.0
|
||||
# Convert 0.67.3.dev0 to 0.68.0
|
||||
# Convert 0.67.0.b5 to 0.67.0
|
||||
# Convert 0.67.0.dev0 to 0.67.0
|
||||
to_change['dev'] = None
|
||||
to_change['pre'] = None
|
||||
to_change["dev"] = None
|
||||
to_change["pre"] = None
|
||||
|
||||
if not version.is_prerelease or version.release[2] != 0:
|
||||
to_change['release'] = _bump_release(version.release, 'minor')
|
||||
to_change["release"] = _bump_release(version.release, "minor")
|
||||
|
||||
elif bump_type == 'patch':
|
||||
elif bump_type == "patch":
|
||||
# Convert 0.67.3 to 0.67.4
|
||||
# Convert 0.67.3.b5 to 0.67.3
|
||||
# Convert 0.67.3.dev0 to 0.67.3
|
||||
to_change['dev'] = None
|
||||
to_change['pre'] = None
|
||||
to_change["dev"] = None
|
||||
to_change["pre"] = None
|
||||
|
||||
if not version.is_prerelease:
|
||||
to_change['release'] = _bump_release(version.release, 'patch')
|
||||
to_change["release"] = _bump_release(version.release, "patch")
|
||||
|
||||
elif bump_type == 'dev':
|
||||
elif bump_type == "dev":
|
||||
# Convert 0.67.3 to 0.67.4.dev0
|
||||
# Convert 0.67.3.b5 to 0.67.4.dev0
|
||||
# Convert 0.67.3.dev0 to 0.67.3.dev1
|
||||
if version.is_devrelease:
|
||||
to_change['dev'] = ('dev', version.dev + 1)
|
||||
to_change["dev"] = ("dev", version.dev + 1)
|
||||
else:
|
||||
to_change['pre'] = ('dev', 0)
|
||||
to_change['release'] = _bump_release(version.release, 'minor')
|
||||
to_change["pre"] = ("dev", 0)
|
||||
to_change["release"] = _bump_release(version.release, "minor")
|
||||
|
||||
elif bump_type == 'beta':
|
||||
elif bump_type == "beta":
|
||||
# Convert 0.67.5 to 0.67.6b0
|
||||
# Convert 0.67.0.dev0 to 0.67.0b0
|
||||
# Convert 0.67.5.b4 to 0.67.5b5
|
||||
|
||||
if version.is_devrelease:
|
||||
to_change['dev'] = None
|
||||
to_change['pre'] = ('b', 0)
|
||||
to_change["dev"] = None
|
||||
to_change["pre"] = ("b", 0)
|
||||
|
||||
elif version.is_prerelease:
|
||||
if version.pre[0] == 'a':
|
||||
to_change['pre'] = ('b', 0)
|
||||
if version.pre[0] == 'b':
|
||||
to_change['pre'] = ('b', version.pre[1] + 1)
|
||||
if version.pre[0] == "a":
|
||||
to_change["pre"] = ("b", 0)
|
||||
if version.pre[0] == "b":
|
||||
to_change["pre"] = ("b", version.pre[1] + 1)
|
||||
else:
|
||||
to_change['pre'] = ('b', 0)
|
||||
to_change['release'] = _bump_release(version.release, 'patch')
|
||||
to_change["pre"] = ("b", 0)
|
||||
to_change["release"] = _bump_release(version.release, "patch")
|
||||
|
||||
else:
|
||||
to_change['release'] = _bump_release(version.release, 'patch')
|
||||
to_change['pre'] = ('b', 0)
|
||||
to_change["release"] = _bump_release(version.release, "patch")
|
||||
to_change["pre"] = ("b", 0)
|
||||
|
||||
else:
|
||||
assert False, 'Unsupported type: {}'.format(bump_type)
|
||||
assert False, "Unsupported type: {}".format(bump_type)
|
||||
|
||||
temp = Version('0')
|
||||
temp = Version("0")
|
||||
temp._version = version._version._replace(**to_change)
|
||||
return Version(str(temp))
|
||||
|
||||
|
||||
def write_version(version):
|
||||
"""Update Home Assistant constant file with new version."""
|
||||
with open('homeassistant/const.py') as fil:
|
||||
with open("homeassistant/const.py") as fil:
|
||||
content = fil.read()
|
||||
|
||||
major, minor, patch = str(version).split('.', 2)
|
||||
major, minor, patch = str(version).split(".", 2)
|
||||
|
||||
content = re.sub('MAJOR_VERSION = .*\n',
|
||||
'MAJOR_VERSION = {}\n'.format(major),
|
||||
content)
|
||||
content = re.sub('MINOR_VERSION = .*\n',
|
||||
'MINOR_VERSION = {}\n'.format(minor),
|
||||
content)
|
||||
content = re.sub('PATCH_VERSION = .*\n',
|
||||
"PATCH_VERSION = '{}'\n".format(patch),
|
||||
content)
|
||||
content = re.sub(
|
||||
"MAJOR_VERSION = .*\n", "MAJOR_VERSION = {}\n".format(major), content
|
||||
)
|
||||
content = re.sub(
|
||||
"MINOR_VERSION = .*\n", "MINOR_VERSION = {}\n".format(minor), content
|
||||
)
|
||||
content = re.sub(
|
||||
"PATCH_VERSION = .*\n", "PATCH_VERSION = '{}'\n".format(patch), content
|
||||
)
|
||||
|
||||
with open('homeassistant/const.py', 'wt') as fil:
|
||||
with open("homeassistant/const.py", "wt") as fil:
|
||||
content = fil.write(content)
|
||||
|
||||
|
||||
def main():
|
||||
"""Execute script."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Bump version of Home Assistant")
|
||||
parser = argparse.ArgumentParser(description="Bump version of Home Assistant")
|
||||
parser.add_argument(
|
||||
'type',
|
||||
"type",
|
||||
help="The type of the bump the version to.",
|
||||
choices=['beta', 'dev', 'patch', 'minor'],
|
||||
choices=["beta", "dev", "patch", "minor"],
|
||||
)
|
||||
parser.add_argument(
|
||||
'--commit', action='store_true',
|
||||
help='Create a version bump commit.')
|
||||
"--commit", action="store_true", help="Create a version bump commit."
|
||||
)
|
||||
arguments = parser.parse_args()
|
||||
current = Version(const.__version__)
|
||||
bumped = bump_version(current, arguments.type)
|
||||
assert bumped > current, 'BUG! New version is not newer than old version'
|
||||
assert bumped > current, "BUG! New version is not newer than old version"
|
||||
write_version(bumped)
|
||||
|
||||
if not arguments.commit:
|
||||
return
|
||||
|
||||
subprocess.run([
|
||||
'git', 'commit', '-am', 'Bumped version to {}'.format(bumped)])
|
||||
subprocess.run(["git", "commit", "-am", "Bumped version to {}".format(bumped)])
|
||||
|
||||
|
||||
def test_bump_version():
|
||||
"""Make sure it all works."""
|
||||
assert bump_version(Version('0.56.0'), 'beta') == Version('0.56.1b0')
|
||||
assert bump_version(Version('0.56.0b3'), 'beta') == Version('0.56.0b4')
|
||||
assert bump_version(Version('0.56.0.dev0'), 'beta') == Version('0.56.0b0')
|
||||
assert bump_version(Version("0.56.0"), "beta") == Version("0.56.1b0")
|
||||
assert bump_version(Version("0.56.0b3"), "beta") == Version("0.56.0b4")
|
||||
assert bump_version(Version("0.56.0.dev0"), "beta") == Version("0.56.0b0")
|
||||
|
||||
assert bump_version(Version('0.56.3'), 'dev') == Version('0.57.0.dev0')
|
||||
assert bump_version(Version('0.56.0b3'), 'dev') == Version('0.57.0.dev0')
|
||||
assert bump_version(Version('0.56.0.dev0'), 'dev') == \
|
||||
Version('0.56.0.dev1')
|
||||
assert bump_version(Version("0.56.3"), "dev") == Version("0.57.0.dev0")
|
||||
assert bump_version(Version("0.56.0b3"), "dev") == Version("0.57.0.dev0")
|
||||
assert bump_version(Version("0.56.0.dev0"), "dev") == Version("0.56.0.dev1")
|
||||
|
||||
assert bump_version(Version('0.56.3'), 'patch') == \
|
||||
Version('0.56.4')
|
||||
assert bump_version(Version('0.56.3.b3'), 'patch') == \
|
||||
Version('0.56.3')
|
||||
assert bump_version(Version('0.56.0.dev0'), 'patch') == \
|
||||
Version('0.56.0')
|
||||
assert bump_version(Version("0.56.3"), "patch") == Version("0.56.4")
|
||||
assert bump_version(Version("0.56.3.b3"), "patch") == Version("0.56.3")
|
||||
assert bump_version(Version("0.56.0.dev0"), "patch") == Version("0.56.0")
|
||||
|
||||
assert bump_version(Version('0.56.0'), 'minor') == \
|
||||
Version('0.57.0')
|
||||
assert bump_version(Version('0.56.3'), 'minor') == \
|
||||
Version('0.57.0')
|
||||
assert bump_version(Version('0.56.0.b3'), 'minor') == \
|
||||
Version('0.56.0')
|
||||
assert bump_version(Version('0.56.3.b3'), 'minor') == \
|
||||
Version('0.57.0')
|
||||
assert bump_version(Version('0.56.0.dev0'), 'minor') == \
|
||||
Version('0.56.0')
|
||||
assert bump_version(Version('0.56.2.dev0'), 'minor') == \
|
||||
Version('0.57.0')
|
||||
assert bump_version(Version("0.56.0"), "minor") == Version("0.57.0")
|
||||
assert bump_version(Version("0.56.3"), "minor") == Version("0.57.0")
|
||||
assert bump_version(Version("0.56.0.b3"), "minor") == Version("0.56.0")
|
||||
assert bump_version(Version("0.56.3.b3"), "minor") == Version("0.57.0")
|
||||
assert bump_version(Version("0.56.0.dev0"), "minor") == Version("0.56.0")
|
||||
assert bump_version(Version("0.56.2.dev0"), "minor") == Version("0.57.0")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user