1# SPDX-FileCopyrightText: 2014-2023 Fredrik Ahlberg, Angus Gratton,
2# Espressif Systems (Shanghai) CO LTD, other contributors as noted.
3#
4# SPDX-License-Identifier: GPL-2.0-or-later
5
6import io
7import os
8import re
9import sys
10
11try:
12    from setuptools import find_packages, setup
13except ImportError:
14    print(
15        "Package setuptools is missing from your Python installation. "
16        "Please see the installation section in the esptool documentation"
17        " for instructions on how to install it."
18    )
19    exit(1)
20
21
22# Example code to pull version from esptool module with regex, taken from
23# https://packaging.python.org/en/latest/guides/single-sourcing-package-version/
24def read(*names, **kwargs):
25    with io.open(
26        os.path.join(os.path.dirname(__file__), *names),
27        encoding=kwargs.get("encoding", "utf8"),
28    ) as fp:
29        return fp.read()
30
31
32def find_version(*file_paths):
33    version_file = read(*file_paths)
34    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M)
35    if version_match:
36        return version_match.group(1)
37    raise RuntimeError("Unable to find version string.")
38
39
40if os.name != "nt":
41    scripts = ["esptool.py", "espefuse.py", "espsecure.py"]
42    entry_points = {}
43else:
44    scripts = []
45    entry_points = {
46        "console_scripts": [
47            "esptool.py=esptool.__init__:_main",
48            "espsecure.py=espsecure.__init__:_main",
49            "espefuse.py=espefuse.__init__:_main",
50        ],
51    }
52
53
54long_description = """
55==========
56esptool.py
57==========
58A Python-based, open-source, platform-independent utility to communicate with \
59the ROM bootloader in Espressif chips.
60
61The esptool.py project is `hosted on github <https://github.com/espressif/esptool>`_.
62
63Documentation
64-------------
65Visit online `esptool documentation <https://docs.espressif.com/projects/esptool/>`_ \
66or run ``esptool.py -h``.
67
68Contributing
69------------
70Please see the `contributions guide \
71<https://docs.espressif.com/projects/esptool/en/latest/contributing.html>`_.
72"""
73
74setup(
75    name="esptool",
76    version=find_version("esptool/__init__.py"),
77    description="A serial utility to communicate & flash code to Espressif chips.",
78    long_description=long_description,
79    url="https://github.com/espressif/esptool/",
80    project_urls={
81        "Documentation": "https://docs.espressif.com/projects/esptool/",
82        "Source": "https://github.com/espressif/esptool/",
83        "Tracker": "https://github.com/espressif/esptool/issues/",
84    },
85    author="Fredrik Ahlberg (themadinventor) & Angus Gratton (projectgus) "
86    "& Espressif Systems",
87    author_email="",
88    license="GPLv2+",
89    classifiers=[
90        "Development Status :: 5 - Production/Stable",
91        "Intended Audience :: Developers",
92        "Natural Language :: English",
93        "Operating System :: POSIX",
94        "Operating System :: Microsoft :: Windows",
95        "Operating System :: MacOS :: MacOS X",
96        "Topic :: Software Development :: Embedded Systems",
97        "Environment :: Console",
98        "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
99        "Programming Language :: Python :: 3.7",
100        "Programming Language :: Python :: 3.8",
101        "Programming Language :: Python :: 3.9",
102        "Programming Language :: Python :: 3.10",
103    ],
104    python_requires=">=3.7",
105    setup_requires=(["wheel"] if "bdist_wheel" in sys.argv else []),
106    extras_require={
107        "dev": [
108            "flake8>=3.2.0",
109            "flake8-import-order",
110            "flake8-gl-codeclimate",
111            "pyelftools",
112            "coverage~=6.0",
113            "black",
114            "pre-commit",
115            "pytest",
116            "pytest-rerunfailures",
117        ],
118        "hsm": [
119            "python-pkcs11",
120        ],
121    },
122    install_requires=[
123        "bitstring>=3.1.6",
124        "cryptography>=2.1.4",
125        "ecdsa>=0.16.0",
126        "pyserial>=3.0",
127        "reedsolo>=1.5.3,<=1.6.0",
128    ],
129    packages=find_packages(),
130    include_package_data=True,
131    package_data={"": ["esptool/targets/stub_flasher/*.json"]},
132    entry_points=entry_points,
133    scripts=scripts,
134)
135