Skip to content

Commit

Permalink
Enable building as bytes or unicode
Browse files Browse the repository at this point in the history
The environment variables AHOCORASICK_UNICODE and AHOCORASICK_BYTES now
drive the flavor of the build if defined (using any value).

Reference: #65
Reference: #165
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
  • Loading branch information
pombredanne committed Mar 8, 2022
1 parent 51d1e54 commit f6a5d20
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,52 @@
License : BSD-3-Clause (see LICENSE)
"""

import os

from setuptools import setup
from setuptools import Extension

# check for the mere of environment variables
try:
build_as_unicode = os.environ['AHOCORASICK_UNICODE']
build_as_unicode = True
except KeyError:
build_as_unicode = False

try:
build_as_bytes = os.environ['AHOCORASICK_BYTES']
build_as_bytes = True
except KeyError:
build_as_bytes = False

if build_as_unicode and build_as_bytes:
raise Exception(
'Cannot build pyahocorasick both as bytes and unicode: '
'only one of AHOCORASICK_UNICODE and AHOCORASICK_BYTES environment variable should be set.'
)

if not build_as_unicode and not build_as_bytes:
# we default to unicode
build_as_unicode = True

if build_as_unicode:
macros = [('AHOCORASICK_UNICODE', '')]
else:
macros = []


def get_long_description():
import io
with io.open('README.rst', encoding='UTF-8') as f:
return f.read()


module = Extension(
'ahocorasick',
sources=[
'src/pyahocorasick.c',
],
define_macros= [
# when defined unicode strings are supported
('AHOCORASICK_UNICODE', ''),
],
define_macros=macros,
depends=[
'src/common.h',
'src/Automaton.c',
Expand Down Expand Up @@ -65,7 +93,6 @@ def get_long_description():
],
)


setup(
name='pyahocorasick',
version='2.0.0b1',
Expand Down Expand Up @@ -104,7 +131,7 @@ def get_long_description():
'Topic :: Text Editors :: Text Processing',
],
extras_require={
"testing": ["pytest", "twine", "setuptools", "wheel",],
"testing": ["pytest", "twine", "setuptools", "wheel", ],
},
python_requires=">=3.6",
)

0 comments on commit f6a5d20

Please sign in to comment.