Skip to content

Commit

Permalink
Move version metadata key to setup.cfg (home-assistant#65091)
Browse files Browse the repository at this point in the history
* Move version to setup.cfg
* Move python_requires to setup.cfg
* Add script to validate project metadata
* Add dedicated pre-commit hook
  • Loading branch information
cdce8p authored Jan 28, 2022
1 parent a9cc35d commit 75f39f9
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)$
2 changes: 2 additions & 0 deletions script/hassfest/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
dhcp,
json,
manifest,
metadata,
mqtt,
mypy_config,
requirements,
Expand Down Expand Up @@ -41,6 +42,7 @@
HASS_PLUGINS = [
coverage,
mypy_config,
metadata,
]

ALL_PLUGIN_NAMES = [
Expand Down
31 changes: 31 additions & 0 deletions script/hassfest/metadata.py
Original file line number Diff line number Diff line change
@@ -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!")
14 changes: 13 additions & 1 deletion script/version_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[metadata]
version = 2022.3.0.dev0
license = Apache-2.0
license_file = LICENSE.md
platforms = any
Expand All @@ -15,6 +16,7 @@ classifier =
Topic :: Home Automation

[options]
python_requires = >=3.9.0
install_requires =
aiohttp==3.8.1
astral==2.2
Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@

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,
Expand All @@ -44,7 +41,6 @@
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"]},
)

0 comments on commit 75f39f9

Please sign in to comment.