-
Notifications
You must be signed in to change notification settings - Fork 69
/
setup.py
137 lines (115 loc) · 4.12 KB
/
setup.py
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
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/python3
"""Setup script for Home Assistant CLI."""
import codecs
from datetime import datetime as dt
import os
import re
import subprocess
from setuptools import find_packages, setup
# shared consts using approach suggested at
# https://stackoverflow.com/questions/17583443/what-is-the-correct-way-to-share-package-version-with-setup-py-and-the-package
def read(*parts):
"""Read file from current directory."""
here = os.path.abspath(os.path.dirname(__file__))
with codecs.open(os.path.join(here, *parts), 'r') as infofile:
return infofile.read()
def find_version(*file_paths):
"""Locate version info to share between const.py and setup.py."""
version_file = read(*file_paths) # type: ignore
version_match = re.search(
r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M
)
if version_match:
return version_match.group(1)
raise RuntimeError("Unable to find version string.")
def get_git_commit_datetime() -> str:
"""Return timestamp from last commit."""
try:
commit_timestamp = subprocess.check_output(
"git show -s --format=%ct", shell=True, stderr=subprocess.STDOUT
)
datetime_object = dt.fromtimestamp(int(commit_timestamp))
return f"{datetime_object:%Y%m%d%H%M%S}"
except subprocess.CalledProcessError as cpe:
print(cpe.output)
return "00000000000000"
__VERSION__ = find_version("homeassistant_cli", "const.py") # type: ignore
# Append a suffix to the version for dev builds
if 'dev' in __VERSION__:
__VERSION__ = f'{__VERSION__}{get_git_commit_datetime()}'
REQUIRED_PYTHON_VER = (3, 11, 0)
PROJECT_NAME = 'Home Assistant CLI'
PROJECT_PACKAGE_NAME = 'homeassistant-cli'
PROJECT_LICENSE = 'Apache License 2.0'
PROJECT_AUTHOR = 'The Home Assistant CLI Authors'
PROJECT_COPYRIGHT = f' 2018-{dt.now().year}, {PROJECT_AUTHOR}'
PROJECT_URL = 'https://github.com/home-assistant-ecosystem/home-assistant-cli'
PROJECT_EMAIL = '[email protected]'
PROJECT_GITHUB_USERNAME = 'home-assistant-ecosystem'
PROJECT_GITHUB_REPOSITORY = 'home-assistant-cli'
PYPI_URL = f'https://pypi.python.org/pypi/{PROJECT_PACKAGE_NAME}'
GITHUB_PATH = '{}/{}'.format(
PROJECT_GITHUB_USERNAME, PROJECT_GITHUB_REPOSITORY
)
GITHUB_URL = f'https://github.com/{GITHUB_PATH}'
DOWNLOAD_URL = f'{GITHUB_URL}/archive/{__VERSION__}.zip'
PROJECT_URLS = {
'Bug Reports': f'{GITHUB_URL}/issues',
'Dev Docs': 'https://developers.home-assistant.io/',
'Discord': 'https://discordapp.com/invite/c5DvZ4e',
'Forum': 'https://community.home-assistant.io/',
}
PACKAGES = find_packages(exclude=['tests', 'tests.*'])
REQUIRES = [
'aiohttp>=3.9,<4',
'click-log>=0.4,<0.5',
'click>=8,<9',
'dateparser>=0.7.1,<1.2',
'jinja2>=2.10',
'jsonpath-ng>=1.5.1,<2',
'netdisco>=3.0.0,<4',
'regex>=2024.5',
'ruamel.yaml>=0.17,<0.18',
'requests>=2.28.0,<3',
'tabulate>=0.9,<0.10',
]
# Should be as close to Home Assistant dev/master as possible
TESTS_REQUIRE = [
'black>=24.3,<30',
'codecov>=2.0.15,<3',
'coveralls>=1.2.0,<2',
'flake8>=3.9,<4',
'flake8-docstrings>=1.3.0,<2',
'mock-open>=1.4,<1.5',
'mypy>=0.800,<0.900',
'pydocstyle>=6,<7',
'pylint>=2.7,<3',
'pytest>=8,<9',
'pytest-cov>=2.11,<3',
'pytest-sugar>=0.9.4,<0.10',
'pytest-timeout>=2,<3',
'requests_mock>=1.8.0,<2',
'twine>=1.13.0,<2',
'wheel>=0.33.1,<0.40', # Otherwise setup.py bdist_wheel does not work
]
MIN_PY_VERSION = '.'.join(map(str, REQUIRED_PYTHON_VER))
# Allow you to run pip0 install .[test] to get test dependencies included
EXTRAS_REQUIRE = {'test': TESTS_REQUIRE}
setup(
name=PROJECT_PACKAGE_NAME,
version=__VERSION__,
url=PROJECT_URL,
download_url=DOWNLOAD_URL,
project_urls=PROJECT_URLS,
author=PROJECT_AUTHOR,
author_email=PROJECT_EMAIL,
packages=PACKAGES,
include_package_data=True,
zip_safe=False,
install_requires=REQUIRES,
tests_require=TESTS_REQUIRE,
extras_require=EXTRAS_REQUIRE,
python_requires=f'>={MIN_PY_VERSION}',
test_suite='tests',
entry_points={'console_scripts': ['hass-cli = homeassistant_cli.cli:run']},
)