setup.py 4.18 KB
Newer Older
1 2
#!/usr/bin/python
# Builds on python2.X and python3
Arch Librarian's avatar
Arch Librarian committed
3
# $Id: setup.py,v 1.2 2002/01/08 07:13:21 jgg Exp $
Michael Vogt's avatar
Michael Vogt committed
4 5
import glob
import os
Michael Vogt's avatar
Michael Vogt committed
6
import shutil
Michael Vogt's avatar
Michael Vogt committed
7 8
import sys

9
from distutils.core import setup, Extension
Michael Vogt's avatar
Michael Vogt committed
10
from distutils.command.install import install
11
from distutils import sysconfig
12
cmdclass = {}
13

14 15 16 17 18 19 20 21
try:
    from DistUtilsExtra.command import build_extra, build_i18n
    from DistUtilsExtra.auto import clean_build_tree
    cmdclass['build'] = build_extra.build_extra
    cmdclass['build_i18n'] = build_i18n.build_i18n
    cmdclass['clean'] = clean_build_tree
except ImportError:
    print('W: [python%s] DistUtilsExtra import error.' % sys.version[:3])
22

23 24 25 26 27 28
try:
    from sphinx.setup_command import BuildDoc
    cmdclass['build_sphinx'] = BuildDoc
except ImportError:
    print('W: [python%s] Sphinx import error.' % sys.version[:3])

29

Michael Vogt's avatar
Michael Vogt committed
30 31 32 33 34 35 36 37 38 39
class InstallTypeinfo(install):
    def run(self):
        install.run(self)
        for pyi in glob.glob("typehinting/*.pyi"):
            shutil.copy(pyi, self.install_purelib)


cmdclass['install'] = InstallTypeinfo


40 41 42
def get_version():
    """Get a PEP 0440 compatible version string"""
    version = os.environ.get('DEBVER')
43 44 45
    if not version:
        return version

46 47 48 49 50 51 52 53 54 55 56
    version = version.replace("~alpha", ".a")
    version = version.replace("~beta", ".b")
    version = version.replace("~rc", ".rc")
    version = version.replace("~exp", ".dev")
    version = version.replace("ubuntu", "+ubuntu")
    version = version.replace("tanglu", "+tanglu")
    version = version.split("build")[0]

    return version


57 58
# The apt_pkg module.
files = ['apt_pkgmodule.cc', 'acquire.cc', 'cache.cc', 'cdrom.cc',
59
         'configuration.cc', 'depcache.cc', 'generic.cc', 'hashes.cc',
60
         'hashstring.cc', 'indexfile.cc', 'metaindex.cc',
61
         'pkgmanager.cc', 'pkgrecords.cc', 'pkgsrcrecords.cc', 'policy.cc',
62
         'progress.cc', 'sourcelist.cc', 'string.cc', 'tag.cc',
63
         'lock.cc', 'acquire-item.cc', 'python-apt-helpers.cc',
64
         'cachegroup.cc', 'orderlist.cc', 'hashstringlist.cc']
65
files = sorted(['python/' + fname for fname in files], key=lambda s: s[:-3])
66
apt_pkg = Extension("apt_pkg", files, libraries=["apt-pkg"],
67 68 69 70
                    extra_compile_args=['-std=c++11', '-Wno-write-strings',
                                        '-DAPT_8_CLEANER_HEADERS',
                                        '-DAPT_9_CLEANER_HEADERS',
                                        '-DAPT_10_CLEANER_HEADERS'])
71 72

# The apt_inst module
73
files = ["python/apt_instmodule.cc", "python/generic.cc",
74
         "python/arfile.cc", "python/tarfile.cc"]
75 76
apt_inst = Extension("apt_inst", files, libraries=["apt-pkg", "apt-inst"],
                     extra_compile_args=['-std=c++11', '-Wno-write-strings'])
77

78
# Replace the leading _ that is used in the templates for translation
79 80 81 82 83
if len(sys.argv) > 1 and sys.argv[1] == "build":
    if not os.path.exists("build/data/templates/"):
        os.makedirs("build/data/templates")
    for template in glob.glob('data/templates/*.info.in'):
        source = open(template, "r")
84 85
        build = open("build/" + template[:-3], "w")
        for line in source:
86 87 88
            build.write(line.lstrip("_"))
        source.close()
        build.close()
89 90
    for template in glob.glob('data/templates/*.mirrors'):
        shutil.copy(template, os.path.join("build", template))
Michael Vogt's avatar
Michael Vogt committed
91

92 93 94 95 96 97
# Remove the "-Wstrict-prototypes" compiler option, which isn't valid for C++.
# See http://bugs.python.org/issue9031 and http://bugs.python.org/issue1222585
cfg_vars = sysconfig.get_config_vars()
for key, value in cfg_vars.items():
    if type(value) == str:
        cfg_vars[key] = value.replace("-Wstrict-prototypes", "")
98

99
setup(name="python-apt",
100
      description="Python bindings for APT",
101
      version=get_version(),
102 103
      author="APT Development Team",
      author_email="deity@lists.debian.org",
104
      ext_modules=[apt_pkg, apt_inst],
105
      packages=['apt', 'apt.progress', 'aptsources'],
Michael Vogt's avatar
Michael Vogt committed
106 107 108
      package_data={
          'apt': ["*.pyi"],
      },
Michael Vogt's avatar
Michael Vogt committed
109 110 111 112 113 114 115
      data_files=[('share/python-apt/templates',
                   glob.glob('build/data/templates/*.info')),
                  ('share/python-apt/templates',
                   glob.glob('data/templates/*.mirrors'))],
      cmdclass=cmdclass,
      license='GNU GPL',
      platforms='posix')