File: setup.py

package info (click to toggle)
freetype-py 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,976 kB
  • sloc: python: 7,676; makefile: 111
file content (137 lines) | stat: -rw-r--r-- 4,706 bytes parent folder | download | duplicates (2)
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
# -----------------------------------------------------------------------------
#  FreeType high-level python API - copyright 2011 Nicolas P. Rougier
#  Distributed under the terms of the new BSD license.
# -----------------------------------------------------------------------------

import distutils
import distutils.dir_util
import distutils.file_util
import os
import subprocess
import sys
from io import open
from os import path

from setuptools import setup

if os.environ.get("FREETYPEPY_BUNDLE_FT"):
    print("# Will build and bundle FreeType.")

    from setuptools import Extension
    from setuptools.command.build_ext import build_ext
    from wheel.bdist_wheel import bdist_wheel

    class BdistWheel(bdist_wheel):
        def get_tag(self):
            return ('py3', 'none') + bdist_wheel.get_tag(self)[2:]

    class SharedLibrary(Extension):
        """Object that describes the library (filename) and how to make it."""
        if sys.platform == "darwin":
            suffix = ".dylib"
        elif sys.platform == "win32":
            suffix = ".dll"
        else:
            suffix = ".so"

        def __init__(self, name, cmd, cwd=".", output_dir=".", env=None):
            Extension.__init__(self, name, sources=[])
            self.cmd = cmd
            self.cwd = path.normpath(cwd)
            self.output_dir = path.normpath(output_dir)
            self.env = env or dict(os.environ)

    class SharedLibBuildExt(build_ext):
        """Object representing command to produce and install a shared
        library."""

        # Needed to make setuptools and wheel believe they're looking at an
        # extension instead of a shared library.
        def get_ext_filename(self, ext_name):
            for ext in self.extensions:
                if isinstance(ext, SharedLibrary):
                    return os.path.join(*ext_name.split('.')) + ext.suffix
            return build_ext.get_ext_filename(self, ext_name)

        def build_extension(self, ext):
            if not isinstance(ext, SharedLibrary):
                build_ext.build_extension(self, ext)
                return

            distutils.log.info("running '{}'".format(ext.cmd))
            if not self.dry_run:
                rv = subprocess.Popen(
                    ext.cmd, cwd=ext.cwd, env=ext.env, shell=True).wait()
                if rv != 0:
                    sys.exit(rv)

            lib_name = ext.name.split(".")[-1] + ext.suffix
            lib_fullpath = path.join(ext.output_dir, lib_name)
            dest_path = self.get_ext_fullpath(ext.name)

            distutils.dir_util.mkpath(
                path.dirname(dest_path),
                verbose=self.verbose,
                dry_run=self.dry_run)

            distutils.file_util.copy_file(
                lib_fullpath,
                dest_path,
                verbose=self.verbose,
                dry_run=self.dry_run)

    ext_modules = [
        SharedLibrary(
            "freetype.libfreetype",  # package.shared_lib_name
            cmd='"{}" ./setup-build-freetype.py'.format(sys.executable),
            output_dir="build/local/lib")
    ]
    cmdclass = {
        'bdist_wheel': BdistWheel,
        'build_ext': SharedLibBuildExt
    }

else:
    print("# Will use the system-provided FreeType.")
    ext_modules = []
    cmdclass = {}

description = open(
    path.join(path.abspath(path.dirname(__file__)), 'README.rst'),
    encoding='utf-8').read()

setup(
    name='freetype-py',
    use_scm_version=True,
    description='Freetype python bindings',
    long_description=description,
    author='Nicolas P. Rougier',
    author_email='Nicolas.Rougier@inria.fr',
    url='https://github.com/rougier/freetype-py',
    python_requires=">=3.7",
    packages=['freetype', 'freetype.ft_enums', 'freetype.__pyinstaller', 'freetype.__pyinstaller.tests'],
    ext_modules=ext_modules,
    zip_safe=False if ext_modules else True,
    cmdclass=cmdclass,
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Environment :: X11 Applications',
        'Environment :: MacOS X',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: BSD License',
        'Operating System :: MacOS',
        'Operating System :: Microsoft :: Windows',
        'Operating System :: POSIX',
        'Operating System :: Unix',
        'Programming Language :: Python :: 3',
        'Topic :: Multimedia :: Graphics',
    ],
    keywords=['freetype', 'font'],
    setup_requires=['setuptools_scm'],
    entry_points={
        "pyinstaller40": [
            "hook-dirs = freetype.__pyinstaller:get_hook_dirs",
            "tests = freetype.__pyinstaller:get_test_dirs",
        ],
    },
)