-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathsetup.py
More file actions
142 lines (120 loc) · 4.24 KB
/
Copy pathsetup.py
File metadata and controls
142 lines (120 loc) · 4.24 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
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
138
139
140
141
142
# transformations/setup.py
"""Transformations package Setuptools script."""
import os
import re
import sys
import sysconfig
import numpy
from setuptools import Extension, setup
LIMITED_API = os.environ.get('CG_LIMITED_API', '1').lower() in {'1', 'true'}
GIL_DISABLED = bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
if LIMITED_API and not GIL_DISABLED:
py_limited_api = True
define_macros = [('Py_LIMITED_API', 0x030C0000)]
setup_options = {'bdist_wheel': {'py_limited_api': 'cp312'}}
else:
py_limited_api = False
define_macros = []
setup_options = {}
def search(pattern: str, string: str, flags: int = 0) -> str:
"""Return first match of pattern in string."""
match = re.search(pattern, string, flags)
if match is None:
msg = f'{pattern=!r} not found'
raise ValueError(msg)
return match.groups()[0]
def fix_docstring_examples(docstring: str) -> str:
"""Return docstring with examples fixed for GitHub."""
start = True
indent = False
lines = ['..', ' This file is generated by setup.py', '']
for line in docstring.splitlines():
if not line.strip():
start = True
indent = False
if line.startswith('>>> '):
indent = True
if start:
lines.extend(['.. code-block:: python', ''])
start = False
lines.append((' ' if indent else '') + line)
return '\n'.join(lines)
with open('transformations/transformations.py', encoding='utf-8') as fh:
code = fh.read()
version = search(r"__version__ = '(.*?)'", code).replace('.x.x', '.dev0')
description = search(r'"""(.*)\.(?:\r\n|\r|\n)', code)
readme = search(
r'(?:\r\n|\r|\n){2}"""(.*)"""(?:\r\n|\r|\n){2}from __future__',
code,
re.MULTILINE | re.DOTALL,
)
readme = '\n'.join(
[description, '=' * len(description), *readme.splitlines()[1:]]
)
if 'sdist' in sys.argv:
# update README, LICENSE, and CHANGES files
with open('README.rst', 'w', encoding='utf-8') as fh:
fh.write(fix_docstring_examples(readme))
license = search(
r'(# Copyright.*?(?:\r\n|\r|\n))(?:\r\n|\r|\n)+""',
code,
re.MULTILINE | re.DOTALL,
)
license = license.replace('# ', '').replace('#', '')
with open('LICENSE', 'w', encoding='utf-8') as fh:
fh.write('BSD-3-Clause license\n\n')
fh.write(license)
revisions = search(
r'(?:\r\n|\r|\n){2}(Revisions.*)- …',
readme,
re.MULTILINE | re.DOTALL,
).strip()
with open('CHANGES.rst', encoding='utf-8') as fh:
old = fh.read()
old = old.split(revisions.splitlines()[-1])[-1]
with open('CHANGES.rst', 'w', encoding='utf-8') as fh:
fh.write(revisions.strip())
fh.write(old)
setup(
name='transformations',
version=version,
license='BSD-3-Clause',
description=description,
long_description=readme,
long_description_content_type='text/x-rst',
author='Christoph Gohlke',
author_email='cgohlke@cgohlke.com',
url='https://www.cgohlke.com',
project_urls={
'Bug Tracker': 'https://github.com/cgohlke/transformations/issues',
'Source Code': 'https://github.com/cgohlke/transformations',
# 'Documentation': 'https://www.cgohlke.com/docs/transformations/',
},
python_requires='>=3.12',
install_requires=['numpy>=2.1'],
packages=['transformations'],
ext_modules=[
Extension(
'transformations._transformations',
['transformations/transformations.c'],
include_dirs=[numpy.get_include()],
libraries=(['bcrypt'] if sys.platform == 'win32' else []),
define_macros=define_macros,
py_limited_api=py_limited_api,
)
],
options=setup_options,
platforms=['any'],
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Science/Research',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3.14',
'Programming Language :: Python :: 3.15',
],
)