Move version metadata key to setup.cfg (#65091)
* Move version to setup.cfg * Move python_requires to setup.cfg * Add script to validate project metadata * Add dedicated pre-commit hook
This commit is contained in:
parent
a9cc35d6b6
commit
75f39f9ca2
6 changed files with 55 additions and 5 deletions
|
@ -115,3 +115,10 @@ repos:
|
||||||
language: script
|
language: script
|
||||||
types: [text]
|
types: [text]
|
||||||
files: ^(homeassistant/.+/(manifest|strings)\.json|\.coveragerc|\.strict-typing|homeassistant/.+/services\.yaml|script/hassfest/.+\.py)$
|
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)$
|
||||||
|
|
|
@ -12,6 +12,7 @@ from . import (
|
||||||
dhcp,
|
dhcp,
|
||||||
json,
|
json,
|
||||||
manifest,
|
manifest,
|
||||||
|
metadata,
|
||||||
mqtt,
|
mqtt,
|
||||||
mypy_config,
|
mypy_config,
|
||||||
requirements,
|
requirements,
|
||||||
|
@ -41,6 +42,7 @@ INTEGRATION_PLUGINS = [
|
||||||
HASS_PLUGINS = [
|
HASS_PLUGINS = [
|
||||||
coverage,
|
coverage,
|
||||||
mypy_config,
|
mypy_config,
|
||||||
|
metadata,
|
||||||
]
|
]
|
||||||
|
|
||||||
ALL_PLUGIN_NAMES = [
|
ALL_PLUGIN_NAMES = [
|
||||||
|
|
31
script/hassfest/metadata.py
Normal file
31
script/hassfest/metadata.py
Normal file
|
@ -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!")
|
|
@ -117,7 +117,18 @@ def write_version(version):
|
||||||
)
|
)
|
||||||
|
|
||||||
with open("homeassistant/const.py", "wt") as fil:
|
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():
|
def main():
|
||||||
|
@ -142,6 +153,7 @@ def main():
|
||||||
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)
|
write_version(bumped)
|
||||||
|
write_version_metadata(bumped)
|
||||||
|
|
||||||
if not arguments.commit:
|
if not arguments.commit:
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
[metadata]
|
[metadata]
|
||||||
|
version = 2022.3.0.dev0
|
||||||
license = Apache-2.0
|
license = Apache-2.0
|
||||||
license_file = LICENSE.md
|
license_file = LICENSE.md
|
||||||
platforms = any
|
platforms = any
|
||||||
|
@ -15,6 +16,7 @@ classifier =
|
||||||
Topic :: Home Automation
|
Topic :: Home Automation
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
|
python_requires = >=3.9.0
|
||||||
install_requires =
|
install_requires =
|
||||||
aiohttp==3.8.1
|
aiohttp==3.8.1
|
||||||
astral==2.2
|
astral==2.2
|
||||||
|
|
4
setup.py
4
setup.py
|
@ -31,11 +31,8 @@ PROJECT_URLS = {
|
||||||
|
|
||||||
PACKAGES = find_packages(exclude=["tests", "tests.*"])
|
PACKAGES = find_packages(exclude=["tests", "tests.*"])
|
||||||
|
|
||||||
MIN_PY_VERSION = ".".join(map(str, hass_const.REQUIRED_PYTHON_VER))
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name=PROJECT_PACKAGE_NAME,
|
name=PROJECT_PACKAGE_NAME,
|
||||||
version=hass_const.__version__,
|
|
||||||
url=PROJECT_URL,
|
url=PROJECT_URL,
|
||||||
download_url=DOWNLOAD_URL,
|
download_url=DOWNLOAD_URL,
|
||||||
project_urls=PROJECT_URLS,
|
project_urls=PROJECT_URLS,
|
||||||
|
@ -44,7 +41,6 @@ setup(
|
||||||
packages=PACKAGES,
|
packages=PACKAGES,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
python_requires=f">={MIN_PY_VERSION}",
|
|
||||||
test_suite="tests",
|
test_suite="tests",
|
||||||
entry_points={"console_scripts": ["hass = homeassistant.__main__:main"]},
|
entry_points={"console_scripts": ["hass = homeassistant.__main__:main"]},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue