forked from ni/niflexlogger-automation-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
123 lines (102 loc) · 4.11 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
import subprocess
import sys
from typing import List
from setuptools import find_namespace_packages, setup # type: ignore
from setuptools.command.build_py import build_py as BuildPyCommand # type: ignore
from setuptools.command.test import test as TestCommand # type: ignore
pypi_name = "niflexlogger-automation"
packages = find_namespace_packages(where="src", include=["flexlogger.*"])
PROTO_PATHS = [
"ConfigurationBasedSoftware/FlexLogger/Automation/FlexLogger.Automation.Protocols",
"Core/Automation/Core.Automation.Protocols",
"DiagramSdk/Automation/DiagramSdk.Automation.Protocols",
]
class GenerateProtobufAndBuildPyCommand(BuildPyCommand):
def run(self) -> None:
_generate_protobuf_classes()
super().run()
def _generate_protobuf_classes() -> None:
proc = subprocess.Popen(
[sys.executable, "generate_protobuf_classes.py"],
universal_newlines=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
(stdout_text, stderr_text) = proc.communicate()
if proc.returncode != 0:
print("stdout: " + stdout_text)
print("stderr: " + stderr_text)
raise RuntimeError("generate_protobuf_classes returned error code %d" % proc.returncode)
class PyTest(TestCommand):
def finalize_options(self) -> None:
TestCommand.finalize_options(self)
self.test_args = [] # type: List[str]
self.test_suite = True
def run_tests(self) -> None:
import pytest # type: ignore
pytest.main(self.test_args)
def _get_version(name: str) -> str:
import os
version = None
script_dir = os.path.dirname(os.path.realpath(__file__))
script_dir = os.path.join(script_dir, name)
if not os.path.exists(os.path.join(script_dir, "VERSION")):
version = "0.1.1"
else:
with open(os.path.join(script_dir, "VERSION"), "r") as version_file:
version = version_file.read().rstrip()
return version
def _read_contents(file_to_read: str) -> str:
with open(file_to_read, "r") as f:
return f.read()
def _build_protobuf_paths() -> List[str]:
# The package_data member does not support recursive ** globbing,
# so build up the paths here.
# Note that this path is relative to the flexlogger.automation package
# directory
return ["../../../protobuf/" + x + "/*.proto" for x in PROTO_PATHS]
setup(
name=pypi_name,
version=_get_version(pypi_name),
description="NI FlexLogger Python API",
long_description=_read_contents("README.rst"),
author="National Instruments",
maintainer="Ben Parrott, Greg Stoll",
maintainer_email="ben.parrott@ni.com, greg.stoll@ni.com",
keywords=["niflexlogger", "flexlogger"],
license="MIT",
packages=packages,
scripts=["generate_protobuf_classes.py"],
install_requires=[
"typing-extensions",
"grpcio",
"grpcio-tools",
"psutil",
# This package only works correctly on Windows,
# but add this specifier to allow installing it on
# Linux, which is helpful for pypi builds and readthedocs.
"pywin32; platform_system=='Windows'",
"console-menu",
"PrettyTable",
],
setup_requires=["grpcio", "grpcio-tools"],
tests_require=["pytest", "mypy", "npTDMS", "pytest-timeout", "psutil"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Manufacturing",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering",
"Topic :: System :: Hardware",
],
cmdclass={"test": PyTest, "build_py": GenerateProtobufAndBuildPyCommand},
package_data={"": ["VERSION", "*.pyi", "py.typed"] + _build_protobuf_paths()},
package_dir={"": "src"},
)