|
|
@@ -21,12 +21,16 @@ |
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
|
|
# SOFTWARE. |
|
|
|
|
|
|
|
import os |
|
|
|
import sys |
|
|
|
|
|
|
|
if (sys.version_info[0] == 2 and sys.version_info[1] < 6) or \ |
|
|
|
(sys.version_info[1] == 3 and sys.version_info[1] < 2): |
|
|
|
raise Exception("mwparserfromhell needs Python 2.6+ or 3.2+") |
|
|
|
|
|
|
|
if sys.version_info >= (3, 0): |
|
|
|
basestring = (str, ) |
|
|
|
|
|
|
|
from setuptools import setup, find_packages, Extension |
|
|
|
|
|
|
|
from mwparserfromhell import __version__ |
|
|
@@ -39,7 +43,63 @@ tokenizer = Extension("mwparserfromhell.parser._tokenizer", |
|
|
|
sources=["mwparserfromhell/parser/tokenizer.c"], |
|
|
|
depends=["mwparserfromhell/parser/tokenizer.h"]) |
|
|
|
|
|
|
|
setup( |
|
|
|
use_extension=True |
|
|
|
|
|
|
|
# Allow env var WITHOUT_EXTENSION and args --with[out]-extension |
|
|
|
if '--without-extension' in sys.argv: |
|
|
|
use_extension = False |
|
|
|
elif '--with-extension' in sys.argv: |
|
|
|
pass |
|
|
|
elif os.environ.get('WITHOUT_EXTENSION', '0') == '1': |
|
|
|
use_extension = False |
|
|
|
|
|
|
|
# Remove the command line argument as it isnt understood by |
|
|
|
# setuptools/distutils |
|
|
|
sys.argv = [arg for arg in sys.argv |
|
|
|
if not arg.startswith('--with') |
|
|
|
and not arg.endswith('-extension')] |
|
|
|
|
|
|
|
|
|
|
|
def optional_compile_setup(func=setup, use_ext=use_extension, |
|
|
|
*args, **kwargs): |
|
|
|
""" |
|
|
|
Wrap setup to allow optional compilation of extensions. |
|
|
|
|
|
|
|
Falls back to pure python mode (no extensions) |
|
|
|
if compilation of extensions fails. |
|
|
|
""" |
|
|
|
extensions = kwargs.get('ext_modules', None) |
|
|
|
|
|
|
|
if use_ext and extensions: |
|
|
|
try: |
|
|
|
func(*args, **kwargs) |
|
|
|
return |
|
|
|
except SystemExit as e: |
|
|
|
assert(e.args) |
|
|
|
if e.args[0] is False: |
|
|
|
raise |
|
|
|
elif isinstance(e.args[0], basestring): |
|
|
|
if e.args[0].startswith('usage: '): |
|
|
|
raise |
|
|
|
else: |
|
|
|
# Fallback to pure python mode |
|
|
|
print('setup with extension failed: %s' % repr(e)) |
|
|
|
pass |
|
|
|
except Exception as e: |
|
|
|
print('setup with extension failed: %s' % repr(e)) |
|
|
|
|
|
|
|
if extensions: |
|
|
|
if use_ext: |
|
|
|
print('Falling back to pure python mode.') |
|
|
|
else: |
|
|
|
print('Using pure python mode.') |
|
|
|
|
|
|
|
del kwargs['ext_modules'] |
|
|
|
|
|
|
|
func(*args, **kwargs) |
|
|
|
|
|
|
|
|
|
|
|
optional_compile_setup( |
|
|
|
name = "mwparserfromhell", |
|
|
|
packages = find_packages(exclude=("tests",)), |
|
|
|
ext_modules = [tokenizer], |
|
|
|