# -*- coding: utf-8 -*- """ https://github.com/cython/cython/wiki/PackageHierarchy """ import os import sys import setuptools from distutils.core import setup from distutils.extension import Extension # from setuptools import setup, find_packages # from setuptools.extension import Extension import shutil from pathlib import Path import glob # we'd better have Cython installed, or it's a no-go try: # from Cython.Distutils import build_ext from distutils.command.build_ext import build_ext from Cython.Build import cythonize except ImportError: print("You don't seem to have Cython installed. Please get a") print("copy from www.cython.org and install it") sys.exit(1) # https://stackoverflow.com/questions/58797673/how-to-compile-init-py # -file-using-cython-on-window def get_export_symbols_fixed(self, ext): pass # return [] also does the job! # replace wrong version with the fixed: build_ext.get_export_symbols = get_export_symbols_fixed # scan directory for extension files, converting # them to extension names in dotted notation def scan_dir(dir, files=[], file_ext='.py'): for file in os.listdir(dir): path = os.path.join(dir, file) if os.path.isfile(path) and path.endswith(file_ext): files.append(path.replace(os.path.sep, ".")[:-len(file_ext)]) elif os.path.isdir(path): scan_dir(path, files, file_ext=file_ext) return files # https://groups.google.com/forum/#!msg/cython-users/JV1-KvIUeIg/A1tHkJfvTmEJ # Robert Bradshaw: you should compile with flag -fno-strict-aliasing # Generate an Extension object from its dotted name def make_extension(ext_name, file_ext='.py', include_dir='.'): ext_path = ext_name.replace(".", os.path.sep) + file_ext return Extension( ext_name, [ext_path], # adding the '.' to include_dirs is CRUCIAL!! include_dirs=[include_dir, "."], # extra_compile_args=["-O3", "-Wall", "-fno-strict-aliasing"], # extra_link_args=['-g'], ) def copy_file(file, source_dir, destination_dir): if not (source_dir / file).exists(): return shutil.copyfile(str(source_dir / file), str(destination_dir / file)) def copy_folder(folder, source_dir, destination_dir): if not (source_dir / folder).exists(): return if (destination_dir / folder).exists(): shutil.rmtree(str(destination_dir / folder)) shutil.copytree(str(source_dir / folder), str(destination_dir / folder)) # From this SO, package_data does not work. Try subclass build_ext. # https://stackoverflow.com/questions/7522250/how-to-include-package-data- # with-setuptools-distribute # package_data = {'ezcad': ['fonts/*', 'images/*', 'locale/*', 'main.py']}, class CustomBuildExt(build_ext): def run(self): build_ext.run(self) build_dir = Path(self.build_lib) root_dir = Path(__file__).parent target_dir = build_dir if not self.inplace else root_dir # Remove compiled __main__* files which are precedent than # __main__.py, which is needed for launch "python -m ezcad". file_list = glob.glob(str(target_dir / 'ezcad/__main__.*')) for file in file_list: if os.path.isfile(file): os.remove(file) copy_file(Path('ezcad') / '__main__.py', root_dir, target_dir) # Copy package data folders copy_folder(Path('ezcad/fonts'), root_dir, target_dir) copy_folder(Path('ezcad/images'), root_dir, target_dir) copy_folder(Path('ezcad/locale'), root_dir, target_dir) def main(): # file_ext = ".pyx" file_ext = ".py" include_dir = os.path.dirname(os.path.realpath(__file__)) print('Include directory:', include_dir) # get the list of extensions ext_names = scan_dir("ezcad", file_ext=file_ext) print("Number of ext modules =", len(ext_names)) # and build up the set of Extension objects extensions = [make_extension(name, file_ext=file_ext, include_dir=include_dir) for name in ext_names] ext_modules = cythonize(extensions, compiler_directives={'language_level': "3"}) # long_description = """\ # A tool for data visualization and analysis, geophysical and beyond. # """ with open("README.md", "r") as fh: long_description = fh.read() from ezcad import __version__ as version install_requires = [ 'chardet', 'cycler', 'freetype-py', 'joblib', 'kiwisolver', 'lxml', 'matplotlib', 'numpy', 'pandas', 'PyOpenGL', 'pyparsing', 'PyQt5', 'pyqtgraph >= 0.11.0rc0', 'python-dateutil', 'python-dotenv', 'pytz', 'QtAwesome', 'QtPy', 'scipy', 'six', 'vispy', 'Yapsy', ] setup( name='ezcad', version=version, author='ezcad team', author_email='ezcad.dev@gmail.com', description='Easy computer-aided design', long_description=long_description, long_description_content_type="text/markdown", # url='https://github.com/ezcad-dev/ezcad.git', url='http://ezcad.org', # packages=find_packages(), # packages=['ezcad'], ext_modules=ext_modules, # package_data=package_data, # cmdclass={'build_ext': build_ext}, cmdclass={'build_ext': CustomBuildExt}, install_requires=install_requires, ) print("version =", version) if __name__ == '__main__': main()