forked from chython/chython
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.py
More file actions
72 lines (66 loc) · 2.56 KB
/
build.py
File metadata and controls
72 lines (66 loc) · 2.56 KB
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
# -*- coding: utf-8 -*-
#
# Copyright 2023 Ramil Nugmanov <nougmanoff@protonmail.com>
# This file is part of chython.
#
# chython is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, see <https://www.gnu.org/licenses/>.
#
from Cython.Build import build_ext, cythonize
from pathlib import Path
from setuptools import Extension
from setuptools.dist import Distribution
from shutil import copyfile
from sysconfig import get_platform
platform = get_platform()
if platform == 'win-amd64':
libname = 'libinchi.dll'
extra_compile_args = ['/O2']
elif platform == 'linux-x86_64':
libname = 'libinchi.so'
extra_compile_args = ['-O3']
elif platform.startswith('macosx') and platform.endswith('x86_64'):
libname = 'libinchi.dynlib'
extra_compile_args = []
elif platform.startswith('macosx') and platform.endswith('arm64'):
libname = 'libinchi_arm64.dylib'
extra_compile_args = []
else:
libname = None
extra_compile_args = []
if libname:
copyfile(Path('INCHI') / libname, Path('chython/files/libinchi') / libname)
extensions = [
Extension('chython.algorithms._isomorphism',
['chython/algorithms/_isomorphism.pyx'],
extra_compile_args=extra_compile_args),
Extension('chython.containers._pack',
['chython/containers/_pack.pyx'],
extra_compile_args=extra_compile_args),
Extension('chython.containers._unpack',
['chython/containers/_unpack.pyx'],
extra_compile_args=extra_compile_args),
Extension('chython.containers._cpack',
['chython/containers/_cpack.pyx'],
extra_compile_args=extra_compile_args),
Extension('chython.files._xyz',
['chython/files/_xyz.pyx'],
extra_compile_args=extra_compile_args)
]
ext_modules = cythonize(extensions, language_level=3)
cmd = build_ext(Distribution({'ext_modules': ext_modules}))
cmd.ensure_finalized()
cmd.run()
for output in cmd.get_outputs():
output = Path(output)
copyfile(output, output.relative_to(cmd.build_lib))