Skip to content

Commit f7faff8

Browse files
authored
PYTHON-4489 Make setup.py private (mongodb#1667)
1 parent ca543d4 commit f7faff8

File tree

4 files changed

+154
-141
lines changed

4 files changed

+154
-141
lines changed

_setup.py

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import sys
5+
import warnings
6+
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

doc/changelog.rst

+8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ Changelog
33

44
Changes in Version 4.8.0
55
-------------------------
6+
67
.. warning:: PyMongo 4.8 drops support for Python 3.7 and PyPy 3.8: Python 3.8+ or PyPy 3.9+ is now required.
78

89
PyMongo 4.8 brings a number of improvements including:
10+
911
- The handshake metadata for "os.name" on Windows has been simplified to "Windows" to improve import time.
1012
- The repr of ``bson.binary.Binary`` is now redacted when the subtype is SENSITIVE_SUBTYPE(8).
1113
- A new asynchronous API with full asyncio support.
1214

15+
Unavoidable breaking changes
16+
............................
17+
18+
- Since we are now using ``hatch`` as our build backend, we no longer have a ``setup.py`` file
19+
and require installation using ``pip``.
20+
1321
Changes in Version 4.7.3
1422
-------------------------
1523

hatch_build.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def initialize(self, version, build_data):
1919
here = Path(__file__).parent.resolve()
2020
sys.path.insert(0, str(here))
2121

22-
subprocess.check_call([sys.executable, "setup.py", "build_ext", "-i"])
22+
subprocess.check_call([sys.executable, "_setup.py", "build_ext", "-i"])
2323

2424
# Ensure wheel is marked as binary and contains the binary files.
2525
build_data["infer_tag"] = True

setup.py

+2-140
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,5 @@
11
from __future__ import annotations
22

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"
64

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

Comments
 (0)