Move remaining metadata to pyproject (#72469)

This commit is contained in:
Marc Mueller 2022-05-26 02:54:49 +02:00 committed by GitHub
parent 30edc039ae
commit 1ac71455cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 62 additions and 52 deletions

View file

@ -132,7 +132,7 @@ requirements: &requirements
- homeassistant/package_constraints.txt - homeassistant/package_constraints.txt
- script/pip_check - script/pip_check
- requirements*.txt - requirements*.txt
- setup.cfg - pyproject.toml
any: any:
- *base_platforms - *base_platforms

View file

@ -106,7 +106,7 @@ repos:
pass_filenames: false pass_filenames: false
language: script language: script
types: [text] 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 - id: hassfest
name: hassfest name: hassfest
entry: script/run-in-env.sh python3 -m script.hassfest entry: script/run-in-env.sh python3 -m script.hassfest
@ -120,7 +120,7 @@ repos:
pass_filenames: false pass_filenames: false
language: script language: script
types: [text] 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 - id: hassfest-mypy-config
name: hassfest-mypy-config name: hassfest-mypy-config
entry: script/run-in-env.sh python3 -m script.hassfest -p mypy_config entry: script/run-in-env.sh python3 -m script.hassfest -p mypy_config

View file

@ -6,6 +6,7 @@
# Home Assistant Core # Home Assistant Core
setup.cfg @home-assistant/core setup.cfg @home-assistant/core
pyproject.toml @home-assistant/core
/homeassistant/*.py @home-assistant/core /homeassistant/*.py @home-assistant/core
/homeassistant/helpers/ @home-assistant/core /homeassistant/helpers/ @home-assistant/core
/homeassistant/util/ @home-assistant/core /homeassistant/util/ @home-assistant/core

View file

@ -4,6 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "homeassistant" name = "homeassistant"
version = "2022.7.0.dev0"
license = {text = "Apache-2.0"} license = {text = "Apache-2.0"}
description = "Open-source home automation platform running on Python 3." description = "Open-source home automation platform running on Python 3."
readme = "README.rst" readme = "README.rst"
@ -21,7 +22,34 @@ classifiers = [
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Topic :: Home Automation", "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] [project.urls]
"Source Code" = "https://github.com/home-assistant/core" "Source Code" = "https://github.com/home-assistant/core"

View file

@ -28,6 +28,7 @@ pytest==7.1.1
requests_mock==1.9.2 requests_mock==1.9.2
respx==0.19.0 respx==0.19.0
stdlib-list==0.7.0 stdlib-list==0.7.0
tomli==2.0.1;python_version<"3.11"
tqdm==4.49.0 tqdm==4.49.0
types-atomicwrites==1.4.1 types-atomicwrites==1.4.1
types-croniter==1.0.0 types-croniter==1.0.0

View file

@ -1,6 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""Generate an updated requirements_all.txt.""" """Generate an updated requirements_all.txt."""
import configparser
import difflib import difflib
import importlib import importlib
import os import os
@ -12,6 +11,11 @@ import sys
from homeassistant.util.yaml.loader import load_yaml from homeassistant.util.yaml.loader import load_yaml
from script.hassfest.model import Integration from script.hassfest.model import Integration
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
COMMENT_REQUIREMENTS = ( COMMENT_REQUIREMENTS = (
"Adafruit_BBIO", "Adafruit_BBIO",
"avea", # depends on bluepy "avea", # depends on bluepy
@ -166,10 +170,10 @@ def explore_module(package, explore_children):
def core_requirements(): def core_requirements():
"""Gather core requirements out of setup.cfg.""" """Gather core requirements out of pyproject.toml."""
parser = configparser.ConfigParser() with open("pyproject.toml", "rb") as fp:
parser.read("setup.cfg") data = tomllib.load(fp)
return parser["options"]["install_requires"].strip().split("\n") return data["project"]["dependencies"]
def gather_recursive_requirements(domain, seen=None): def gather_recursive_requirements(domain, seen=None):

View file

@ -12,6 +12,7 @@ BASE = """
# Home Assistant Core # Home Assistant Core
setup.cfg @home-assistant/core setup.cfg @home-assistant/core
pyproject.toml @home-assistant/core
/homeassistant/*.py @home-assistant/core /homeassistant/*.py @home-assistant/core
/homeassistant/helpers/ @home-assistant/core /homeassistant/helpers/ @home-assistant/core
/homeassistant/util/ @home-assistant/core /homeassistant/util/ @home-assistant/core

View file

@ -1,31 +1,36 @@
"""Package metadata validation.""" """Package metadata validation."""
import configparser import sys
from homeassistant.const import REQUIRED_PYTHON_VER, __version__ from homeassistant.const import REQUIRED_PYTHON_VER, __version__
from .model import Config, Integration 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: def validate(integrations: dict[str, Integration], config: Config) -> None:
"""Validate project metadata keys.""" """Validate project metadata keys."""
metadata_path = config.root / "setup.cfg" metadata_path = config.root / "pyproject.toml"
parser = configparser.ConfigParser() with open(metadata_path, "rb") as fp:
parser.read(metadata_path) data = tomllib.load(fp)
try: try:
if parser["metadata"]["version"] != __version__: if data["project"]["version"] != __version__:
config.add_error( config.add_error(
"metadata", f"'metadata.version' value does not match '{__version__}'" "metadata", f"'project.version' value does not match '{__version__}'"
) )
except KeyError: except KeyError:
config.add_error("metadata", "No 'metadata.version' key found!") config.add_error("metadata", "No 'metadata.version' key found!")
required_py_version = f">={'.'.join(map(str, REQUIRED_PYTHON_VER))}" required_py_version = f">={'.'.join(map(str, REQUIRED_PYTHON_VER))}"
try: try:
if parser["options"]["python_requires"] != required_py_version: if data["project"]["requires-python"] != required_py_version:
config.add_error( config.add_error(
"metadata", "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: except KeyError:
config.add_error("metadata", "No 'options.python_requires' key found!") config.add_error("metadata", "No 'options.python_requires' key found!")

View file

@ -121,13 +121,13 @@ def write_version(version):
def write_version_metadata(version: Version) -> None: def write_version_metadata(version: Version) -> None:
"""Update setup.cfg file with new version.""" """Update pyproject.toml file with new version."""
with open("setup.cfg") as fp: with open("pyproject.toml", encoding="utf8") as fp:
content = fp.read() 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) fp.write(content)

View file

@ -1,36 +1,6 @@
[metadata] [metadata]
version = 2022.7.0.dev0
url = https://www.home-assistant.io/ 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] [flake8]
exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build exclude = .venv,.git,.tox,docs,venv,bin,lib,deps,build
max-complexity = 25 max-complexity = 25