Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
keewenaw
GitHub Repository: keewenaw/ethereum-wallet-cracker
Path: blob/main/test/lib/python3.9/site-packages/setuptools/extension.py
4798 views
1
import re
2
import functools
3
import distutils.core
4
import distutils.errors
5
import distutils.extension
6
7
from .monkey import get_unpatched
8
9
10
def _have_cython():
11
"""
12
Return True if Cython can be imported.
13
"""
14
cython_impl = 'Cython.Distutils.build_ext'
15
try:
16
# from (cython_impl) import build_ext
17
__import__(cython_impl, fromlist=['build_ext']).build_ext
18
return True
19
except Exception:
20
pass
21
return False
22
23
24
# for compatibility
25
have_pyrex = _have_cython
26
27
_Extension = get_unpatched(distutils.core.Extension)
28
29
30
class Extension(_Extension):
31
"""Extension that uses '.c' files in place of '.pyx' files"""
32
33
def __init__(self, name, sources, *args, **kw):
34
# The *args is needed for compatibility as calls may use positional
35
# arguments. py_limited_api may be set only via keyword.
36
self.py_limited_api = kw.pop("py_limited_api", False)
37
super().__init__(name, sources, *args, **kw)
38
39
def _convert_pyx_sources_to_lang(self):
40
"""
41
Replace sources with .pyx extensions to sources with the target
42
language extension. This mechanism allows language authors to supply
43
pre-converted sources but to prefer the .pyx sources.
44
"""
45
if _have_cython():
46
# the build has Cython, so allow it to compile the .pyx files
47
return
48
lang = self.language or ''
49
target_ext = '.cpp' if lang.lower() == 'c++' else '.c'
50
sub = functools.partial(re.sub, '.pyx$', target_ext)
51
self.sources = list(map(sub, self.sources))
52
53
54
class Library(Extension):
55
"""Just like a regular Extension, but built as a library instead"""
56
57