2015-07-08 23:22:58 +02:00
|
|
|
#!/usr/bin/env python
|
2016-05-25 00:43:16 +02:00
|
|
|
"""The setup and build script for the python-telegram-bot library."""
|
2021-01-30 14:15:39 +01:00
|
|
|
import subprocess
|
2022-04-24 12:38:09 +02:00
|
|
|
import sys
|
2022-08-26 06:50:03 +02:00
|
|
|
from collections import defaultdict
|
2022-05-05 09:27:54 +02:00
|
|
|
from pathlib import Path
|
2024-02-29 19:11:03 +01:00
|
|
|
from typing import Any, Dict, List, Tuple
|
2020-02-02 21:56:25 +01:00
|
|
|
|
2022-05-05 09:27:54 +02:00
|
|
|
from setuptools import find_packages, setup
|
2015-07-08 23:22:58 +02:00
|
|
|
|
|
|
|
|
2024-02-29 19:11:03 +01:00
|
|
|
def get_requirements() -> List[str]:
|
2015-11-10 15:27:18 +01:00
|
|
|
"""Build the requirements list for this project"""
|
|
|
|
requirements_list = []
|
|
|
|
|
2024-02-29 19:11:03 +01:00
|
|
|
with Path("requirements.txt").open(encoding="utf-8") as reqs:
|
2021-01-30 14:15:39 +01:00
|
|
|
for install in reqs:
|
2022-10-31 10:12:18 +01:00
|
|
|
if install.startswith("#"):
|
2021-01-30 14:15:39 +01:00
|
|
|
continue
|
2015-11-10 15:27:18 +01:00
|
|
|
requirements_list.append(install.strip())
|
|
|
|
|
|
|
|
return requirements_list
|
|
|
|
|
2016-08-10 21:39:14 +02:00
|
|
|
|
2024-02-29 19:11:03 +01:00
|
|
|
def get_packages_requirements(raw: bool = False) -> Tuple[List[str], List[str]]:
|
2021-01-30 14:15:39 +01:00
|
|
|
"""Build the package & requirements list for this project"""
|
2022-10-31 10:12:18 +01:00
|
|
|
reqs = get_requirements()
|
2020-02-02 21:56:25 +01:00
|
|
|
|
2024-03-06 22:04:19 +01:00
|
|
|
exclude = ["tests*", "docs*"]
|
2021-01-30 14:15:39 +01:00
|
|
|
if raw:
|
2022-05-05 17:40:22 +02:00
|
|
|
exclude.append("telegram.ext*")
|
2021-01-30 14:15:39 +01:00
|
|
|
|
|
|
|
packs = find_packages(exclude=exclude)
|
|
|
|
|
|
|
|
return packs, reqs
|
|
|
|
|
|
|
|
|
2024-02-29 19:11:03 +01:00
|
|
|
def get_optional_requirements(raw: bool = False) -> Dict[str, List[str]]:
|
2022-08-26 06:50:03 +02:00
|
|
|
"""Build the optional dependencies"""
|
|
|
|
requirements = defaultdict(list)
|
|
|
|
|
2024-02-29 19:11:03 +01:00
|
|
|
with Path("requirements-opts.txt").open(encoding="utf-8") as reqs:
|
2022-08-26 06:50:03 +02:00
|
|
|
for line in reqs:
|
2024-02-29 19:11:03 +01:00
|
|
|
effective_line = line.strip()
|
|
|
|
if not effective_line or effective_line.startswith("#"):
|
2022-08-26 06:50:03 +02:00
|
|
|
continue
|
2024-02-29 19:11:03 +01:00
|
|
|
dependency, names = effective_line.split("#")
|
2022-08-26 06:50:03 +02:00
|
|
|
dependency = dependency.strip()
|
|
|
|
for name in names.split(","):
|
2024-02-29 19:11:03 +01:00
|
|
|
effective_name = name.strip()
|
|
|
|
if effective_name.endswith("!ext"):
|
2022-08-27 13:23:17 +02:00
|
|
|
if raw:
|
|
|
|
continue
|
2024-02-29 19:11:03 +01:00
|
|
|
effective_name = effective_name[:-4]
|
|
|
|
requirements["ext"].append(dependency)
|
|
|
|
requirements[effective_name].append(dependency)
|
2022-10-31 10:12:18 +01:00
|
|
|
requirements["all"].append(dependency)
|
2022-08-26 06:50:03 +02:00
|
|
|
|
|
|
|
return requirements
|
|
|
|
|
|
|
|
|
2024-02-29 19:11:03 +01:00
|
|
|
def get_setup_kwargs(raw: bool = False) -> Dict[str, Any]:
|
2021-01-30 14:15:39 +01:00
|
|
|
"""Builds a dictionary of kwargs for the setup function"""
|
|
|
|
packages, requirements = get_packages_requirements(raw=raw)
|
|
|
|
|
|
|
|
raw_ext = "-raw" if raw else ""
|
2021-10-05 19:50:11 +02:00
|
|
|
readme = Path(f'README{"_RAW" if raw else ""}.rst')
|
2017-03-11 15:51:20 +01:00
|
|
|
|
2024-02-29 19:11:03 +01:00
|
|
|
version_file = Path("telegram/_version.py").read_text(encoding="utf-8")
|
2022-05-14 15:50:12 +02:00
|
|
|
first_part = version_file.split("# SETUP.PY MARKER")[0]
|
2024-02-29 19:11:03 +01:00
|
|
|
exec(first_part) # pylint: disable=exec-used
|
|
|
|
|
|
|
|
return {
|
|
|
|
"script_name": f"setup{raw_ext}.py",
|
|
|
|
"name": f"python-telegram-bot{raw_ext}",
|
|
|
|
"version": locals()["__version__"],
|
|
|
|
"author": "Leandro Toledo",
|
|
|
|
"author_email": "devs@python-telegram-bot.org",
|
|
|
|
"license": "LGPLv3",
|
|
|
|
"url": "https://python-telegram-bot.org/",
|
|
|
|
# Keywords supported by PyPI can be found at
|
|
|
|
# https://github.com/pypa/warehouse/blob/aafc5185e57e67d43487ce4faa95913dd4573e14/
|
|
|
|
# warehouse/templates/packaging/detail.html#L20-L58
|
|
|
|
"project_urls": {
|
2022-06-09 17:08:54 +02:00
|
|
|
"Documentation": "https://docs.python-telegram-bot.org",
|
2021-10-05 19:50:11 +02:00
|
|
|
"Bug Tracker": "https://github.com/python-telegram-bot/python-telegram-bot/issues",
|
|
|
|
"Source Code": "https://github.com/python-telegram-bot/python-telegram-bot",
|
|
|
|
"News": "https://t.me/pythontelegrambotchannel",
|
2022-06-09 17:08:54 +02:00
|
|
|
"Changelog": "https://docs.python-telegram-bot.org/en/stable/changelog.html",
|
2021-10-05 19:50:11 +02:00
|
|
|
},
|
2024-02-29 19:11:03 +01:00
|
|
|
"download_url": f"https://pypi.org/project/python-telegram-bot{raw_ext}/",
|
|
|
|
"keywords": "python telegram bot api wrapper",
|
|
|
|
"description": "We have made you a wrapper you can't refuse",
|
|
|
|
"long_description": readme.read_text(encoding="utf-8"),
|
|
|
|
"long_description_content_type": "text/x-rst",
|
|
|
|
"packages": packages,
|
|
|
|
"install_requires": requirements,
|
|
|
|
"extras_require": get_optional_requirements(raw=raw),
|
|
|
|
"include_package_data": True,
|
|
|
|
"classifiers": [
|
2022-05-05 17:40:22 +02:00
|
|
|
"Development Status :: 5 - Production/Stable",
|
|
|
|
"Intended Audience :: Developers",
|
|
|
|
"License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)",
|
|
|
|
"Operating System :: OS Independent",
|
|
|
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
|
|
"Topic :: Communications :: Chat",
|
|
|
|
"Topic :: Internet",
|
|
|
|
"Programming Language :: Python",
|
|
|
|
"Programming Language :: Python :: 3",
|
|
|
|
"Programming Language :: Python :: 3.8",
|
|
|
|
"Programming Language :: Python :: 3.9",
|
|
|
|
"Programming Language :: Python :: 3.10",
|
2022-08-17 18:24:50 +02:00
|
|
|
"Programming Language :: Python :: 3.11",
|
2023-08-21 18:27:02 +02:00
|
|
|
"Programming Language :: Python :: 3.12",
|
2021-10-05 19:50:11 +02:00
|
|
|
],
|
2024-02-29 19:11:03 +01:00
|
|
|
"python_requires": ">=3.8",
|
|
|
|
}
|
2021-01-30 14:15:39 +01:00
|
|
|
|
|
|
|
|
2024-02-29 19:11:03 +01:00
|
|
|
def main() -> None:
|
2021-01-30 14:15:39 +01:00
|
|
|
# If we're building, build ptb-raw as well
|
2022-05-05 17:40:22 +02:00
|
|
|
if set(sys.argv[1:]) in [{"bdist_wheel"}, {"sdist"}, {"sdist", "bdist_wheel"}]:
|
2024-02-29 19:11:03 +01:00
|
|
|
args = ["python", "setup_raw.py"]
|
2021-01-30 14:15:39 +01:00
|
|
|
args.extend(sys.argv[1:])
|
|
|
|
subprocess.run(args, check=True, capture_output=True)
|
|
|
|
|
|
|
|
setup(**get_setup_kwargs(raw=False))
|
|
|
|
|
|
|
|
|
2022-05-05 17:40:22 +02:00
|
|
|
if __name__ == "__main__":
|
2021-01-30 14:15:39 +01:00
|
|
|
main()
|