From 1ac71455cbcaf05d8b9b13d69b9bd7372c92111c Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 26 May 2022 02:54:49 +0200 Subject: [PATCH] Move remaining metadata to pyproject (#72469) --- .core_files.yaml | 2 +- .pre-commit-config.yaml | 4 ++-- CODEOWNERS | 1 + pyproject.toml | 32 ++++++++++++++++++++++++++++++-- requirements_test.txt | 1 + script/gen_requirements_all.py | 14 +++++++++----- script/hassfest/codeowners.py | 1 + script/hassfest/metadata.py | 21 +++++++++++++-------- script/version_bump.py | 8 ++++---- setup.cfg | 30 ------------------------------ 10 files changed, 62 insertions(+), 52 deletions(-) diff --git a/.core_files.yaml b/.core_files.yaml index 2928d450ce2..55b543a333e 100644 --- a/.core_files.yaml +++ b/.core_files.yaml @@ -132,7 +132,7 @@ requirements: &requirements - homeassistant/package_constraints.txt - script/pip_check - requirements*.txt - - setup.cfg + - pyproject.toml any: - *base_platforms diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 539308c08f1..ff00ce07e0c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -106,7 +106,7 @@ repos: pass_filenames: false language: script types: [text] - files: ^(homeassistant/.+/manifest\.json|setup\.cfg|\.pre-commit-config\.yaml|script/gen_requirements_all\.py)$ + files: ^(homeassistant/.+/manifest\.json|pyproject\.toml|\.pre-commit-config\.yaml|script/gen_requirements_all\.py)$ - id: hassfest name: hassfest entry: script/run-in-env.sh python3 -m script.hassfest @@ -120,7 +120,7 @@ repos: pass_filenames: false language: script types: [text] - files: ^(script/hassfest/metadata\.py|homeassistant/const\.py$|setup\.cfg)$ + files: ^(script/hassfest/metadata\.py|homeassistant/const\.py$|pyproject\.toml)$ - id: hassfest-mypy-config name: hassfest-mypy-config entry: script/run-in-env.sh python3 -m script.hassfest -p mypy_config diff --git a/CODEOWNERS b/CODEOWNERS index 98d60fbfcb7..3baeb6dda68 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -6,6 +6,7 @@ # Home Assistant Core setup.cfg @home-assistant/core +pyproject.toml @home-assistant/core /homeassistant/*.py @home-assistant/core /homeassistant/helpers/ @home-assistant/core /homeassistant/util/ @home-assistant/core diff --git a/pyproject.toml b/pyproject.toml index e0db5324d02..60551dae997 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,11 +4,12 @@ build-backend = "setuptools.build_meta" [project] name = "homeassistant" +version = "2022.7.0.dev0" license = {text = "Apache-2.0"} description = "Open-source home automation platform running on Python 3." readme = "README.rst" authors = [ - {name = "The Home Assistant Authors", email = "hello@home-assistant.io"} + {name = "The Home Assistant Authors", email = "hello@home-assistant.io"} ] keywords = ["home", "automation"] classifiers = [ @@ -21,7 +22,34 @@ classifiers = [ "Programming Language :: Python :: 3.10", "Topic :: Home Automation", ] -dynamic = ["version", "requires-python", "dependencies"] +requires-python = ">=3.9.0" +dependencies = [ + "aiohttp==3.8.1", + "astral==2.2", + "async_timeout==4.0.2", + "attrs==21.2.0", + "atomicwrites==1.4.0", + "awesomeversion==22.5.1", + "bcrypt==3.1.7", + "certifi>=2021.5.30", + "ciso8601==2.2.0", + # When bumping httpx, please check the version pins of + # httpcore, anyio, and h11 in gen_requirements_all + "httpx==0.22.0", + "ifaddr==0.1.7", + "jinja2==3.1.2", + "PyJWT==2.4.0", + # PyJWT has loose dependency. We want the latest one. + "cryptography==36.0.2", + "pip>=21.0,<22.2", + "python-slugify==4.0.1", + "pyyaml==6.0", + "requests==2.27.1", + "typing-extensions>=3.10.0.2,<5.0", + "voluptuous==0.13.1", + "voluptuous-serialize==2.5.0", + "yarl==1.7.2", +] [project.urls] "Source Code" = "https://github.com/home-assistant/core" diff --git a/requirements_test.txt b/requirements_test.txt index 7e4e29de339..e888d715cd4 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -28,6 +28,7 @@ pytest==7.1.1 requests_mock==1.9.2 respx==0.19.0 stdlib-list==0.7.0 +tomli==2.0.1;python_version<"3.11" tqdm==4.49.0 types-atomicwrites==1.4.1 types-croniter==1.0.0 diff --git a/script/gen_requirements_all.py b/script/gen_requirements_all.py index 369045e5124..a7b26d297c9 100755 --- a/script/gen_requirements_all.py +++ b/script/gen_requirements_all.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """Generate an updated requirements_all.txt.""" -import configparser import difflib import importlib import os @@ -12,6 +11,11 @@ import sys from homeassistant.util.yaml.loader import load_yaml from script.hassfest.model import Integration +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib + COMMENT_REQUIREMENTS = ( "Adafruit_BBIO", "avea", # depends on bluepy @@ -166,10 +170,10 @@ def explore_module(package, explore_children): def core_requirements(): - """Gather core requirements out of setup.cfg.""" - parser = configparser.ConfigParser() - parser.read("setup.cfg") - return parser["options"]["install_requires"].strip().split("\n") + """Gather core requirements out of pyproject.toml.""" + with open("pyproject.toml", "rb") as fp: + data = tomllib.load(fp) + return data["project"]["dependencies"] def gather_recursive_requirements(domain, seen=None): diff --git a/script/hassfest/codeowners.py b/script/hassfest/codeowners.py index d2ee6182f22..5511bc8a518 100644 --- a/script/hassfest/codeowners.py +++ b/script/hassfest/codeowners.py @@ -12,6 +12,7 @@ BASE = """ # Home Assistant Core setup.cfg @home-assistant/core +pyproject.toml @home-assistant/core /homeassistant/*.py @home-assistant/core /homeassistant/helpers/ @home-assistant/core /homeassistant/util/ @home-assistant/core diff --git a/script/hassfest/metadata.py b/script/hassfest/metadata.py index ab5ba3f036d..48459eacb72 100644 --- a/script/hassfest/metadata.py +++ b/script/hassfest/metadata.py @@ -1,31 +1,36 @@ """Package metadata validation.""" -import configparser +import sys from homeassistant.const import REQUIRED_PYTHON_VER, __version__ from .model import Config, Integration +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib + 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) + metadata_path = config.root / "pyproject.toml" + with open(metadata_path, "rb") as fp: + data = tomllib.load(fp) try: - if parser["metadata"]["version"] != __version__: + if data["project"]["version"] != __version__: config.add_error( - "metadata", f"'metadata.version' value does not match '{__version__}'" + "metadata", f"'project.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: + if data["project"]["requires-python"] != required_py_version: config.add_error( "metadata", - f"'options.python_requires' value doesn't match '{required_py_version}", + f"'project.requires-python' 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 d714c5183b7..f7dc37b5e22 100755 --- a/script/version_bump.py +++ b/script/version_bump.py @@ -121,13 +121,13 @@ def write_version(version): def write_version_metadata(version: Version) -> None: - """Update setup.cfg file with new version.""" - with open("setup.cfg") as fp: + """Update pyproject.toml file with new version.""" + with open("pyproject.toml", encoding="utf8") as fp: content = fp.read() - content = re.sub(r"(version\W+=\W).+\n", f"\\g<1>{version}\n", content, count=1) + content = re.sub(r"(version\W+=\W).+\n", f'\\g<1>"{version}"\n', content, count=1) - with open("setup.cfg", "w") as fp: + with open("pyproject.toml", "w", encoding="utf8") as fp: fp.write(content) diff --git a/setup.cfg b/setup.cfg index 15db31bd306..dbf815a56e9 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,36 +1,6 @@ [metadata] -version = 2022.7.0.dev0 url = https://www.home-assistant.io/ -[options] -python_requires = >=3.9.0 -install_requires = - aiohttp==3.8.1 - astral==2.2 - async_timeout==4.0.2 - attrs==21.2.0 - atomicwrites==1.4.0 - awesomeversion==22.5.1 - bcrypt==3.1.7 - certifi>=2021.5.30 - ciso8601==2.2.0 - # When bumping httpx, please check the version pins of - # httpcore, anyio, and h11 in gen_requirements_all - httpx==0.22.0 - ifaddr==0.1.7 - jinja2==3.1.2 - PyJWT==2.4.0 - # PyJWT has loose dependency. We want the latest one. - cryptography==36.0.2 - pip>=21.0,<22.2 - python-slugify==4.0.1 - pyyaml==6.0 - requests==2.27.1 - typing-extensions>=3.10.0.2,<5.0 - voluptuous==0.13.1 - voluptuous-serialize==2.5.0 - yarl==1.7.2 - [flake8] exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build max-complexity = 25 -- GitLab