[core] Migrate to pyproject.toml

This commit is contained in:
Jesse Hills 2024-05-14 16:00:37 +12:00
parent 921e56f2c6
commit 6cfa2236b5
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
7 changed files with 138 additions and 174 deletions

View File

@ -110,7 +110,7 @@ RUN if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
fi; \
pip3 install \
--break-system-packages --no-cache-dir --no-use-pep517 -e /esphome
--break-system-packages --no-cache-dir -e /esphome
# Settings for dashboard
ENV USERNAME="" PASSWORD=""
@ -160,7 +160,7 @@ RUN if [ "$TARGETARCH$TARGETVARIANT" = "armv7" ]; then \
export PIP_EXTRA_INDEX_URL="https://www.piwheels.org/simple"; \
fi; \
pip3 install \
--break-system-packages --no-cache-dir --no-use-pep517 -e /esphome
--break-system-packages --no-cache-dir -e /esphome
# Labels
LABEL \

View File

@ -1,3 +1,80 @@
[build-system]
requires = ["setuptools==69.2.0", "wheel~=0.43.0"]
build-backend = "setuptools.build_meta"
[project]
name = "esphome"
version = "2024.6.0-dev"
license = {text = "MIT"}
description = "Make creating custom firmwares for ESP32/ESP8266 super easy."
readme = "README.md"
authors = [
{name = "The ESPHome Authors", email = "esphome@nabucasa.com"}
]
keywords = ["home", "automation"]
classifiers = [
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: MIT License",
"Programming Language :: C++",
"Programming Language :: Python :: 3",
"Topic :: Home Automation",
]
requires-python = ">=3.9.0"
dependencies = [
"async_timeout==4.0.3;python_version<='3.10'",
"cryptography==42.0.2",
"voluptuous==0.14.2",
"PyYAML==6.0.1",
"paho-mqtt==1.6.1",
"colorama==0.4.6",
"icmplib==3.0.4",
"tornado==6.4",
"tzlocal==5.2", # from time
"tzdata>=2021.1", # from time
"pyserial==3.5",
"platformio==6.1.15", # When updating platformio, also update Dockerfile
"esptool==4.7.0",
"click==8.1.7",
"esphome-dashboard==20240412.0",
"aioesphomeapi==24.3.0",
"zeroconf==0.132.2",
"python-magic==0.4.27",
"ruamel.yaml==0.18.6", # dashboard_import
"pip>=21.3.1",
# esp-idf requires this, but doesn't bundle it by default
# https://github.com/espressif/esp-idf/blob/220590d599e134d7a5e7f1e683cc4550349ffbf8/requirements.txt#L24
"kconfiglib==13.7.1",
# esp-idf >= 5.0 requires this
"pyparsing >= 3.0",
# For autocompletion
"argcomplete>=2.0.0",
]
[project.urls]
"Documentation" = "https://esphome.io"
"Source Code" = "https://github.com/esphome/esphome"
"Bug Tracker" = "https://github.com/esphome/issues/issues"
"Feature Request Tracker" = "https://github.com/esphome/feature-requests/issues"
"Discord" = "https://discord.gg/KhAMKrd"
"Forum" = "https://community.home-assistant.io/c/esphome"
"Twitter" = "https://twitter.com/esphome_"
[project.scripts]
esphome = "esphome.__main__:main"
[tool.setuptools]
platforms = ["any"]
zip-safe = false
include-package-data = true
[tool.setuptools.packages.find]
include = ["esphome*"]
[tool.black]
target-version = ["py39", "py310"]
exclude = 'generated'

View File

@ -1,29 +1,25 @@
async_timeout==4.0.3; python_version <= "3.10"
cryptography==42.0.2
voluptuous==0.14.2
# Automatically generated by gen_requirements.py, do not edit
PyYAML==6.0.1
paho-mqtt==1.6.1
colorama==0.4.6
icmplib==3.0.4
tornado==6.4
tzlocal==5.2 # from time
tzdata>=2021.1 # from time
pyserial==3.5
platformio==6.1.15 # When updating platformio, also update Dockerfile
esptool==4.7.0
click==8.1.7
esphome-dashboard==20240412.0
aioesphomeapi==24.3.0
zeroconf==0.132.2
python-magic==0.4.27
ruamel.yaml==0.18.6 # dashboard_import
# esp-idf requires this, but doesn't bundle it by default
# https://github.com/espressif/esp-idf/blob/220590d599e134d7a5e7f1e683cc4550349ffbf8/requirements.txt#L24
kconfiglib==13.7.1
# esp-idf >= 5.0 requires this
pyparsing >= 3.0
# For autocompletion
argcomplete>=2.0.0
async_timeout==4.0.3;python_version<='3.10'
click==8.1.7
colorama==0.4.6
cryptography==42.0.2
esphome-dashboard==20240412.0
esptool==4.7.0
icmplib==3.0.4
kconfiglib==13.7.1
paho-mqtt==1.6.1
pip>=21.3.1
platformio==6.1.15
pyparsing >= 3.0
pyserial==3.5
python-magic==0.4.27
ruamel.yaml==0.18.6
tornado==6.4
tzdata>=2021.1
tzlocal==5.2
voluptuous==0.14.2
zeroconf==0.132.2

