-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PYTHON-4451 Use Hatch as Build Backend #1644
Changes from 20 commits
0b0d31c
496faf8
ac18c7f
4361f54
9310777
db46308
f79414c
ca6850b
5e35224
dd4d1fd
fd6d343
ed9ad5e
6c1f2e6
2971ce9
0a2fa64
17503f0
a57e6e1
0ead71e
28494f4
c45e030
589d89d
799830e
8571970
3cc40a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""A custom hatch build hook for pymongo.""" | ||
from __future__ import annotations | ||
|
||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
from hatchling.builders.hooks.plugin.interface import BuildHookInterface | ||
|
||
|
||
class CustomHook(BuildHookInterface): | ||
"""The pymongo build hook.""" | ||
|
||
def initialize(self, version, build_data): | ||
"""Initialize the hook.""" | ||
if self.target_name == "sdist": | ||
return | ||
here = Path(__file__).parent.resolve() | ||
sys.path.insert(0, str(here)) | ||
|
||
subprocess.check_call([sys.executable, "setup.py", "build_ext", "-i"]) | ||
|
||
# Ensure wheel is marked as binary and contains the binary files. | ||
build_data["infer_tag"] = True | ||
build_data["pure_python"] = False | ||
if os.name == "nt": | ||
patt = ".pyd" | ||
else: | ||
patt = ".so" | ||
for pkg in ["bson", "pymongo"]: | ||
dpath = here / pkg | ||
for fpath in dpath.glob(f"*{patt}"): | ||
relpath = os.path.relpath(fpath, here) | ||
build_data["artifacts"].append(relpath) | ||
build_data["force_include"][relpath] = relpath |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +15,22 @@ | |
"""Current version of PyMongo.""" | ||
from __future__ import annotations | ||
|
||
from typing import Tuple, Union | ||
import re | ||
from typing import List, Tuple, Union | ||
|
||
version_tuple: Tuple[Union[int, str], ...] = (4, 8, 0, ".dev0") | ||
__version__ = "4.8.0.dev1" | ||
|
||
|
||
def get_version_string() -> str: | ||
if isinstance(version_tuple[-1], str): | ||
return ".".join(map(str, version_tuple[:-1])) + version_tuple[-1] | ||
return ".".join(map(str, version_tuple)) | ||
pattern = r"(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(?P<rest>.*)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this a function and add a few unit tests to make sure it works with a variety of versions? Eg "4.8.0.dev1", "4.8.0", "5.0", etc... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. We don't support "5.0", it has to have the patch version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think not supporting "5.0" is a mistake. Our 4.0 release used "4.0" for example, same for "3.0". If we don't support "5.0" then I worry we'll accidentally set the version to a 2 part at some point and lead to a bug where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
match = re.match(pattern, __version__) | ||
if match: | ||
parts: List[Union[int, str]] = [int(match[part]) for part in ["major", "minor", "patch"]] | ||
if match["rest"]: | ||
parts.append(match["rest"]) | ||
else: | ||
parts = [] | ||
version_tuple: Tuple[Union[int, str], ...] = tuple(parts) | ||
version = __version__ | ||
|
||
|
||
__version__: str = get_version_string() | ||
version = __version__ | ||
def get_version_string() -> str: | ||
return __version__ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,32 +136,8 @@ def build_extension(self, ext): | |
) | ||
ext_modules = [] | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You were able to get rid of all this because of the way that requirements.txt is handled? That's awesome! |
||
def parse_reqs_file(fname): | ||
with open(fname) as fid: | ||
lines = [li.strip() for li in fid.readlines()] | ||
return [li for li in lines if li and not li.startswith("#")] | ||
|
||
|
||
dependencies = parse_reqs_file("requirements.txt") | ||
|
||
extras_require = dict( | ||
aws=parse_reqs_file("requirements/aws.txt"), | ||
encryption=parse_reqs_file("requirements/encryption.txt"), | ||
gssapi=parse_reqs_file("requirements/gssapi.txt"), | ||
ocsp=parse_reqs_file("requirements/ocsp.txt"), | ||
snappy=parse_reqs_file("requirements/snappy.txt"), | ||
# PYTHON-3423 Removed in 4.3 but kept here to avoid pip warnings. | ||
srv=[], | ||
tls=[], | ||
# PYTHON-2133 Removed in 4.0 but kept here to avoid pip warnings. | ||
zstd=parse_reqs_file("requirements/zstd.txt"), | ||
test=parse_reqs_file("requirements/test.txt"), | ||
) | ||
|
||
setup( | ||
cmdclass={"build_ext": custom_build_ext}, | ||
install_requires=dependencies, | ||
extras_require=extras_require, | ||
ext_modules=ext_modules, | ||
packages=["bson", "pymongo", "gridfs"], | ||
) # type:ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No manifest file!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I read the Why Hatch? page. I'm starting to get it. Very nice.