forked from redhat-openstack/infrared
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
101 lines (85 loc) · 3.4 KB
/
setup.py
File metadata and controls
101 lines (85 loc) · 3.4 KB
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
import os
from os.path import join, dirname, abspath
from pip import req
import platform
from setuptools import setup, find_packages
import cli
# parse_requirements() returns generator of pip.req.InstallRequirement objects
install_reqs = req.parse_requirements('requirements.txt', session=False)
# reqs is a list of requirement
# e.g. ['django==1.5.1', 'mezzanine==1.4.6']
reqs = [str(ir.req) for ir in install_reqs]
def generate_entry_scripts():
"""
Generates the entry points for the ir-* scripts.
"""
# at this point we don't have any packages installed
# so hard-code settings folder for now here
specs = next(os.walk('settings'))[1]
scripts = next(os.walk('cli/scripts'))[2]
specs_e_points = ["ir-{0} = cli.main:entry_point".format(
spec_name) for spec_name in specs]
scripts_e_points = \
["ir-{script} = cli.scripts.{script}:main".format(
script=script.split('.')[0]) for script in scripts
if script.endswith('.py') and not script.startswith('__')]
return specs_e_points + scripts_e_points
prj_dir = dirname(abspath(__file__))
setup(
name='infrared',
version=cli.__VERSION__,
packages=find_packages(),
long_description=open(join(prj_dir, 'README.rst')).read(),
entry_points={
'console_scripts': generate_entry_scripts()
},
install_requires=reqs,
author='rhos-qe',
author_email='rhos-qe-dept@redhat.com'
)
if all(platform.linux_distribution(supported_dists="redhat")):
# For RedHat based systems, get selinux binding
try:
import selinux
except ImportError as e:
new_error = type(e)(e.message + ". check that 'python-libselinux is "
"installed'")
import sys
import shutil
from distutils import sysconfig
if hasattr(sys, 'real_prefix'):
# check for venv
VENV_SITE = sysconfig.get_python_lib()
SELINUX_PATH = os.path.join(
sysconfig.get_python_lib(plat_specific=True,
prefix=sys.real_prefix),
"selinux")
if not os.path.exists(SELINUX_PATH):
raise new_error
dest = os.path.join(VENV_SITE, "selinux")
if os.path.exists(dest):
raise new_error
# filter precompiled files
files = [os.path.join(SELINUX_PATH, f)
for f in os.listdir(SELINUX_PATH)
if not os.path.splitext(f)[1] in (".pyc", ".pyo")]
# add extra file for (libselinux-python-2.5-9.fc24.x86_64)
_selinux_file = os.path.join(
sysconfig.get_python_lib(plat_specific=True,
prefix=sys.real_prefix),
"_selinux.so")
if os.path.exists(_selinux_file):
files.append(_selinux_file)
os.makedirs(dest)
for f in files:
shutil.copy(f, dest)
# add extra file for (libselinux-python-2.5-13.fc25.x86_64)
_selinux_file = os.path.join(
sysconfig.get_python_lib(plat_specific=True,
prefix=sys.real_prefix),
"_selinux.so")
if os.path.exists(_selinux_file):
shutil.copy(_selinux_file, os.path.dirname(dest))
else:
raise new_error
import selinux # noqa