summaryrefslogtreecommitdiff
path: root/setup.py
blob: d1dde4d2f02fe90893cae96c10690b2529a987c5 (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python3
import os
import subprocess
import sys
from tempfile import TemporaryFile

try:
    from setuptools import setup, Extension
except ImportError:
    print('\nSetuptools was not found. Install setuptools for python 3.\n')
    sys.exit(1)

cmdclass = {}
try:
    from sphinx.setup_command import BuildDoc
    cmdclass = {'build_man': BuildDoc}
except ImportError:
    print('\nSphinx not found, the build_man command will be unavailable.\n')

current_dir = os.path.dirname(__file__)

from poezio.version import __version__

def get_relative_dir(folder, stopper):
    """
    Find the path from a directory to a pseudo-root in order to recreate
    the filetree.
    """
    acc = []
    last = os.path.basename(folder)
    while last != stopper:
        acc.append(last)
        folder = os.path.dirname(folder)
        last = os.path.basename(folder)
    return os.path.join(*acc[::-1]) if acc else ''

def find_doc(before, path):
    _files = []
    stop = os.path.basename(path)
    for root, dirs, files in os.walk(os.path.join(current_dir, 'doc', path)):
        files_path = []
        relative_root = get_relative_dir(root, stop)
        for name in files:
            files_path.append(os.path.join(root, name))
        _files.append((os.path.join(before, relative_root), files_path))
    return _files

def check_include(library_name, header):
    command = [os.environ.get('PKG_CONFIG', 'pkg-config'), '--cflags', library_name]
    try:
        cflags = subprocess.check_output(command).decode('utf-8').split()
    except FileNotFoundError:
        print('pkg-config not found.')
        return False
    except subprocess.CalledProcessError:
        # pkg-config already prints the missing libraries on stderr.
        return False
    command = [os.environ.get('CC', 'cc')] + cflags + ['-E', '-']
    with TemporaryFile('w+') as c_file:
        c_file.write('#include <%s>' % header)
        c_file.seek(0)
        try:
            return subprocess.call(command, stdin=c_file, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0
        except FileNotFoundError:
            print('%s headers not found.' % library_name)
            return False

def sphinx_man():
    expected_sphinx_files = [
        'build/sphinx/man/poezio.cfg.7',
        'build/sphinx/man/poezio.keys.7',
        'build/sphinx/man/poezio.commands.7'
    ]
    found = []
    for item in expected_sphinx_files:
        if os.path.exists(item):
            found.append(item)
    if found:
        return [('share/man/man7/', found)]
    return []


sphinx_files_found = sphinx_man()
if not sphinx_files_found:
    print(
        '\nSphinx-built manpages not found. Only the '
        'short handwritten manpages will be installed\n'
    )


if not check_include('python3', 'Python.h'):
    sys.exit(2)

module_poopt = Extension('poezio.poopt',
                    extra_compile_args=['-Wno-declaration-after-statement'],
                    sources=['poezio/pooptmodule.c'])

# Create a link to the config file (for packaging purposes)
if not os.path.exists(os.path.join(current_dir, 'poezio', 'default_config.cfg')):
    os.link(os.path.join(current_dir, 'data', 'default_config.cfg'),
         os.path.join(current_dir, 'poezio', 'default_config.cfg'))

# identify the git version
git_dir = os.path.join(current_dir, '.git')
if os.path.exists(git_dir):
    try:
        result = subprocess.Popen(['git', '--git-dir', git_dir, 'describe'],
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.DEVNULL)
        result.wait()
        data = result.stdout.read().decode('utf-8', errors='ignore')
        version = '.dev' + data.split('-')[1]
    except:
        version = '.dev1'
else:
    version = ''

with open('README.rst', encoding='utf-8') as readme_fd:
    LONG_DESCRIPTION = readme_fd.read()

setup(
    name="poezio",
    version=__version__ + version,
    description="A console XMPP client",
    long_description=LONG_DESCRIPTION,
    ext_modules=[module_poopt],
    url='https://poez.io/',
    license='zlib',
    download_url='https://poez.io/#download',

    author='Florent Le Coz',
    author_email='louiz@louiz.org',

    maintainer='Mathieu Pasquet',
    maintainer_email='mathieui@mathieui.net',

    classifiers=['Development Status :: 5 - Production/Stable',
        'Topic :: Communications :: Chat',
        'Topic :: Internet :: XMPP',
        'Environment :: Console :: Curses',
        'Intended Audience :: End Users/Desktop',
        'License :: OSI Approved :: zlib/libpng License',
        'Natural Language :: English',
        'Operating System :: Unix',
        'Programming Language :: Python :: 3.9',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3 :: Only'],
    keywords=['jabber', 'xmpp', 'client', 'chat', 'im', 'console'],
    packages=['poezio', 'poezio.core', 'poezio.tabs', 'poezio.windows',
        'poezio.ui', 'poezio_plugins', 'poezio_themes'],
    package_dir={'poezio': 'poezio',
        'poezio_plugins': 'plugins',
        'poezio_themes': 'data/themes'},
    package_data={'poezio': ['default_config.cfg']},
    scripts=['scripts/poezio_logs'],
    entry_points={'console_scripts': ['poezio = poezio.__main__:run']},
    data_files=([
            ('share/man/man1/', ['data/poezio.1', 'data/poezio_logs.1']),
            ('share/poezio/', ['README.rst', 'COPYING', 'CHANGELOG']),
            ('share/applications/', ['data/io.poez.Poezio.desktop']),
            ('share/metainfo/', ['data/io.poez.Poezio.appdata.xml'])
        ]
        + find_doc('share/doc/poezio/source', 'source')
        + find_doc('share/doc/poezio/html', 'build/html')
        + sphinx_files_found
    ),
    install_requires=['slixmpp>=1.6.0', 'aiodns', 'pyasn1_modules', 'pyasn1', 'typing_extensions', 'setuptools'],
    extras_require={'OTR plugin': 'python-potr>=1.0',
        'Screen autoaway plugin': 'pyinotify==0.9.4',
        'Avoiding cython': 'cffi'},
    cmdclass=cmdclass,
    command_options={
        'build_man' : {
            'builder': ('setup.py', 'man'),
        }
    },
)

# Remove the link afterwards
if (os.path.exists(os.path.join(current_dir, 'poezio', 'default_config.cfg')) and
        os.path.exists(os.path.join(current_dir, 'data', 'default_config.cfg'))):

    os.unlink(os.path.join(current_dir, 'poezio', 'default_config.cfg'))