setup.py 4.17 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

mathieui's avatar
mathieui committed
10 11
from os.path import basename, dirname, exists, join
from os import link, walk, unlink
louiz’'s avatar
louiz’ committed
12

mathieui's avatar
mathieui committed
13
current_dir = dirname(__file__)
louiz’'s avatar
louiz’ committed
14

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

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

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

# Create a link to the config file (for packaging purposes)
44
if not exists(join(current_dir, 'poezio', 'default_config.cfg')):
mathieui's avatar
mathieui committed
45
    link(join(current_dir, 'data', 'default_config.cfg'),
46
         join(current_dir, 'poezio', 'default_config.cfg'))
47

48
# identify the git version
mathieui's avatar
mathieui committed
49 50
git_dir = join(current_dir, '.git')
if exists(git_dir):
51 52
    try:
        import subprocess
53
        result = subprocess.Popen(['git', '--git-dir', git_dir, 'describe'],
mathieui's avatar
mathieui committed
54
                                  stdout=subprocess.PIPE,
55
                                  stderr=subprocess.DEVNULL)
56 57 58 59 60 61 62 63
        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
64 65
with open('README.rst', encoding='utf-8') as readme_fd:
    LONG_DESCRIPTION = readme_fd.read()
mathieui's avatar
mathieui committed
66

mathieui's avatar
mathieui committed
67
setup(name="poezio",
mathieui's avatar
mathieui committed
68
      version="0.10" + version,
mathieui's avatar
mathieui committed
69 70 71
      description="A console XMPP client",
      long_description=LONG_DESCRIPTION,
      ext_modules=[module_poopt],
72
      url='https://poez.io/',
mathieui's avatar
mathieui committed
73 74
      license='zlib',
      download_url='https://dev.louiz.org/projects/poezio/files',
mathieui's avatar
mathieui committed
75

mathieui's avatar
mathieui committed
76 77
      author='Florent Le Coz',
      author_email='louiz@louiz.org',
mathieui's avatar
mathieui committed
78

mathieui's avatar
mathieui committed
79 80
      maintainer='Mathieu Pasquet',
      maintainer_email='mathieui@mathieui.net',
81

mathieui's avatar
mathieui committed
82 83 84 85 86 87 88 89 90 91 92 93
      classifiers=['Development Status :: 2 - Pre-Alpha',
                   'Topic :: Communications :: Chat',
                   'Environment :: Console :: Curses',
                   'Intended Audience :: End Users/Desktop',
                   'License :: OSI Approved :: zlib/libpng License',
                   'Natural Language :: English',
                   'Operating System :: Unix',
                   'Programming Language :: Python :: 3.4',
                   'Programming Language :: Python :: 3 :: Only'],
      keywords=['jabber', 'xmpp', 'client', 'chat', 'im', 'console'],
      packages=['poezio', 'poezio.core', 'poezio.tabs', 'poezio.windows',
                'poezio_plugins', 'poezio_plugins.gpg', 'poezio_themes'],
94
      package_dir={'poezio': 'poezio',
mathieui's avatar
mathieui committed
95 96 97
                   'poezio_plugins': 'plugins',
                   'poezio_themes': 'data/themes'},
      package_data={'poezio': ['default_config.cfg']},
98
      scripts=['scripts/poezio_gpg_export', 'scripts/poezio_logs'],
mathieui's avatar
mathieui committed
99
      entry_points={'console_scripts': ['poezio = poezio.__main__:run']},
mathieui's avatar
mathieui committed
100 101
      data_files=([('share/man/man1/', ['data/poezio.1']),
                   ('share/poezio/', ['README.rst', 'COPYING', 'CHANGELOG'])]
mathieui's avatar
mathieui committed
102 103
                  + find_doc('share/doc/poezio/source', 'source')
                  + find_doc('share/doc/poezio/html', 'build/html')),
mathieui's avatar
mathieui committed
104 105 106
      install_requires=['slixmpp', 'aiodns'],
      extras_require={'OTR plugin': 'python-potr>=1.0',
                      'Screen autoaway plugin': 'pyinotify==0.9.4'})
107 108

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

112
    unlink(join(current_dir, 'poezio', 'default_config.cfg'))
113