setup.py 5.61 KB
Newer Older
1
#!/usr/bin/env python3
2

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

10
import os
11
import subprocess
12
from tempfile import TemporaryFile
louiz’'s avatar
louiz’ committed
13

14
current_dir = os.path.dirname(__file__)
louiz’'s avatar
louiz’ committed
15

mathieui's avatar
mathieui committed
16 17 18 19 20 21
def get_relative_dir(folder, stopper):
    """
    Find the path from a directory to a pseudo-root in order to recreate
    the filetree.
    """
    acc = []
22
    last = os.path.basename(folder)
mathieui's avatar
mathieui committed
23 24
    while last != stopper:
        acc.append(last)
25 26 27
        folder = os.path.dirname(folder)
        last = os.path.basename(folder)
    return os.path.join(*acc[::-1]) if acc else ''
28

mathieui's avatar
mathieui committed
29 30
def find_doc(before, path):
    _files = []
31 32
    stop = os.path.basename(path)
    for root, dirs, files in os.walk(os.path.join(current_dir, 'doc', path)):
mathieui's avatar
mathieui committed
33 34 35
        files_path = []
        relative_root = get_relative_dir(root, stop)
        for name in files:
36 37
            files_path.append(os.path.join(root, name))
        _files.append((os.path.join(before, relative_root), files_path))
mathieui's avatar
mathieui committed
38 39
    return _files

40 41 42
def check_include(library_name, header):
    command = [os.environ.get('PKG_CONFIG', 'pkg-config'), '--cflags', library_name]
    try:
43
        cflags = subprocess.check_output(command).decode('utf-8').split()
44 45 46
    except FileNotFoundError:
        print('pkg-config not found.')
        return False
47
    except subprocess.CalledProcessError:
48 49 50 51 52 53 54
        # 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:
55
            return subprocess.call(command, stdin=c_file, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) == 0
56 57 58 59 60 61
        except FileNotFoundError:
            print('%s headers not found.' % library_name)
            return False

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

mathieui's avatar
mathieui committed
64 65
module_poopt = Extension('poezio.poopt',
                    extra_compile_args=['-Wno-declaration-after-statement'],
66
                    sources=['poezio/pooptmodule.c'])
67 68

# Create a link to the config file (for packaging purposes)
69 70 71
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'))
72

73
# identify the git version
74 75
git_dir = os.path.join(current_dir, '.git')
if os.path.exists(git_dir):
76
    try:
77
        result = subprocess.Popen(['git', '--git-dir', git_dir, 'describe'],
mathieui's avatar
mathieui committed
78
                                  stdout=subprocess.PIPE,
79
                                  stderr=subprocess.DEVNULL)
80 81 82 83 84 85 86 87
        result.wait()
        data = result.stdout.read().decode('utf-8', errors='ignore')
        version = '.dev' + data.split('-')[1]
    except:
        version = '.dev1'
else:
    version = '.dev1'

mathieui's avatar
mathieui committed
88 89
with open('README.rst', encoding='utf-8') as readme_fd:
    LONG_DESCRIPTION = readme_fd.read()
mathieui's avatar
mathieui committed
90

mathieui's avatar
mathieui committed
91
setup(name="poezio",
mathieui's avatar
mathieui committed
92
      version="0.13" + version,
mathieui's avatar
mathieui committed
93 94 95
      description="A console XMPP client",
      long_description=LONG_DESCRIPTION,
      ext_modules=[module_poopt],
96
      url='https://poez.io/',
mathieui's avatar
mathieui committed
97 98
      license='zlib',
      download_url='https://dev.louiz.org/projects/poezio/files',
mathieui's avatar
mathieui committed
99

mathieui's avatar
mathieui committed
100 101
      author='Florent Le Coz',
      author_email='louiz@louiz.org',
mathieui's avatar
mathieui committed
102

mathieui's avatar
mathieui committed
103 104
      maintainer='Mathieu Pasquet',
      maintainer_email='mathieui@mathieui.net',
105

106
      classifiers=['Development Status :: 5 - Production/Stable',
mathieui's avatar
mathieui committed
107
                   'Topic :: Communications :: Chat',
108
                   'Topic :: Internet :: XMPP',
mathieui's avatar
mathieui committed
109 110 111 112 113
                   'Environment :: Console :: Curses',
                   'Intended Audience :: End Users/Desktop',
                   'License :: OSI Approved :: zlib/libpng License',
                   'Natural Language :: English',
                   'Operating System :: Unix',
114
                   'Programming Language :: Python :: 3.7',
115
                   'Programming Language :: Python :: 3.6',
116
                   'Programming Language :: Python :: 3.5',
mathieui's avatar
mathieui committed
117 118 119
                   'Programming Language :: Python :: 3 :: Only'],
      keywords=['jabber', 'xmpp', 'client', 'chat', 'im', 'console'],
      packages=['poezio', 'poezio.core', 'poezio.tabs', 'poezio.windows',
120
                'poezio_plugins', 'poezio_themes'],
121
      package_dir={'poezio': 'poezio',
mathieui's avatar
mathieui committed
122 123 124
                   'poezio_plugins': 'plugins',
                   'poezio_themes': 'data/themes'},
      package_data={'poezio': ['default_config.cfg']},
125
      scripts=['scripts/poezio_logs'],
mathieui's avatar
mathieui committed
126
      entry_points={'console_scripts': ['poezio = poezio.__main__:run']},
127 128
      data_files=([('share/man/man1/', ['data/poezio.1',
                                        'data/poezio_logs.1']),
Link Mauve's avatar
Link Mauve committed
129
                   ('share/poezio/', ['README.rst', 'COPYING', 'CHANGELOG']),
Link Mauve's avatar
Link Mauve committed
130
                   ('share/applications/', ['data/io.poez.Poezio.desktop']),
Link Mauve's avatar
Link Mauve committed
131
                   ('share/metainfo/', ['data/io.poez.Poezio.appdata.xml'])]
mathieui's avatar
mathieui committed
132 133
                  + find_doc('share/doc/poezio/source', 'source')
                  + find_doc('share/doc/poezio/html', 'build/html')),
134
      install_requires=['slixmpp>=1.3.0', 'aiodns', 'pyasn1_modules', 'pyasn1'],
mathieui's avatar
mathieui committed
135
      extras_require={'OTR plugin': 'python-potr>=1.0',
mathieui's avatar
mathieui committed
136 137
                      'Screen autoaway plugin': 'pyinotify==0.9.4',
                      'Avoiding cython': 'cffi'})
138 139

# Remove the link afterwards
140 141
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'))):
142

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