-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
158 lines (137 loc) · 4.99 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# This file is part of nakivo_prometheus_exporter package
__intname__ = "nakivo_prometheus_exporter.setup"
__author__ = "Orsiris de Jong"
__copyright__ = "Copyright (C) 2024 NetInvent"
__license__ = "GPL-3.0-only"
__build__ = "2024032601"
__setup_ver__ = "1.0.0"
PACKAGE_NAME = "nakivo_prometheus_exporter"
DESCRIPTION = "Connecto to Nakivo API and export metrics to Prometheus"
import sys
import os
import pkg_resources
import setuptools
def _read_file(filename):
here = os.path.abspath(os.path.dirname(__file__))
if sys.version_info[0] < 3:
# With python 2.7, open has no encoding parameter, resulting in TypeError
# Fix with io.open (slow but works)
from io import open as io_open
try:
with io_open(
os.path.join(here, filename), "r", encoding="utf-8"
) as file_handle:
return file_handle.read()
except IOError:
# Ugly fix for missing requirements.txt file when installing via pip under Python 2
return ""
else:
with open(os.path.join(here, filename), "r", encoding="utf-8") as file_handle:
return file_handle.read()
def get_metadata(package_file):
"""
Read metadata from package file
"""
_metadata = {}
for line in _read_file(package_file).splitlines():
if line.startswith("__version__") or line.startswith("__description__"):
delim = "="
_metadata[line.split(delim)[0].strip().strip("__")] = (
line.split(delim)[1].strip().strip("'\"")
)
return _metadata
def parse_requirements(filename):
"""
There is a parse_requirements function in pip but it keeps changing import path
Let's build a simple one
"""
try:
requirements_txt = _read_file(filename)
install_requires = [
str(requirement)
for requirement in pkg_resources.parse_requirements(requirements_txt)
]
print(install_requires)
return install_requires
except OSError:
print(
'WARNING: No requirements.txt file found as "{}". Please check path or create an empty one'.format(
filename
)
)
# With this, we can enforce a binary package.
class BinaryDistribution(setuptools.Distribution):
"""Distribution which always forces a binary package with platform name"""
@staticmethod
def has_ext_modules():
return True
package_path = os.path.abspath(PACKAGE_NAME)
for path in ["__main__.py", PACKAGE_NAME + ".py"]:
package_file = os.path.join(package_path, "__version__.py")
if os.path.isfile(package_file):
break
metadata = get_metadata(package_file)
requirements = parse_requirements(
os.path.join(package_path, os.pardir, "requirements.txt")
)
long_description = _read_file("README.md")
console_scripts = [
"nakivo_prometheus_exporter = nakivo_prometheus_exporter.server:main"
]
setuptools.setup(
name=PACKAGE_NAME,
# We may use find_packages in order to not specify each package manually
# packages = ['command_runner'],
packages=setuptools.find_packages(),
version=metadata["version"],
install_requires=requirements,
classifiers=[
# command_runner is mature
"Development Status :: 5 - Production/Stable",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: System Administrators",
"Intended Audience :: Information Technology",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Topic :: System :: Archiving :: Backup",
"Topic :: System",
"Topic :: System :: Monitoring",
"Topic :: Utilities",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Operating System :: POSIX :: Linux",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
],
description=DESCRIPTION,
license="GPLv3",
author="NetInvent - Orsiris de Jong",
author_email="[email protected]",
url="https://github.com/netinvent/nakivo_prometheus_exporter",
keywords=[
"shell",
"backup",
"prometheus",
"linux",
"cli",
],
long_description=long_description,
long_description_content_type="text/markdown",
python_requires=">=3.6",
entry_points={
"console_scripts": console_scripts,
},
# As we do version specific hacks for installed inline copies, make the
# wheel version and platform specific.
# distclass=BinaryDistribution,
)