aboutsummaryrefslogtreecommitdiffstats
path: root/setup.py
blob: f61a0f2a4219bfb45a1fbd95d73dbfad96198aa8 (plain)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# =============================================================================
#               ____ _   _ ____  _
#  _ __  _   _ / ___| | | |  _ \| |
# | '_ \| | | | |  _| |_| | | | | |
# | |_) | |_| | |_| |  _  | |_| | |___
# | .__/ \__, |\____|_| |_|____/|_____|
# |_|    |___/
# =============================================================================
#  Authors:
#    Tristan Gingold
#    Patrick Lehmann
#    Unai Martinez-Corral
#
# Package installer:  Python binding for GHDL and high-level APIs.
#
# License:
# ============================================================================
#  Copyright (C) 2019-2021 Tristan Gingold
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <gnu.org/licenses>.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ============================================================================

from pathlib import Path
from re import compile as re_compile
from typing import List

from setuptools import (
    setup as setuptools_setup,
    find_packages as setuptools_find_packages,
)

gitHubNamespace = "ghdl"
projectName = "ghdl"
packageName = "pyGHDL"
packagePath = Path(packageName)

readmeFile = packagePath / "README.md"
requirementsFile = packagePath / "requirements.txt"


# Read (local) README for upload to PyPI
def get_description(file: Path) -> str:
    with file.open("r") as fh:
        description = fh.read()
    return description


# Read requirements file and add them to package dependency list
def get_requirements(file: Path) -> List[str]:
    requirements = []
    with file.open("r") as fh:
        for line in fh.read().splitlines():
            if line.startswith("#") or line == "":
                continue
            elif line.startswith("-r"):
                # Remove the first word/argument (-r)
                filename = " ".join(line.split(" ")[1:])
                requirements += get_requirements(file.parent / filename)
            elif line.startswith("https"):
                # Convert 'URL#NAME' to 'NAME @ URL'
                splitItems = line.split("#")
                requirements.append("{} @ {}".format(splitItems[1], splitItems[0]))
            else:
                requirements.append(line)
    return requirements


def get_version():
    # Try from version.py.  Reads it to avoid loading the shared library.
    pattern = re_compile('^__version__ = "(.*)"\n')
    try:
        line = open("pyGHDL/libghdl/version.py").read()
        match = pattern.match(line)
        if match:
            return match.group(1)
    except Exception:
        pass

    raise Exception("Cannot find version")


# Derive URLs
sourceCodeURL = "https://github.com/{namespace}/{projectName}".format(
    namespace=gitHubNamespace, projectName=projectName
)
documentationURL = (
    "https://{namespace}.github.io/{projectName}/using/py/index.html".format(
        namespace=gitHubNamespace, projectName=projectName
    )
)
requirements = list(set(get_requirements(requirementsFile)))


# Assemble all package information
setuptools_setup(
    name=packageName,
    version=get_version(),
    author="Tristan Gingold",
    author_email="tgingold@free.fr",
    license="GPL-2.0-or-later",
    description="Python binding for GHDL and high-level APIs (incl. LSP).",
    long_description=get_description(readmeFile),
    long_description_content_type="text/markdown",
    url=sourceCodeURL,
    project_urls={
        "Documentation": documentationURL,
        "Source Code": sourceCodeURL,
        "Issue Tracker": sourceCodeURL + "/issues",
    },
    python_requires=">=3.6",
    install_requires=requirements,
    packages=setuptools_find_packages(exclude=("tests",)),
    entry_points={
        "console_scripts": [
            "ghdl-ls = pyGHDL.cli.lsp:main",
            "ghdl-dom = pyGHDL.cli.dom:main",
        ]
    },
    keywords="Python3 VHDL Parser Compiler Simulator GHDL",
    classifiers=[
        "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
        "Operating System :: MacOS",
        "Operating System :: Microsoft :: Windows :: Windows 10",
        "Operating System :: POSIX :: Linux",
        "Programming Language :: Python :: 3 :: Only",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: 3.9",
        "Development Status :: 4 - Beta",
        # "Development Status :: 5 - Production/Stable",
        "Intended Audience :: Developers",
        "Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)",
        "Topic :: Software Development :: Code Generators",
        "Topic :: Software Development :: Compilers",
        "Topic :: Software Development :: Testing",
        "Topic :: Utilities",
    ],
)