diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 256a0d7d155..87c7d9e9102 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -115,3 +115,10 @@ repos: language: script types: [text] files: ^(homeassistant/.+/(manifest|strings)\.json|\.coveragerc|\.strict-typing|homeassistant/.+/services\.yaml|script/hassfest/.+\.py)$ + - id: hassfest-metadata + name: hassfest-metadata + entry: script/run-in-env.sh python3 -m script.hassfest -p metadata + pass_filenames: false + language: script + types: [text] + files: ^(script/hassfest/.+\.py|homeassistant/const\.py$|setup\.cfg)$ diff --git a/script/hassfest/__main__.py b/script/hassfest/__main__.py index 8a8e1155ab9..c6a9799a502 100644 --- a/script/hassfest/__main__.py +++ b/script/hassfest/__main__.py @@ -12,6 +12,7 @@ from . import ( dhcp, json, manifest, + metadata, mqtt, mypy_config, requirements, @@ -41,6 +42,7 @@ INTEGRATION_PLUGINS = [ HASS_PLUGINS = [ coverage, mypy_config, + metadata, ] ALL_PLUGIN_NAMES = [ diff --git a/script/hassfest/metadata.py b/script/hassfest/metadata.py new file mode 100644 index 00000000000..ab5ba3f036d --- /dev/null +++ b/script/hassfest/metadata.py @@ -0,0 +1,31 @@ +"""Package metadata validation.""" +import configparser + +from homeassistant.const import REQUIRED_PYTHON_VER, __version__ + +from .model import Config, Integration + + +def validate(integrations: dict[str, Integration], config: Config) -> None: + """Validate project metadata keys.""" + metadata_path = config.root / "setup.cfg" + parser = configparser.ConfigParser() + parser.read(metadata_path) + + try: + if parser["metadata"]["version"] != __version__: + config.add_error( + "metadata", f"'metadata.version' value does not match '{__version__}'" + ) + except KeyError: + config.add_error("metadata", "No 'metadata.version' key found!") + + required_py_version = f">={'.'.join(map(str, REQUIRED_PYTHON_VER))}" + try: + if parser["options"]["python_requires"] != required_py_version: + config.add_error( + "metadata", + f"'options.python_requires' value doesn't match '{required_py_version}", + ) + except KeyError: + config.add_error("metadata", "No 'options.python_requires' key found!") diff --git a/script/version_bump.py b/script/version_bump.py index 5f1988f3c26..6044cdb277c 100755 --- a/script/version_bump.py +++ b/script/version_bump.py @@ -117,7 +117,18 @@ def write_version(version): ) with open("homeassistant/const.py", "wt") as fil: - content = fil.write(content) + fil.write(content) + + +def write_version_metadata(version: Version) -> None: + """Update setup.cfg file with new version.""" + with open("setup.cfg") as fp: + content = fp.read() + + content = re.sub(r"(version\W+=\W).+\n", f"\\g<1>{version}\n", content, count=1) + + with open("setup.cfg", "w") as fp: + fp.write(content) def main(): @@ -142,6 +153,7 @@ def main(): assert bumped > current, "BUG! New version is not newer than old version" write_version(bumped) + write_version_metadata(bumped) if not arguments.commit: return diff --git a/setup.cfg b/setup.cfg index 4b226b4402c..0625178d78f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,5 @@ [metadata] +version = 2022.3.0.dev0 license = Apache-2.0 license_file = LICENSE.md platforms = any @@ -15,6 +16,7 @@ classifier = Topic :: Home Automation [options] +python_requires = >=3.9.0 install_requires = aiohttp==3.8.1 astral==2.2 diff --git a/setup.py b/setup.py index c6f3f1fb02f..403ba9f0a33 100755 --- a/setup.py +++ b/setup.py @@ -31,11 +31,8 @@ PROJECT_URLS = { PACKAGES = find_packages(exclude=["tests", "tests.*"]) -MIN_PY_VERSION = ".".join(map(str, hass_const.REQUIRED_PYTHON_VER)) - setup( name=PROJECT_PACKAGE_NAME, - version=hass_const.__version__, url=PROJECT_URL, download_url=DOWNLOAD_URL, project_urls=PROJECT_URLS, @@ -44,7 +41,6 @@ setup( packages=PACKAGES, include_package_data=True, zip_safe=False, - python_requires=f">={MIN_PY_VERSION}", test_suite="tests", entry_points={"console_scripts": ["hass = homeassistant.__main__:main"]}, )