summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2023-01-26 07:18:50 -0800
committerDavid Lord <davidism@gmail.com>2023-01-26 07:18:50 -0800
commit45dbe44a36a2abe1b0b62b8ff9e32653fe91fb83 (patch)
tree8469681beac3314ed3d660fdb6e3dd9f5a1ced95 /setup.py
parent00fea0a771ed63169933684283862e50ff3497aa (diff)
downloadmarkupsafe-rust.tar.gz
initial rust implementationrust
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py91
1 files changed, 17 insertions, 74 deletions
diff --git a/setup.py b/setup.py
index 7208cdd..e0ebfed 100644
--- a/setup.py
+++ b/setup.py
@@ -1,84 +1,27 @@
import os
import platform
-import sys
-from distutils.errors import CCompilerError
-from distutils.errors import DistutilsExecError
-from distutils.errors import DistutilsPlatformError
from setuptools import Extension
from setuptools import setup
-from setuptools.command.build_ext import build_ext
+from setuptools_rust import RustExtension
-ext_modules = [Extension("markupsafe._speedups", ["src/markupsafe/_speedups.c"])]
-
-
-class BuildFailed(Exception):
- pass
-
-
-class ve_build_ext(build_ext):
- """This class allows C extension building to fail."""
-
- def run(self):
- try:
- build_ext.run(self)
- except DistutilsPlatformError as e:
- raise BuildFailed() from e
-
- def build_extension(self, ext):
- try:
- build_ext.build_extension(self, ext)
- except (CCompilerError, DistutilsExecError, DistutilsPlatformError) as e:
- raise BuildFailed() from e
- except ValueError as e:
- # this can happen on Windows 64 bit, see Python issue 7511
- if "'path'" in str(sys.exc_info()[1]): # works with Python 2 and 3
- raise BuildFailed() from e
- raise
-
-
-def run_setup(with_binary):
- setup(
- cmdclass={"build_ext": ve_build_ext},
- ext_modules=ext_modules if with_binary else [],
- )
-
-
-def show_message(*lines):
- print("=" * 74)
- for line in lines:
- print(line)
- print("=" * 74)
-
-
-supports_speedups = platform.python_implementation() not in {
+if platform.python_implementation() not in {
"PyPy",
"Jython",
"GraalVM",
-}
-
-if os.environ.get("CIBUILDWHEEL", "0") == "1" and supports_speedups:
- run_setup(True)
-elif supports_speedups:
- try:
- run_setup(True)
- except BuildFailed:
- show_message(
- "WARNING: The C extension could not be compiled, speedups"
- " are not enabled.",
- "Failure information, if any, is above.",
- "Retrying the build without the C extension now.",
- )
- run_setup(False)
- show_message(
- "WARNING: The C extension could not be compiled, speedups"
- " are not enabled.",
- "Plain-Python build succeeded.",
- )
-else:
- run_setup(False)
- show_message(
- "WARNING: C extensions are not supported on this Python"
- " platform, speedups are not enabled.",
- "Plain-Python build succeeded.",
+}:
+ local = os.environ.get("CIBUIDWHEEL", "0") != "1"
+ setup(
+ ext_modules=[
+ Extension(
+ "markupsafe._speedups", ["src/markupsafe/_speedups.c"], optional=local
+ )
+ ],
+ rust_extensions=[
+ RustExtension(
+ "markupsafe._rust_speedups", "src/rust/Cargo.toml", optional=local
+ )
+ ],
)
+else:
+ setup()