solvespace/cython/setup.py

139 lines
3.6 KiB
Python
Raw Normal View History

2019-05-28 12:00:15 +00:00
# -*- coding: utf-8 -*-
"""Compile the Cython libraries of Python-Solvespace."""
__author__ = "Yuan Chang"
__copyright__ = "Copyright (C) 2016-2019"
__license__ = "GPLv3+"
__email__ = "pyslvs@gmail.com"
import os
2019-08-31 01:57:49 +00:00
from os.path import (
abspath,
dirname,
join as pth_join,
)
2019-05-28 12:00:15 +00:00
import re
import codecs
2019-05-29 06:34:49 +00:00
from textwrap import dedent
2019-05-28 12:00:15 +00:00
from setuptools import setup, Extension, find_packages
2019-05-29 06:34:49 +00:00
from setuptools.command.build_ext import build_ext
2019-05-28 12:00:15 +00:00
from platform import system
from distutils import sysconfig
2019-08-31 01:57:49 +00:00
here = abspath(dirname(__file__))
2019-05-28 12:00:15 +00:00
include_path = '../include/'
src_path = '../src/'
platform_path = src_path + 'platform/'
ver = sysconfig.get_config_var('VERSION')
lib = sysconfig.get_config_var('BINDIR')
2019-05-29 06:34:49 +00:00
def write(doc, *parts):
2019-08-31 01:57:49 +00:00
with codecs.open(pth_join(here, *parts), 'w') as f:
2019-05-29 06:34:49 +00:00
f.write(doc)
2019-05-28 12:00:15 +00:00
def read(*parts):
2019-08-31 01:57:49 +00:00
with codecs.open(pth_join(here, *parts), 'r') as f:
2019-05-28 12:00:15 +00:00
return f.read()
2019-09-23 02:30:20 +00:00
def find_version(*file_paths):
m = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", read(*file_paths), re.M)
if m:
return m.group(1)
2019-05-28 12:00:15 +00:00
raise RuntimeError("Unable to find version string.")
macros = [
('_hypot', 'hypot'),
('M_PI', 'PI'), # C++ 11
('ISOLATION_AWARE_ENABLED', None),
('LIBRARY', None),
('EXPORT_DLL', None),
('_CRT_SECURE_NO_WARNINGS', None),
]
compile_args = [
'-O3',
'-Wno-cpp',
'-g',
'-Wno-write-strings',
'-fpermissive',
'-fPIC',
'-std=c++11',
]
sources = [
'python_solvespace/' + 'slvs.pyx',
src_path + 'util.cpp',
src_path + 'entity.cpp',
src_path + 'expr.cpp',
src_path + 'constrainteq.cpp',
src_path + 'constraint.cpp',
src_path + 'system.cpp',
src_path + 'lib.cpp',
]
if system() == 'Windows':
# Avoid compile error with CYTHON_USE_PYLONG_INTERNALS.
# https://github.com/cython/cython/issues/2670#issuecomment-432212671
macros.append(('MS_WIN64', None))
# Disable format warning
compile_args.append('-Wno-format')
# Solvespace arguments
macros.append(('WIN32', None))
# Platform sources
2019-05-29 06:34:49 +00:00
sources.append(platform_path + 'utilwin.cpp')
2019-05-28 12:00:15 +00:00
sources.append(platform_path + 'platform.cpp')
else:
2019-05-29 06:34:49 +00:00
sources.append(platform_path + 'utilunix.cpp')
class Build(build_ext):
def run(self):
# Generate "config.h", actually not used.
config_h = src_path + "config.h"
write(dedent(f"""\
#ifndef SOLVESPACE_CONFIG_H
#define SOLVESPACE_CONFIG_H
#endif
"""), config_h)
super(Build, self).run()
os.remove(config_h)
2019-05-28 12:00:15 +00:00
setup(
name="python_solvespace",
2019-09-23 02:30:20 +00:00
version=find_version('python_solvespace', '__init__.py'),
2019-05-28 12:00:15 +00:00
author=__author__,
author_email=__email__,
description="Python library of Solvespace",
long_description=read("README.md"),
2019-09-23 13:24:08 +00:00
long_description_content_type='text/markdown',
2019-05-28 12:00:15 +00:00
url="https://github.com/solvespace/solvespace",
packages=find_packages(exclude=('tests',)),
2019-05-29 09:44:55 +00:00
package_data={'': ["*.pyi"]},
2019-05-28 12:00:15 +00:00
ext_modules=[Extension(
2019-05-29 06:34:49 +00:00
"python_solvespace.slvs",
2019-05-28 12:00:15 +00:00
sources,
language="c++",
include_dirs=[include_path, src_path, platform_path],
define_macros=macros,
extra_compile_args=compile_args
)],
2019-05-29 06:34:49 +00:00
cmdclass={'build_ext': Build},
2019-05-28 12:00:15 +00:00
python_requires=">=3.6",
2019-09-13 06:22:10 +00:00
install_requires=read('requirements.txt').splitlines(),
2019-09-06 04:43:52 +00:00
test_suite="tests",
2019-05-28 12:00:15 +00:00
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Cython",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Operating System :: OS Independent",
]
)