|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -import os |
4 |
| -import sys |
5 |
| -import warnings |
| 3 | +msg = "PyMongo>=4.8 no longer supports building via setup.py, use python -m pip install <path/to/pymongo> instead" |
6 | 4 |
|
7 |
| -# Hack to silence atexit traceback in some Python versions |
8 |
| -try: |
9 |
| - import multiprocessing # noqa: F401 |
10 |
| -except ImportError: |
11 |
| - pass |
12 |
| - |
13 |
| -from setuptools import setup |
14 |
| -from setuptools.command.build_ext import build_ext |
15 |
| -from setuptools.extension import Extension |
16 |
| - |
17 |
| - |
18 |
| -class custom_build_ext(build_ext): |
19 |
| - """Allow C extension building to fail. |
20 |
| -
|
21 |
| - The C extension speeds up BSON encoding, but is not essential. |
22 |
| - """ |
23 |
| - |
24 |
| - warning_message = """ |
25 |
| -******************************************************************** |
26 |
| -WARNING: %s could not |
27 |
| -be compiled. No C extensions are essential for PyMongo to run, |
28 |
| -although they do result in significant speed improvements. |
29 |
| -%s |
30 |
| -
|
31 |
| -Please see the installation docs for solutions to build issues: |
32 |
| -
|
33 |
| -https://pymongo.readthedocs.io/en/stable/installation.html |
34 |
| -
|
35 |
| -Here are some hints for popular operating systems: |
36 |
| -
|
37 |
| -If you are seeing this message on Linux you probably need to |
38 |
| -install GCC and/or the Python development package for your |
39 |
| -version of Python. |
40 |
| -
|
41 |
| -Debian and Ubuntu users should issue the following command: |
42 |
| -
|
43 |
| - $ sudo apt-get install build-essential python-dev |
44 |
| -
|
45 |
| -Users of Red Hat based distributions (RHEL, CentOS, Amazon Linux, |
46 |
| -Oracle Linux, Fedora, etc.) should issue the following command: |
47 |
| -
|
48 |
| - $ sudo yum install gcc python-devel |
49 |
| -
|
50 |
| -If you are seeing this message on Microsoft Windows please install |
51 |
| -PyMongo using pip. Modern versions of pip will install PyMongo |
52 |
| -from binary wheels available on pypi. If you must install from |
53 |
| -source read the documentation here: |
54 |
| -
|
55 |
| -https://pymongo.readthedocs.io/en/stable/installation.html#installing-from-source-on-windows |
56 |
| -
|
57 |
| -If you are seeing this message on macOS / OSX please install PyMongo |
58 |
| -using pip. Modern versions of pip will install PyMongo from binary |
59 |
| -wheels available on pypi. If wheels are not available for your version |
60 |
| -of macOS / OSX, or you must install from source read the documentation |
61 |
| -here: |
62 |
| -
|
63 |
| -https://pymongo.readthedocs.io/en/stable/installation.html#osx |
64 |
| -******************************************************************** |
65 |
| -""" |
66 |
| - |
67 |
| - def run(self): |
68 |
| - try: |
69 |
| - build_ext.run(self) |
70 |
| - except Exception: |
71 |
| - if os.environ.get("PYMONGO_C_EXT_MUST_BUILD"): |
72 |
| - raise |
73 |
| - e = sys.exc_info()[1] |
74 |
| - sys.stdout.write("%s\n" % str(e)) |
75 |
| - warnings.warn( |
76 |
| - self.warning_message |
77 |
| - % ( |
78 |
| - "Extension modules", |
79 |
| - "There was an issue with your platform configuration - see above.", |
80 |
| - ), |
81 |
| - stacklevel=2, |
82 |
| - ) |
83 |
| - |
84 |
| - def build_extension(self, ext): |
85 |
| - name = ext.name |
86 |
| - try: |
87 |
| - build_ext.build_extension(self, ext) |
88 |
| - except Exception: |
89 |
| - if os.environ.get("PYMONGO_C_EXT_MUST_BUILD"): |
90 |
| - raise |
91 |
| - e = sys.exc_info()[1] |
92 |
| - sys.stdout.write("%s\n" % str(e)) |
93 |
| - warnings.warn( |
94 |
| - self.warning_message |
95 |
| - % ( |
96 |
| - "The %s extension module" % (name,), # noqa: UP031 |
97 |
| - "The output above this warning shows how the compilation failed.", |
98 |
| - ), |
99 |
| - stacklevel=2, |
100 |
| - ) |
101 |
| - |
102 |
| - |
103 |
| -ext_modules = [ |
104 |
| - Extension( |
105 |
| - "bson._cbson", |
106 |
| - include_dirs=["bson"], |
107 |
| - sources=["bson/_cbsonmodule.c", "bson/time64.c", "bson/buffer.c"], |
108 |
| - ), |
109 |
| - Extension( |
110 |
| - "pymongo._cmessage", |
111 |
| - include_dirs=["bson"], |
112 |
| - sources=[ |
113 |
| - "pymongo/_cmessagemodule.c", |
114 |
| - "bson/_cbsonmodule.c", |
115 |
| - "bson/time64.c", |
116 |
| - "bson/buffer.c", |
117 |
| - ], |
118 |
| - ), |
119 |
| -] |
120 |
| - |
121 |
| - |
122 |
| -if "--no_ext" in sys.argv or os.environ.get("NO_EXT"): |
123 |
| - try: |
124 |
| - sys.argv.remove("--no_ext") |
125 |
| - except ValueError: |
126 |
| - pass |
127 |
| - ext_modules = [] |
128 |
| -elif sys.platform.startswith("java") or sys.platform == "cli" or "PyPy" in sys.version: |
129 |
| - sys.stdout.write( |
130 |
| - """ |
131 |
| -*****************************************************\n |
132 |
| -The optional C extensions are currently not supported\n |
133 |
| -by this python implementation.\n |
134 |
| -*****************************************************\n |
135 |
| -""" |
136 |
| - ) |
137 |
| - ext_modules = [] |
138 |
| - |
139 |
| -setup( |
140 |
| - cmdclass={"build_ext": custom_build_ext}, |
141 |
| - ext_modules=ext_modules, |
142 |
| - packages=["bson", "pymongo", "gridfs"], |
143 |
| -) # type:ignore |
| 5 | +raise RuntimeError(msg) |
0 commit comments