forked from esphome/aioesphomeapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
127 lines (103 loc) · 3.56 KB
/
setup.py
File metadata and controls
127 lines (103 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
"""aioesphomeapi setup script."""
import contextlib
from distutils.command.build_ext import build_ext
import os
from pathlib import Path
from typing import Any
from setuptools import find_packages, setup
try:
from setuptools import Extension
except ImportError:
from distutils.core import Extension
TO_CYTHONIZE = [
"aioesphomeapi/_sanitize.py",
"aioesphomeapi/client_base.py",
"aioesphomeapi/connection.py",
"aioesphomeapi/_frame_helper/base.py",
"aioesphomeapi/_frame_helper/noise.py",
"aioesphomeapi/_frame_helper/noise_encryption.py",
"aioesphomeapi/_frame_helper/packets.py",
"aioesphomeapi/_frame_helper/plain_text.py",
"aioesphomeapi/_frame_helper/pack.pyx",
]
EXTENSIONS = [
Extension(
ext.removesuffix(".py").removesuffix(".pyx").replace("/", "."),
[ext],
language="c",
extra_compile_args=["-O3", "-g0"],
)
for ext in TO_CYTHONIZE
]
here = Path(__file__).parent.resolve()
with (here / "README.rst").open(encoding="utf-8") as readme_file:
long_description = readme_file.read()
VERSION = "45.3.0"
PROJECT_NAME = "aioesphomeapi"
PROJECT_PACKAGE_NAME = "aioesphomeapi"
PROJECT_LICENSE = "MIT"
PROJECT_AUTHOR = "Otto Winter"
PROJECT_COPYRIGHT = " 2019-2020, Otto Winter"
PROJECT_URL = "https://esphome.io/"
PROJECT_EMAIL = "esphome@nabucasa.com"
PROJECT_GITHUB_USERNAME = "esphome"
PROJECT_GITHUB_REPOSITORY = "aioesphomeapi"
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/{VERSION}.zip"
with (here / "requirements" / "base.txt").open() as requirements_txt:
REQUIRES = requirements_txt.read().splitlines()
pkgs = find_packages(exclude=["tests", "tests.*"])
setup_kwargs = {
"name": PROJECT_PACKAGE_NAME,
"version": VERSION,
"url": PROJECT_URL,
"download_url": DOWNLOAD_URL,
"author": PROJECT_AUTHOR,
"author_email": PROJECT_EMAIL,
"description": "Python API for interacting with ESPHome devices.",
"long_description": long_description,
"license": PROJECT_LICENSE,
"packages": pkgs,
"exclude_package_data": {pkg: ["*.c"] for pkg in pkgs},
"include_package_data": True,
"zip_safe": False,
"install_requires": REQUIRES,
"python_requires": ">=3.11",
"test_suite": "tests",
"entry_points": {
"console_scripts": [
"aioesphomeapi-logs=aioesphomeapi.log_reader:cli_entry_point",
"aioesphomeapi-discover=aioesphomeapi.discover:cli_entry_point",
],
},
}
class OptionalBuildExt(build_ext):
def build_extensions(self) -> None:
if self.parallel is None:
self.parallel = os.cpu_count() or 1
with contextlib.suppress(Exception):
super().build_extensions()
def cythonize_if_available(setup_kwargs: dict[str, Any]) -> None:
if os.environ.get("SKIP_CYTHON"):
return
try:
from Cython.Build import cythonize # noqa: PLC0415
setup_kwargs.update(
{
"ext_modules": cythonize(
EXTENSIONS,
compiler_directives={
"language_level": "3", # Python 3
"freethreading_compatible": True, # PEP 703
},
),
"cmdclass": {"build_ext": OptionalBuildExt},
}
)
except Exception:
if os.environ.get("REQUIRE_CYTHON"):
raise
cythonize_if_available(setup_kwargs)
setup(**setup_kwargs)