Debian Codegraph @

tests/minimext/setup.py

raw symbols SCIP
1 # Copyright (C) 2024 Stewart Miles
2 # Licensed to the Python Software Foundation under a contributor agreement.
3 # See LICENSE.txt and CONTRIBUTORS.txt.
4 import codecs
5 import os
6 import json
7 from setuptools import Extension, setup
8 from setuptools.command import egg_info
9 import sys
10
11
12 EMBED_EXTENSIONS_METADATA = (
13 int(os.getenv('MINIMEXT_EMBED_EXTENSIONS_METADATA', '0')))
14
15
16 class EggInfo(egg_info.egg_info):
17 """egg_info command that optionally writes extensions metadata.
18
19 distlib.wheel.Wheel attempts to read the list of extensions from the
20 undocumented JSON EXTENSIONS metadata file.
21
22 This command will add the special file JSON EXTENSIONS metadata file to the
23 *.dist-info directory in the wheel if the
24 MINIMEXT_EMBED_EXTENSIONS_METADATA environment variable is set to 1.
25 """
26
27 def run(self):
28 egg_info.egg_info.run(self)
29 if EMBED_EXTENSIONS_METADATA:
30 build_ext = self.get_finalized_command('build_ext')
31 extensions_dict = {
32 ext_module.name: build_ext.get_ext_filename(ext_module.name)
33 for ext_module in self.distribution.ext_modules
34 }
35 with open(os.path.join(self.egg_info, 'EXTENSIONS'), 'wb') as (
36 extensions_file):
37 json.dump(extensions_dict,
38 codecs.getwriter('utf-8')(extensions_file),
39 indent=2)
40
41
42 setup(
43 name='minimext' + ('_metadata' if EMBED_EXTENSIONS_METADATA else ''),
44 version='0.1',
45 description='Calculates Fibonacci numbers.',
46 long_description=(
47 'Distribution that provides calculate.fib() and calculate_py.fib() '
48 'which calculate Fibonacci numbers. minimext.calculate is implemented '
49 'as a C extension to test distlib.wheel.Wheel.mount().'),
50 packages=['minimext'],
51 ext_modules=[
52 Extension(name='minimext.calculate',
53 sources=['calculate.c'],
54 py_limited_api=True,
55 define_macros=[
56 ('Py_LIMITED_API', str(sys.version_info.major)),
57 ]),
58 ],
59 # The extension uses the limited API so tag the wheel as compatible with
60 # Python 3.2 and later.
61 #
62 # Unfortunately the py_limited_api argument to Extension does not mark the
63 # wheel as supporting the limited API, so set the see compatibility
64 # manually.
65 options={'bdist_wheel': {'py_limited_api': 'cp32'}},
66 cmdclass={'egg_info': EggInfo},
67 )