34
script/gen_requirements.py Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
"""Generate updated requirements file."""
from __future__ import annotations
import os
from pathlib import Path
import sys
import tomllib
def main() -> int:
"""Run the script."""
if not os.path.isfile("requirements.txt"):
print("Run this from ESPHome root dir")
return 1
with open("pyproject.toml", "rb") as fp:
data = tomllib.load(fp)
dependencies: list[str] = sorted(data["project"]["dependencies"])
output = [f"# Automatically generated by {Path(__file__).name}, do not edit\n\n"]
output.append("\n".join(dependencies))
output.append("\n")
reqs = "".join(output)
with open("requirements.txt", "w", encoding="utf-8") as fp:
fp.write(reqs)
return 0
if __name__ == "__main__":
sys.exit(main())

View File

@ -10,17 +10,17 @@ if [ ! -n "$DEVCONTAINER" ] && [ ! -n "$VIRTUAL_ENV" ] && [ ! "$ESPHOME_NO_VENV"
if [ -f venv/Scripts/activate ]; then
location="venv/Scripts/activate"
fi
source $location;
source $location
fi
# Avoid unsafe git error when running inside devcontainer
if [ -n "$DEVCONTAINER" ];then
if [ -n "$DEVCONTAINER" ]; then
git config --global --add safe.directory "$PWD"
fi
pip3 install -r requirements.txt -r requirements_optional.txt -r requirements_test.txt -r requirements_dev.txt
pip3 install setuptools wheel
pip3 install --no-use-pep517 -e .
pip3 install -e . --config-settings editable_mode=compat
pre-commit install

View File

@ -1,61 +0,0 @@
[metadata]
license = MIT
license_file = LICENSE
platforms = any
description = Make creating custom firmwares for ESP32/ESP8266 super easy.
long_description = file: README.md
keywords = home, automation
classifier =
Environment :: Console
Intended Audience :: Developers
Intended Audience :: End Users/Desktop
License :: OSI Approved :: MIT License
Programming Language :: C++
Programming Language :: Python :: 3
Topic :: Home Automation
[flake8]
max-line-length = 120
# Following 4 for black compatibility
# E501: line too long
# W503: Line break occurred before a binary operator
# E203: Whitespace before ':'
# D202 No blank lines allowed after function docstring
# TODO fix flake8
# D100 Missing docstring in public module
# D101 Missing docstring in public class
# D102 Missing docstring in public method
# D103 Missing docstring in public function
# D104 Missing docstring in public package
# D105 Missing docstring in magic method
# D107 Missing docstring in __init__
# D200 One-line docstring should fit on one line with quotes
# D205 1 blank line required between summary line and description
# D209 Multi-line docstring closing quotes should be on a separate line
# D400 First line should end with a period
# D401 First line should be in imperative mood
ignore =
E501,
W503,
E203,
D202,
D100,
D101,
D102,
D103,
D104,
D105,
D107,
D200,
D205,
D209,
D400,
D401,
exclude = api_pb2.py
[bdist_wheel]
universal = 1

View File

@ -1,82 +0,0 @@
#!/usr/bin/env python3
"""esphome setup script."""
import os
from setuptools import setup, find_packages
from esphome import const
PROJECT_NAME = "esphome"
PROJECT_PACKAGE_NAME = "esphome"
PROJECT_LICENSE = "MIT"
PROJECT_AUTHOR = "ESPHome"
PROJECT_COPYRIGHT = "2019, ESPHome"
PROJECT_URL = "https://esphome.io/"
PROJECT_EMAIL = "esphome@nabucasa.com"
PROJECT_GITHUB_USERNAME = "esphome"
PROJECT_GITHUB_REPOSITORY = "esphome"
PYPI_URL = f"https://pypi.python.org/pypi/{PROJECT_PACKAGE_NAME}"
GITHUB_PATH = f"{PROJECT_GITHUB_USERNAME}/{PROJECT_GITHUB_REPOSITORY}"
GITHUB_URL = f"https://github.com/{GITHUB_PATH}"
DOWNLOAD_URL = f"{GITHUB_URL}/archive/{const.__version__}.zip"
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, "requirements.txt")) as requirements_txt:
REQUIRES = requirements_txt.read().splitlines()
with open(os.path.join(here, "README.md")) as readme:
LONG_DESCRIPTION = readme.read()
# If you have problems importing platformio and esptool as modules you can set
# $ESPHOME_USE_SUBPROCESS to make ESPHome call their executables instead.
# This means they have to be in your $PATH.
if "ESPHOME_USE_SUBPROCESS" in os.environ:
# Remove platformio and esptool from requirements
REQUIRES = [
req
for req in REQUIRES
if not any(req.startswith(prefix) for prefix in ["platformio", "esptool"])
]
CLASSIFIERS = [
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"License :: OSI Approved :: MIT License",
"Programming Language :: C++",
"Programming Language :: Python :: 3",
"Topic :: Home Automation",
]
setup(
name=PROJECT_PACKAGE_NAME,
version=const.__version__,
license=PROJECT_LICENSE,
url=GITHUB_URL,
project_urls={
"Bug Tracker": "https://github.com/esphome/issues/issues",
"Feature Request Tracker": "https://github.com/esphome/feature-requests/issues",
"Source Code": "https://github.com/esphome/esphome",
"Documentation": "https://esphome.io",
"Twitter": "https://twitter.com/esphome_",
},
download_url=DOWNLOAD_URL,
author=PROJECT_AUTHOR,
author_email=PROJECT_EMAIL,
description="Make creating custom firmwares for ESP32/ESP8266 super easy.",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
include_package_data=True,
zip_safe=False,
platforms="any",
test_suite="tests",
python_requires=">=3.9.0",
install_requires=REQUIRES,
keywords=["home", "automation"],
entry_points={"console_scripts": ["esphome = esphome.__main__:main"]},
packages=find_packages(include="esphome.*"),
)