| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
options={'bdist_wheel': {'py_limited_api': 'cp32'}}, |
| 66 |
cmdclass={'egg_info': EggInfo}, |
| 67 |
) |