forked from ClusterLabs/pcs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py.in
131 lines (104 loc) · 3.85 KB
/
setup.py.in
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
#!@PYTHON@
import os
from setuptools import (
Command,
Distribution,
find_packages,
setup,
)
from setuptools.command.install import install
class CleanCommand(Command):
user_options = []
def initialize_options(self):
# pylint: disable=attribute-defined-outside-init
self.cwd = None
def finalize_options(self):
# pylint: disable=attribute-defined-outside-init
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, "Must be in package root: %s" % self.cwd
os.system("rm -rf ./build ./dist ./*.pyc ./*.egg-info")
# The following classes (_ScriptDirSpy, _SomeDir, ScriptDir, PlatLib, PureLib )
# allow to get some directories used by setuptools.
#
# The root reason for introduction `scriptdir` command was the error in
# setuptools, which caused wrong shebang in script files
# (see https://github.com/pypa/setuptools/issues/188 and
# https://bugzilla.redhat.com/1353934). As a workaround the shebang was
# corrected in pcs Makefile, however hardcoded path didn't work on some systems,
# so there was a need to get a reliable path to a script (or bin) directory.
#
# Alternative approach would be correct shebang here in `setup.py`. However, it
# would mean to deal with possible user options (like --root, --prefix,
# --install-lib etc. - or its combinations) consistently with setuptools (and it
# can be patched in some OS).
#
# Later it turn out that it is also necessary to obtain purelib/platlib in
# Makefile.
class _ScriptDirSpy(install):
"""
Fake install. Its task is to make the some paths accessible to a caller.
"""
def run(self):
self.distribution.install_scripts = self.install_scripts
self.distribution.install_purelib = self.install_purelib
self.distribution.install_platlib = self.install_platlib
class _SomeDir(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
"""
Print desired path (according to subclass) to stdout.
Unfortunately, setuptools automatically prints "running scriptdir" on
stdout. So, for example, the output will look like this (for example):
running scriptdir
/usr/local/bin
The shell command `tail` can be used to get only the relevant line:
`python setup.py scriptdir | tail --lines=1`
"""
# pylint: disable=no-self-use
# Create fake install to get a setuptools script directory path.
dist = Distribution({"cmdclass": {"install": _ScriptDirSpy}})
dist.dry_run = True
dist.parse_config_files()
command = dist.get_command_obj("install")
command.ensure_finalized()
command.run()
print(self.get_dir_from_distribution(dist))
class ScriptDir(_SomeDir):
def get_dir_from_distribution(self, dist):
return dist.install_scripts
class PlatLib(_SomeDir):
def get_dir_from_distribution(self, dist):
return dist.install_platlib
class PureLib(_SomeDir):
def get_dir_from_distribution(self, dist):
return dist.install_purelib
setup(
name="pcs",
version="@VERSION@",
description="Pacemaker Configuration System",
author="Chris Feist",
author_email="[email protected]",
url="https://github.com/ClusterLabs/pcs",
packages=find_packages(exclude=["pcs_test", "pcs_test.*"]),
package_data={"pcs": ["py.typed"]},
zip_safe=False,
entry_points={
"console_scripts": [
"pcs = pcs.entry_points.cli:main",
"pcsd = pcs.entry_points.daemon:main",
"pcs_snmp_agent = pcs.entry_points.snmp_agent:main",
"pcs_internal = pcs.entry_points.internal:main",
],
},
cmdclass={
"clean": CleanCommand,
"scriptdir": ScriptDir,
"platlib": PlatLib,
"purelib": PureLib,
},
)