From 5f51ea00142385051aa52b7786f8604ad1b7aa69 Mon Sep 17 00:00:00 2001 From: John Wiggins Date: Thu, 7 Jan 2021 16:55:57 +0100 Subject: [PATCH 1/4] Move to a single setup.py file --- ci/edmtool.py | 5 +- kiva/agg/setup.py | 259 -------------------------- kiva/quartz/setup.py | 105 ----------- kiva/setup.py | 45 ----- setup.py | 429 ++++++++++++++++++++++++++----------------- 5 files changed, 264 insertions(+), 579 deletions(-) delete mode 100644 kiva/agg/setup.py delete mode 100644 kiva/quartz/setup.py delete mode 100644 kiva/setup.py diff --git a/ci/edmtool.py b/ci/edmtool.py index 11a216f68..1ec2608aa 100644 --- a/ci/edmtool.py +++ b/ci/edmtool.py @@ -93,6 +93,7 @@ dependencies = { "apptools", "coverage", + "Cython", "fonttools", "hypothesis", "kiwisolver", @@ -137,10 +138,6 @@ 'null': {'ETS_TOOLKIT': 'null.image'}, } -if sys.platform == 'darwin': - dependencies.add('Cython') - - #: Path to the top-level source directory ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) diff --git a/kiva/agg/setup.py b/kiva/agg/setup.py deleted file mode 100644 index 8d8e8e225..000000000 --- a/kiva/agg/setup.py +++ /dev/null @@ -1,259 +0,0 @@ -#!/usr/bin/env python -import sys -import os -import re -import platform - -freetype2_sources =['autofit/autofit.c', - 'base/ftbase.c','base/ftsystem.c','base/ftinit.c', - 'base/ftglyph.c','base/ftmm.c','base/ftbdf.c', - 'base/ftbbox.c','base/ftdebug.c','base/ftxf86.c', - 'base/fttype1.c', - 'bdf/bdf.c', - 'cff/cff.c', - 'cid/type1cid.c', - 'lzw/ftlzw.c', - 'pcf/pcf.c','pfr/pfr.c', - 'psaux/psaux.c', - 'pshinter/pshinter.c', - 'psnames/psnames.c', - 'raster/raster.c', - 'sfnt/sfnt.c', - 'smooth/smooth.c', - 'truetype/truetype.c', - 'type1/type1.c', - 'type42/type42.c', - 'winfonts/winfnt.c', - 'gzip/ftgzip.c', - 'base/ftmac.c', - ] - -freetype2_dirs = [ - 'autofit', - 'base', - 'bdf', - 'cache', - 'cff', - 'cid', - 'gxvalid', - 'gzip', - 'lzw', - 'otvalid', - 'pcf', - 'pfr', - 'psaux', - 'pshinter', - 'psnames', - 'raster', - 'sfnt', - 'smooth', - 'tools', - 'truetype', - 'type1', - 'type42', - 'winfonts', - 'gzip' - ] - - - -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - from numpy.distutils.system_info import dict_append, get_info - - agg_dir = 'agg-24' - agg_lib = 'agg24_src' - - config = Configuration('agg', parent_package,top_path) - numerix_info = get_info('numerix') - - if ('NUMPY', None) in numerix_info.get('define_macros',[]): - dict_append(numerix_info, - define_macros = [('PY_ARRAY_TYPES_PREFIX','NUMPY_CXX'), - ('OWN_DIMENSIONS','0'), - ('OWN_STRIDES','0')]) - - #------------------------------------------------------------------------- - # Configure the Agg backend to use on each platform - #------------------------------------------------------------------------- - if sys.platform=='win32': - plat = 'win32' - elif sys.platform == 'darwin': - plat = 'osx' - else: - #plat = 'gtk1' # use with gtk1, it's fast - plat = 'x11' # use with gtk2, it's slow but reliable - #plat = 'gdkpixbuf2' - - - #------------------------------------------------------------------------- - # Add the freetype library (agg 2.4 links against this) - #------------------------------------------------------------------------- - - prefix = config.paths('freetype2/src')[0] - freetype_lib = 'freetype2_src' - - def get_ft2_sources(name_info, build_dir): - (lib_name, build_info) = name_info - sources = [prefix + "/" + s for s in freetype2_sources] - if sys.platform=='darwin': - return sources[:] - return sources[:-1] - - ft2_incl_dirs = ['freetype2/src/' + s for s in freetype2_dirs] \ - + ['freetype2/include', 'freetype2/src'] - ft2_incl_dirs = config.paths(*ft2_incl_dirs) - if sys.platform == 'darwin' and '64bit' not in platform.architecture(): - ft2_incl_dirs.append("/Developer/Headers/FlatCarbon") - - config.add_library(freetype_lib, - sources = [get_ft2_sources], - include_dirs = ft2_incl_dirs, - - # This macro was introduced in Freetype 2.2; if it is - # not defined, then the ftheader.h file (one of the - # primary headers) won't pull in any additional internal - # Freetype headers, and the library will mysteriously - # fail to build. - macros = [("FT2_BUILD_LIBRARY", None)], - - depends = ['freetype2'], - ) - - #------------------------------------------------------------------------- - # Add the Agg sources - #------------------------------------------------------------------------- - - agg_include_dirs = [agg_dir+'/include',agg_dir+'/font_freetype'] + \ - ft2_incl_dirs - agg_sources = [agg_dir+'/src/*.cpp', - agg_dir+'/font_freetype/*.cpp'] - config.add_library(agg_lib, - agg_sources, - include_dirs = agg_include_dirs, - depends = [agg_dir]) - - #------------------------------------------------------------------------- - # Add the Kiva sources - #------------------------------------------------------------------------- - if sys.platform == 'darwin': - define_macros = [('__DARWIN__', None)] - macros = [('__DARWIN__', None)] - else: - define_macros = [] - macros = [] - - kiva_include_dirs = ['src'] + agg_include_dirs - config.add_library('kiva_src', ['src/kiva_*.cpp'], - include_dirs = kiva_include_dirs, - # Use "macros" instead of "define_macros" because the - # latter is only used for extensions, and not clibs - macros = macros, - ) - - # MSVC6.0: uncomment to handle template parameters: - #extra_compile_args = ['/Zm1000'] - extra_compile_args = [] - - # XXX: test whether numpy has weakref support - - #------------------------------------------------------------------------- - # Build the extension itself - #------------------------------------------------------------------------- - - # Check for g++ < 4.0 on 64-bit Linux - use_32bit_workaround = False - - if sys.platform == 'linux2' and '64bit' in platform.architecture(): - f = os.popen("g++ --version") - line0 = f.readline() - f.close() - m = re.match(r'.+?\s([3-5])\.\d+', line0) - if m is not None and int(m.group(1)) < 4: - use_32bit_workaround = True - - # Enable workaround of agg bug on 64-bit machines with g++ < 4.0 - if use_32bit_workaround: - define_macros.append(("ALWAYS_32BIT_WORKAROUND", 1)) - - # Options to make OS X link - if '64bit' not in platform.architecture(): - darwin_frameworks = ['Carbon', 'ApplicationServices'] - else: - darwin_frameworks = ['ApplicationServices'] - - darwin_extra_link_args = [] - for framework in darwin_frameworks: - darwin_extra_link_args.extend(['-framework', framework]) - - darwin_opengl_opts = dict( - include_dirs = [ - '/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x - for x in darwin_frameworks], - define_macros = [('__DARWIN__',None)], - extra_link_args = darwin_extra_link_args - ) - - build_info = {} - kiva_lib = 'kiva_src' - build_libraries = [kiva_lib, agg_lib, freetype_lib] - if sys.platform == "darwin": - dict_append(build_info, **darwin_opengl_opts) - dict_append(build_info, - sources = ['agg.i'], - include_dirs = kiva_include_dirs, - libraries = build_libraries, - depends = ['src/*.[ih]'], - extra_compile_args = extra_compile_args, - extra_link_args = [], - define_macros=define_macros, - ) - dict_append(build_info, **numerix_info) - config.add_extension('_agg', **build_info) - - sources = [os.path.join('src',plat,'plat_support.i'), - os.path.join('src',plat,'agg_bmp.cpp'), - ] - if plat != 'osx': - sources.append(os.path.join('src',plat,'agg_platform_specific.cpp')) - - plat_info = {} - dict_append(plat_info, libraries = [agg_lib], - include_dirs = kiva_include_dirs, - extra_compile_args = extra_compile_args, - depends = ['src']) - dict_append(plat_info, **numerix_info) - - if plat=='win32': - dict_append(plat_info, libraries = ['gdi32','user32']) - - elif plat in ['x11','gtk1']: - # Make sure we raise an error if the information is not found. - # Frequently, the 64-bit libraries are not in a known location and need - # manual configuration. From experience, this is usually not detected by - # the builder if we do not raise an exception. - x11_info = get_info('x11', notfound_action=2) - dict_append(plat_info, **x11_info) - - elif plat=='gdkpixbuf2': - #gdk_pixbuf_xlib_2 = get_info('gdk_pixbuf_xlib_2',notfound_action=1) - #dict_append(plat_info,**gdk_pixbuf_xlib_2) - gtk_info = get_info('gtk+-2.0') - dict_append(plat_info, **gtk_info) - #x11_info = get_info('x11',notfound_action=1) - #dict_append(plat_info,**x11_info) - - elif plat == 'osx': - if sys.platform == 'darwin': - dict_append(plat_info, **darwin_opengl_opts) - - - config.add_extension('_plat_support', - sources, - **plat_info - ) - - config.add_data_dir('tests') - config.add_data_files('*.txt', '*.bat') - - return config diff --git a/kiva/quartz/setup.py b/kiva/quartz/setup.py deleted file mode 100644 index 65b0604c8..000000000 --- a/kiva/quartz/setup.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python - -import os -import platform -import sys - -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - from numpy.distutils.system_info import dict_append, get_info - config = Configuration('quartz', parent_package, top_path) - - def generate_c_from_cython(extension, build_dir): - if not sys.platform == 'darwin': - print('No %s will be built for this platform.' % extension.name) - return - from distutils.dep_util import newer_group - name = extension.name.split('.')[-1] - source = extension.depends[0] - target = os.path.join(build_dir, name+'.c') - - if newer_group(extension.depends, target): - from Cython.Compiler import Main - options = Main.CompilationOptions( - defaults=Main.default_options, - output_file=target) - cython_result = Main.compile(source, options=options) - if cython_result.num_errors != 0: - raise RuntimeError("%d errors in Cython compile" % - cython_result.num_errors) - return target - - frameworks = ['Cocoa', 'CoreFoundation', 'ApplicationServices', 'Foundation'] - extra_link_args = [] - for framework in frameworks: - extra_link_args.extend(['-framework', framework]) - - include_dirs = [ - '/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x - for x in frameworks - ] - - config.add_extension('ABCGI', - [generate_c_from_cython], - extra_link_args = extra_link_args, - depends = ["ABCGI.pyx", - "Python.pxi", - "numpy.pxi", - "c_numpy.pxd", - "CoreFoundation.pxi", - "CoreGraphics.pxi", - "CoreText.pxi", - ] - ) - - config.add_extension('CTFont', - [generate_c_from_cython], - extra_link_args = extra_link_args, - depends=["CTFont.pyx", - "CoreFoundation.pxi", - "CoreGraphics.pxi", - "CoreText.pxi", - ], - ) - - config.add_extension("mac_context", - ["mac_context.c", "mac_context_cocoa.m"], - include_dirs = include_dirs, - extra_link_args = extra_link_args, - depends = ["mac_context.h"], - ) - - wx_info = get_info('wx') - if wx_info: - wx_release = '2.6' - for macro, value in wx_info['define_macros']: - if macro.startswith('WX_RELEASE_'): - wx_release = macro[len('WX_RELEASE_'):].replace('_', '.') - break - - # only build macport for wxPython version 2.6, it's not needed in the - # newer releases (see __init__.py) - if wx_release == '2.6': - macport_cpp = config.paths('macport26.cpp')[0] - - def get_macport_cpp(extension, build_dir): - if sys.platform != 'darwin': - print('No %s will be built for this platform.' - % extension.name) - return None - - elif wx_release not in ('2.6', '2.8'): - print ('No %s will be built because we do not recognize ' - 'wx version %s' % (extension.name, wx_release)) - return None - - return macport_cpp - - info = {} - dict_append(info, define_macros=[("__WXMAC__", 1)]) - dict_append(info, **wx_info) - config.add_extension('macport', [get_macport_cpp], - depends = [macport_cpp], - **wx_info - ) - return config diff --git a/kiva/setup.py b/kiva/setup.py deleted file mode 100644 index 8dd6b3800..000000000 --- a/kiva/setup.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python -# ----------------------------------------------------------------------------- -# Copyright (c) 2005, Enthought, Inc. -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in enthought/LICENSE.txt and may be redistributed only -# under the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# Thanks for using Enthought open source! -# -# Author: Enthought, Inc. -# Description: -# ----------------------------------------------------------------------------- - -import sys - -from numpy import get_include - - -def configuration(parent_package=None, top_path=None): - from numpy.distutils.misc_util import Configuration - - config = Configuration('kiva', parent_package, top_path) - config.add_data_dir('tests') - config.add_data_files('*.txt') - - config.add_subpackage('agg') - config.add_subpackage('fonttools') - config.add_subpackage('fonttools.tests') - config.add_subpackage('gl') - config.add_subpackage('trait_defs') - config.add_subpackage('trait_defs.ui') - config.add_subpackage('trait_defs.ui.*') - - if sys.platform == 'darwin': - config.add_subpackage('quartz') - - config.get_version() - - ext_sources = ['_cython_speedups.cpp', '_hit_test.cpp'] - config.add_extension('_cython_speedups', sources=ext_sources, - include_dirs=['.', get_include()]) - - return config diff --git a/setup.py b/setup.py index e38891652..57b486c4e 100644 --- a/setup.py +++ b/setup.py @@ -1,51 +1,53 @@ -# Copyright (c) 2008-2017 by Enthought, Inc. +# (C) Copyright 2008-2021 Enthought, Inc., Austin, TX # All rights reserved. - -# These are necessary to get the clib compiled. The following also adds -# an additional option --compiler=STR to develop, which usually does not -# have such an option. The code below is a bad hack, as it changes -# sys.argv to fool setuptools which therefore has to be imported BELOW -# this hack. -import sys -if 'develop' in sys.argv: - idx = sys.argv.index('develop') - compiler = [] - for arg in sys.argv[idx+1:]: - if arg.startswith('--compiler='): - compiler = ['-c', arg[11:]] - del sys.argv[idx+1:] - # insert extra options right before 'develop' - sys.argv[idx:idx] = ['build_src', '--inplace', 'build_clib'] + compiler + \ - ['build_ext', '--inplace'] + compiler - -from os.path import dirname, exists, join - -# Setuptools must be imported BEFORE numpy.distutils for things to work right! -import setuptools - -import distutils -import distutils.command.clean -from setuptools.command.build_py import build_py - +# +# This software is provided without warranty under the terms of the BSD +# license included in LICENSE.txt and may be redistributed only under +# the conditions described in the aforementioned license. The license +# is also available online at http://www.enthought.com/licenses/BSD.txt +# +# Thanks for using Enthought open source! + +from distutils.command.build import build as base_build +import glob import os import re -import shutil import subprocess +import sys -from numpy.distutils.core import setup -from numpy.distutils.misc_util import is_string +from Cython.Distutils import build_ext +import numpy +from setuptools import Extension, find_packages, setup +from setuptools.command.install import install as base_install MAJOR = 4 MINOR = 8 MICRO = 1 IS_RELEASED = False - VERSION = '%d.%d.%d' % (MAJOR, MINOR, MICRO) +# Distutils will collect the `.py` files for the distribution before +# building the Extensions, so `.py` files generated by SWIG will not be +# added, resulting in a broken build. +# See: https://stackoverflow.com/a/21236111 + +class PatchedBuild(base_build): + def run(self): + self.run_command('build_ext') + base_build.run(self) + + +class PatchedInstall(base_install): + def run(self): + self.run_command('build_ext') + super().run() + + def read_version_py(path): - """ Read a _version.py file in a safe way. """ + """ Read a _version.py file in a safe way. + """ with open(path, 'r') as fp: code = compile(fp.read(), 'kiva._version', 'exec') context = {} @@ -54,7 +56,8 @@ def read_version_py(path): def git_version(): - """ Return the git revision as a string """ + """ Return the git revision as a string + """ def _minimal_ext_cmd(cmd): # construct minimal environment env = {} @@ -102,10 +105,11 @@ def write_version_py(filename): # write_version_py(), otherwise the import of kiva._version messes # up the build under Python 3. fullversion = VERSION - kiva_version_path = join(dirname(__file__), 'kiva', '_version.py') - if exists(join(dirname(__file__), '.git')): + kiva_version_path = os.path.join(os.path.dirname(__file__), 'kiva', + '_version.py') + if os.path.exists(os.path.join(os.path.dirname(__file__), '.git')): git_revision, dev_num = git_version() - elif exists(kiva_version_path): + elif os.path.exists(kiva_version_path): # must be a source distribution, use existing version file try: git_revision, full_version = read_version_py(kiva_version_path) @@ -133,113 +137,206 @@ def write_version_py(filename): is_released=IS_RELEASED)) -# Configure python extensions. -def configuration(parent_package='', top_path=None): - from numpy.distutils.misc_util import Configuration - - config = Configuration(None, parent_package, top_path) - config.set_options( - ignore_setup_xxx_py=True, - assume_default_configuration=True, - delegate_options_to_subpackages=True, - quiet=True, - ) - - config.add_subpackage('kiva') - - return config - - -class MyBuildPy(build_py): - """ This is NumPy's version of build_py with 2to3 folded in """ - - def run(self): - build_src = self.get_finalized_command('build_src') - if build_src.py_modules_dict and self.packages is None: - self.packages = list(build_src.py_modules_dict.keys()) - build_py.run(self) - - def find_package_modules(self, package, package_dir): - modules = build_py.find_package_modules(self, package, package_dir) - - # Find build_src generated *.py files. - build_src = self.get_finalized_command('build_src') - modules += build_src.py_modules_dict.get(package, []) - - return modules - - def find_modules(self): - old_py_modules = self.py_modules[:] - new_py_modules = [_m for _m in self.py_modules if is_string(_m)] - self.py_modules[:] = new_py_modules - modules = build_py.find_modules(self) - self.py_modules[:] = old_py_modules - - return modules - - -class MyClean(distutils.command.clean.clean): - ''' - Subclass to remove any files created in an inplace build. - - This subclasses distutils' clean because neither setuptools nor - numpy.distutils implements a clean command. - - ''' - def run(self): - distutils.command.clean.clean.run(self) - - # Clean any build or dist directory - if os.path.isdir("build"): - shutil.rmtree("build", ignore_errors=True) - if os.path.isdir("dist"): - shutil.rmtree("dist", ignore_errors=True) - - # Clean out any files produced by an in-place build. Note that our - # code assumes the files are relative to the 'kiva' dir. - INPLACE_FILES = ( - # Common AGG - join("agg", "agg.py"), - join("agg", "plat_support.py"), - join("agg", "agg_wrap.cpp"), - - # Common GL - join("gl", "gl.py"), - join("gl", "gl_wrap.cpp"), - - # Mac - join("quartz", "ABCGI.so"), - join("quartz", "ABCGI.c"), - join("quartz", "macport.so"), - join("quartz", "mac_context.so"), - join("quartz", "CTFont.so"), - join("quartz", "CTFont.c"), - - # Win32 Agg - join("agg", "_agg.pyd"), - join("agg", "_plat_support.pyd"), - join("agg", "src", "win32", "plat_support.pyd"), - join("agg", "src", "win32", "plat_support_wrap.cpp"), - - # Win32 GL - join("gl", "_gl.pyd"), - - # *nix Agg - join("agg", "_agg.so"), - join("agg", "_plat_support.so"), - join("agg", "src", "x11", "plat_support_wrap.cpp"), - - # *nix GL - join("gl", "_gl.so"), - - # Misc - join("agg", "src", "gl", "plat_support_wrap.cpp"), - join("agg", "src", "gl", "plat_support.py"), - ) - for f in INPLACE_FILES: - f = join("kiva", f) - if os.path.isfile(f): - os.remove(f) +def agg_extensions(): + kiva_agg_dir = os.path.join('kiva', 'agg') + agg_dir = os.path.join(kiva_agg_dir, 'agg-24') + freetype_dir = os.path.join(kiva_agg_dir, 'freetype2') + freetype2_sources = [ + 'autofit/autofit.c', 'base/ftbase.c', 'base/ftbbox.c', 'base/ftbdf.c', + 'base/ftbitmap.c', 'base/ftdebug.c', 'base/ftglyph.c', 'base/ftinit.c', + 'base/ftmm.c', 'base/ftsystem.c', 'base/fttype1.c', 'base/ftxf86.c', + 'bdf/bdf.c', 'cff/cff.c', 'cid/type1cid.c', 'gzip/ftgzip.c', + 'lzw/ftlzw.c', 'pcf/pcf.c', 'pfr/pfr.c', 'psaux/psaux.c', + 'pshinter/pshinter.c', 'psnames/psnames.c', 'raster/raster.c', + 'sfnt/sfnt.c', 'smooth/smooth.c', 'truetype/truetype.c', + 'type1/type1.c', 'type42/type42.c', 'winfonts/winfnt.c', + ] + freetype2_dirs = [ + 'autofit', 'base', 'bdf', 'cache', 'cff', 'cid', 'gxvalid', 'gzip', + 'lzw', 'otvalid', 'pcf', 'pfr', 'psaux', 'pshinter', 'psnames', + 'raster', 'sfnt', 'smooth', 'tools', 'truetype', 'type1', 'type42', + 'winfonts', + ] + + kiva_agg_libraries = [] + define_macros = [ + # Numpy defines + ('NUMPY', None), + ('PY_ARRAY_TYPES_PREFIX', 'NUMPY_CXX'), + ('OWN_DIMENSIONS', '0'), + ('OWN_STRIDES', '0'), + # Freetype defines + ('FT2_BUILD_LIBRARY', None) + ] + extra_link_args = [] + include_dirs = [] + + if sys.platform == 'win32': + plat = 'win32' + kiva_agg_libraries += ['opengl32', 'glu32'] + elif sys.platform == 'darwin': + plat = 'gl' + # Options to make OS X link OpenGL + darwin_frameworks = ['ApplicationServices', 'OpenGL'] + darwin_extra_link_args = [] + for framework in darwin_frameworks: + darwin_extra_link_args.extend(['-framework', framework]) + + include_dirs += [ + '/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x + for x in darwin_frameworks + ] + define_macros += [('__DARWIN__', None)] + extra_link_args += darwin_extra_link_args + else: + # This should work for most linux distributions + plat = 'x11' + kiva_agg_libraries += ['GL', 'GLU'] + + freetype2_sources = [os.path.join(freetype_dir, 'src', src) + for src in freetype2_sources] + freetype2_dirs = [ + os.path.join(freetype_dir, 'src'), + os.path.join(freetype_dir, 'include'), + ] + [os.path.join(freetype_dir, 'src', d) for d in freetype2_dirs] + + agg_sources = [ + *glob.glob(os.path.join(agg_dir, 'src', '*.cpp')), + *glob.glob(os.path.join(agg_dir, 'font_freetype', '*.cpp')), + ] + kiva_agg_sources = [ + *glob.glob(os.path.join(kiva_agg_dir, 'src', 'gl_*.cpp')), + *glob.glob(os.path.join(kiva_agg_dir, 'src', 'kiva_*.cpp')), + ] + agg_sources + freetype2_sources + agg_include_dirs = [ + os.path.join(agg_dir, 'include'), + os.path.join(agg_dir, 'font_freetype'), + ] + freetype2_dirs + include_dirs += [ + numpy.get_include(), + os.path.join(kiva_agg_dir, 'src'), + ] + agg_include_dirs + swig_opts = [ + '-I' + os.path.join(kiva_agg_dir, 'src'), + '-I' + os.path.join(agg_dir, 'include'), + '-c++', + ] + + # Platform support extension + plat_support_sources = [ + os.path.join(kiva_agg_dir, 'src', plat, 'plat_support.i'), + os.path.join(kiva_agg_dir, 'src', plat, 'agg_bmp.cpp'), + ] + plat_support_swig_opts = [ + '-outdir', kiva_agg_dir, # write plat_support.py to this dir + '-c++', + '-I' + os.path.join(kiva_agg_dir, 'src'), + ] + plat_support_libraries = [] + if plat != 'gl': + plat_support_sources.append( + os.path.join(kiva_agg_dir, 'src', plat, + 'agg_platform_specific.cpp') + ) + if plat == 'win32': + plat_support_libraries += ['gdi32', 'user32'] + elif plat == 'x11': + plat_support_libraries += ['X11'] + + return [ + Extension( + 'kiva.agg._agg', + sources=[ + os.path.join(kiva_agg_dir, 'agg.i'), + ] + kiva_agg_sources, + swig_opts=swig_opts, + include_dirs=include_dirs, + extra_link_args=extra_link_args, + define_macros=define_macros, + libraries=kiva_agg_libraries, + language='c++', + ), + Extension( + 'kiva.agg._plat_support', + sources=plat_support_sources, + swig_opts=plat_support_swig_opts, + include_dirs=include_dirs, + extra_link_args=extra_link_args, + define_macros=define_macros, + libraries=plat_support_libraries, + language='c++', + ), + ] + + +def base_extensions(): + return [ + Extension( + 'kiva._cython_speedups', + sources=[ + 'kiva/_cython_speedups.pyx', + 'kiva/_hit_test.cpp' + ], + depends=[ + 'kiva/_hit_test.h', + 'kiva/_hit_test.pxd', + ], + include_dirs=['kiva', numpy.get_include()], + language='c++', + ), + ] + + +def macos_extensions(): + extra_link_args = [] + frameworks = [ + 'Cocoa', 'CoreFoundation', 'ApplicationServices', 'Foundation' + ] + include_dirs = [ + '/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x + for x in frameworks + ] + for framework in frameworks: + extra_link_args.extend(['-framework', framework]) + + return[ + Extension( + 'kiva.quartz.ABCGI', + sources=[ + 'kiva/quartz/ABCGI.pyx', + 'kiva/quartz/Python.pxi', + 'kiva/quartz/numpy.pxi', + 'kiva/quartz/c_numpy.pxd', + 'kiva/quartz/CoreFoundation.pxi', + 'kiva/quartz/CoreGraphics.pxi', + 'kiva/quartz/CoreText.pxi', + ], + extra_link_args=extra_link_args, + include_dirs=[numpy.get_include()], + ), + Extension( + 'kiva.quartz.CTFont', + sources=[ + 'kiva/quartz/CTFont.pyx', + 'kiva/quartz/CoreFoundation.pxi', + 'kiva/quartz/CoreGraphics.pxi', + 'kiva/quartz/CoreText.pxi', + ], + extra_link_args=extra_link_args, + ), + Extension( + 'kiva.quartz.mac_context', + sources=[ + 'kiva/quartz/mac_context.c', + 'kiva/quartz/mac_context_cocoa.m', + ], + depends=[ + 'kiva/quartz/mac_context.h', + ], + extra_link_args=extra_link_args, + include_dirs=include_dirs, + ) + ] if __name__ == "__main__": @@ -247,12 +344,13 @@ def run(self): write_version_py(filename='kiva/_version.py') from enable import __version__, __extras_require__, __requires__ - # Build the full set of packages by appending any found by setuptools' - # find_packages to those discovered by numpy.distutils. - config = configuration().todict() - packages = setuptools.find_packages(exclude=config['packages'] + - ['docs', 'examples']) - config['packages'] += packages + with open('README.rst', 'r') as fp: + long_description = fp.read() + + # Collect extensions + ext_modules = base_extensions() + agg_extensions() + if sys.platform == 'darwin': + ext_modules += macos_extensions() setup(name='enable', version=__version__, @@ -261,6 +359,10 @@ def run(self): maintainer='ETS Developers', maintainer_email='enthought-dev@enthought.com', url='https://github.com/enthought/enable/', + # Note that this URL is only valid for tagged releases. + download_url=('https://github.com/enthought/enable/archive/' + '{0}.tar.gz'.format(__version__)), + license='BSD', classifiers=[c.strip() for c in """\ Development Status :: 5 - Production/Stable Intended Audience :: Developers @@ -277,28 +379,24 @@ def run(self): Topic :: Software Development Topic :: Software Development :: Libraries """.splitlines() if len(c.strip()) > 0], - cmdclass={ - # Work around a numpy distutils bug by forcing the use of the - # setuptools' sdist command. - 'sdist': setuptools.command.sdist.sdist, - # Use our customized commands - 'clean': MyClean, - 'build_py': MyBuildPy, - }, + platforms=['Windows', 'Linux', 'macOS', 'Unix', 'Solaris'], description='low-level drawing and interaction', + long_description=long_description, + install_requires=__requires__, extras_require=__extras_require__, - long_description=open('README.rst').read(), - # Note that this URL is only valid for tagged releases. - download_url=('https://github.com/enthought/enable/archive/' - '{0}.tar.gz'.format(__version__)), + cmdclass={ + 'build': PatchedBuild, + 'install': PatchedInstall, + 'build_ext': build_ext, + }, entry_points={ "etsdemo_data": [ "enable_examples = enable.examples._etsdemo_info:info", "kiva_examples = kiva.examples._etsdemo_info:info", ] }, - install_requires=__requires__, - license='BSD', + ext_modules=ext_modules, + packages=find_packages(exclude=['ci', 'docs']), package_data={ '': ['*.zip', '*.svg', 'images/*'], 'enable': ['tests/primitives/data/PngSuite/*.png'], @@ -315,6 +413,5 @@ def run(self): 'kiva.examples': ['kiva/*', 'kiva/*/*'], }, - platforms=["Windows", "Linux", "Mac OS-X", "Unix", "Solaris"], zip_safe=False, - **config) + ) From 11eeee1d361de5b9a65fa4d968c589a8d4cc4ea2 Mon Sep 17 00:00:00 2001 From: John Wiggins Date: Mon, 11 Jan 2021 10:10:20 +0100 Subject: [PATCH 2/4] Update MANIFEST.in --- MANIFEST.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index cb1543f21..6de23a1f8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,12 +5,16 @@ include font_LICENSE.txt include fonttools_LICENSE.txt include image_LICENSE.txt include image_LICENSE_*.txt -include kiva/agg/agg.i include docs/Makefile include docs/kiva/agg/notes +include kiva/_cython_speedups.cpp +include kiva/_hit_test.* recursive-include docs *.py *.rst *.txt *.css *.png *.ico *.doc recursive-include enable/examples *.py *.svg *.jpg *.enaml recursive-include kiva/examples *.py *.txt *.gif *.jpg +recursive-include kiva/agg *.py *.i *.cpp *.h *.c +recursive-include kiva/agg/LICENSES * +recursive-include kiva/fonttools/tests/data *.ttc *.ttf +recursive-include kiva/fonttools/LICENSES * recursive-include kiva/gl *.h *.cpp *.i LICENSE_* recursive-include kiva/quartz *.pyx *.pxi *.pxd mac_context*.* -recursive-include kiva/fonttools/tests/data *.ttc *.ttf From cce8e3b86b21ab1e6df58ae63d5906d481bce2e0 Mon Sep 17 00:00:00 2001 From: John Wiggins Date: Thu, 28 Jan 2021 11:13:25 +0100 Subject: [PATCH 3/4] Add GL build to main setup.py --- kiva/gl/setup.py | 93 ------------------------------------------------ setup.py | 91 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 78 insertions(+), 106 deletions(-) delete mode 100644 kiva/gl/setup.py diff --git a/kiva/gl/setup.py b/kiva/gl/setup.py deleted file mode 100644 index a26a241e9..000000000 --- a/kiva/gl/setup.py +++ /dev/null @@ -1,93 +0,0 @@ -import platform - - -def configuration(parent_package='', top_path=None): - import numpy - from numpy.distutils.misc_util import Configuration - - config = Configuration('gl', parent_package, top_path) - is_windows = (platform.system() == 'Windows') - is_macos = (platform.system() == 'Darwin') - - sources = [ - # agg pieces - 'src/agg/agg_bezier_arc.cpp', - 'src/agg/agg_sqrt_tables.cpp', - 'src/agg/agg_trans_affine.cpp', - # kiva_gl - 'src/kiva_gl_affine_helpers.cpp', - 'src/kiva_gl_compiled_path.cpp', - 'src/kiva_gl_font_type.cpp', - 'src/kiva_gl_graphics_context_base.cpp', - 'src/kiva_gl_graphics_context.cpp', - 'src/kiva_gl_rect.cpp', - ] - include_dirs = ['src', 'src/agg', numpy.get_include()] - macros = [] - if is_macos: - macros = [ - ('__DARWIN__', None), - # OpenGL is deprecated starting with macOS 10.14 and gone in 10.15 - # But that doesn't mean we want to hear about it. We know, Apple. - ('GL_SILENCE_DEPRECATION', None), - ] - - config.add_library( - 'kiva_gl_src', sources, - include_dirs=include_dirs, - # Use "macros" instead of "define_macros" because the - # latter is only used for extensions, and not clibs - macros=macros, - ) - - include_dirs.append('src/swig') - - build_libraries = ['kiva_gl_src'] - extra_link_args = [] - define_macros = [] - if is_windows: - # Visual studio does not support/need these - extra_compile_args = [] - else: - extra_compile_args = [ - '-Wfatal-errors', - '-Wno-unused-function', - ] - - if is_windows: - build_libraries += ['opengl32', 'glu32'] - elif is_macos: - # Options to make macOS link OpenGL - if '64bit' not in platform.architecture(): - darwin_frameworks = ['Carbon', 'ApplicationServices', 'OpenGL'] - else: - darwin_frameworks = ['ApplicationServices', 'OpenGL'] - - for framework in darwin_frameworks: - extra_link_args.extend(['-framework', framework]) - - include_dirs.extend([ - '/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x - for x in darwin_frameworks - ]) - define_macros = [ - ('__DARWIN__', None), - # OpenGL is deprecated starting with macOS 10.14 and gone in 10.15 - # But that doesn't mean we want to hear about it. We know, Apple. - ('GL_SILENCE_DEPRECATION', None), - ] - else: - # This should work for most linuxes (linuces?) - build_libraries += ['GL', 'GLU'] - - config.add_extension( - '_gl', - sources=['gl.i'], - include_dirs=include_dirs, - define_macros=define_macros, - libraries=build_libraries, - extra_compile_args=extra_compile_args, - extra_link_args=extra_link_args, - language='c++', - ) - return config diff --git a/setup.py b/setup.py index 57b486c4e..9dc11bf51 100644 --- a/setup.py +++ b/setup.py @@ -158,7 +158,6 @@ def agg_extensions(): 'winfonts', ] - kiva_agg_libraries = [] define_macros = [ # Numpy defines ('NUMPY', None), @@ -173,25 +172,20 @@ def agg_extensions(): if sys.platform == 'win32': plat = 'win32' - kiva_agg_libraries += ['opengl32', 'glu32'] elif sys.platform == 'darwin': - plat = 'gl' - # Options to make OS X link OpenGL - darwin_frameworks = ['ApplicationServices', 'OpenGL'] - darwin_extra_link_args = [] + plat = 'osx' + darwin_frameworks = ['ApplicationServices'] for framework in darwin_frameworks: - darwin_extra_link_args.extend(['-framework', framework]) + extra_link_args.extend(['-framework', framework]) include_dirs += [ '/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x for x in darwin_frameworks ] define_macros += [('__DARWIN__', None)] - extra_link_args += darwin_extra_link_args else: # This should work for most linux distributions plat = 'x11' - kiva_agg_libraries += ['GL', 'GLU'] freetype2_sources = [os.path.join(freetype_dir, 'src', src) for src in freetype2_sources] @@ -205,7 +199,6 @@ def agg_extensions(): *glob.glob(os.path.join(agg_dir, 'font_freetype', '*.cpp')), ] kiva_agg_sources = [ - *glob.glob(os.path.join(kiva_agg_dir, 'src', 'gl_*.cpp')), *glob.glob(os.path.join(kiva_agg_dir, 'src', 'kiva_*.cpp')), ] + agg_sources + freetype2_sources agg_include_dirs = [ @@ -233,7 +226,7 @@ def agg_extensions(): '-I' + os.path.join(kiva_agg_dir, 'src'), ] plat_support_libraries = [] - if plat != 'gl': + if plat != 'osx': plat_support_sources.append( os.path.join(kiva_agg_dir, 'src', plat, 'agg_platform_specific.cpp') @@ -253,7 +246,6 @@ def agg_extensions(): include_dirs=include_dirs, extra_link_args=extra_link_args, define_macros=define_macros, - libraries=kiva_agg_libraries, language='c++', ), Extension( @@ -287,6 +279,79 @@ def base_extensions(): ] +def gl_extensions(): + kiva_gl_dir = os.path.join('kiva', 'gl') + agg_dir = os.path.join(kiva_gl_dir, 'src', 'agg') + + kiva_gl_libraries = [] + define_macros = [] + extra_compile_args = [] + extra_link_args = [] + include_dirs = [] + + if sys.platform == 'win32': + kiva_gl_libraries += ['opengl32', 'glu32'] + elif sys.platform == 'darwin': + # Options to make macOS link OpenGL + darwin_frameworks = ['ApplicationServices', 'OpenGL'] + for framework in darwin_frameworks: + extra_link_args.extend(['-framework', framework]) + + include_dirs += [ + '/System/Library/Frameworks/%s.framework/Versions/A/Headers' % x + for x in darwin_frameworks + ] + define_macros += [ + ('__DARWIN__', None), + # OpenGL is deprecated starting with macOS 10.14 and gone in 10.15 + # But that doesn't mean we want to hear about it. We know, Apple. + ('GL_SILENCE_DEPRECATION', None), + ] + extra_compile_args = [ + '-Wfatal-errors', + '-Wno-unused-function', + ] + else: + # This should work for most linux distributions + kiva_gl_libraries += ['GL', 'GLU'] + extra_compile_args = [ + '-Wfatal-errors', + '-Wno-unused-function', + ] + + kiva_gl_sources = [ + *glob.glob(os.path.join(kiva_gl_dir, 'src', 'kiva_gl_*.cpp')), + *glob.glob(os.path.join(agg_dir, '*.cpp')), + ] + include_dirs += [ + os.path.join(kiva_gl_dir, 'src'), + agg_dir, + numpy.get_include(), + ] + swig_opts = [ + '-I' + os.path.join(kiva_gl_dir, 'src', 'swig'), + '-I' + os.path.join(kiva_gl_dir, 'src'), + '-I' + agg_dir, + '-c++', + ] + + return [ + Extension( + 'kiva.gl._gl', + sources=[ + os.path.join(kiva_gl_dir, 'gl.i'), + ] + kiva_gl_sources, + swig_opts=swig_opts, + include_dirs=include_dirs, + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, + define_macros=define_macros, + libraries=kiva_gl_libraries, + language='c++', + ), + ] + + def macos_extensions(): extra_link_args = [] frameworks = [ @@ -348,7 +413,7 @@ def macos_extensions(): long_description = fp.read() # Collect extensions - ext_modules = base_extensions() + agg_extensions() + ext_modules = base_extensions() + agg_extensions() + gl_extensions() if sys.platform == 'darwin': ext_modules += macos_extensions() From b62d1e0080534ba2ab658b512d67949f2e6ba5bb Mon Sep 17 00:00:00 2001 From: John Wiggins Date: Fri, 29 Jan 2021 10:19:40 +0100 Subject: [PATCH 4/4] More MANIFEST.in changes --- MANIFEST.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 6de23a1f8..2a5417398 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -7,12 +7,14 @@ include image_LICENSE.txt include image_LICENSE_*.txt include docs/Makefile include docs/kiva/agg/notes -include kiva/_cython_speedups.cpp +include kiva/_cython_speedups.* include kiva/_hit_test.* recursive-include docs *.py *.rst *.txt *.css *.png *.ico *.doc recursive-include enable/examples *.py *.svg *.jpg *.enaml recursive-include kiva/examples *.py *.txt *.gif *.jpg recursive-include kiva/agg *.py *.i *.cpp *.h *.c +recursive-include kiva/agg/agg-24 * +recursive-include kiva/agg/freetype2 * recursive-include kiva/agg/LICENSES * recursive-include kiva/fonttools/tests/data *.ttc *.ttf recursive-include kiva/fonttools/LICENSES *