Skip to content

Commit 68698c8

Browse files
committed
Switch to PEP517 build with Hatch
1 parent fb1c19c commit 68698c8

File tree

9 files changed

+156
-137
lines changed

9 files changed

+156
-137
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
python-version: ${{ matrix.python-version }}
5252
allow-prereleases: true
5353
cache: "pip"
54-
cache-dependency-path: "**/setup.py"
54+
cache-dependency-path: "**/pyproject.toml"
5555
- name: Install dependencies
5656
run: |
5757
python -m pip install --upgrade pip setuptools wheel
@@ -76,7 +76,7 @@ jobs:
7676
with:
7777
python-version: "3.13"
7878
cache: "pip"
79-
cache-dependency-path: "**/setup.py"
79+
cache-dependency-path: "**/pyproject.toml"
8080
- run: pip install build -e .
8181
- run: make import-cldr
8282
- run: python -m build

MANIFEST.in

Lines changed: 0 additions & 11 deletions
This file was deleted.

babel/core.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@
5656

5757

5858
def _raise_no_data_error():
59-
raise RuntimeError('The babel data files are not available. '
60-
'This usually happens because you are using '
61-
'a source checkout from Babel and you did '
62-
'not build the data files. Just make sure '
63-
'to run "python setup.py import_cldr" before '
64-
'installing the library.')
59+
raise RuntimeError(
60+
'The babel data files are not available. '
61+
'This usually happens because you are using '
62+
'a source checkout from Babel and you did '
63+
'not build the data files. Please see the '
64+
'README.rst file for more information.',
65+
)
6566

6667

6768
def get_global(key: _GLOBAL_KEY) -> Mapping[str, Any]:

conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
collect_ignore = [
66
'babel/messages/setuptools_frontend.py',
7-
'setup.py',
87
'tests/messages/data',
98
]
109
babel_path = Path(__file__).parent / 'babel'

docs/installation.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ Get the git checkout in a new virtualenv and run in development mode::
8383
New python executable in venv/bin/python
8484
Installing distribute............done.
8585
$ . venv/bin/activate
86-
$ python setup.py import_cldr
86+
$ make import-cldr
8787
$ pip install --editable .
8888
...
8989
Finished processing dependencies for Babel
9090

91-
Make sure to not forget about the ``import_cldr`` step because otherwise
91+
Make sure to not forget about the CLDR import step because otherwise
9292
you will be missing the locale data.
9393
The custom setup command will download the most appropriate CLDR release from the
9494
official website and convert it for Babel.
9595

9696
This will pull also in the dependencies and activate the git head as the
9797
current version inside the virtualenv. Then all you have to do is run
9898
``git pull origin`` to update to the latest version. If the CLDR data
99-
changes you will have to re-run ``python setup.py import_cldr``.
99+
changes you will have to re-run ``make import-cldr``.

hatch_build.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import tarfile
3+
import zipfile
4+
5+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
6+
7+
DAT_MESSAGE = """
8+
======
9+
Package should contain multiple .dat files.
10+
* Make sure you've imported the CLDR data; `make import-cldr`.
11+
------
12+
To skip this check, set the environment variable BABEL_NO_CHECK_BUILD=1
13+
======
14+
""".strip()
15+
16+
17+
def check_babel_artifact(artifact_path: str):
18+
if artifact_path.endswith(".whl"):
19+
with zipfile.ZipFile(artifact_path) as whl:
20+
filelist = whl.namelist()
21+
elif artifact_path.endswith(".tar.gz"):
22+
with tarfile.open(artifact_path) as tar:
23+
filelist = tar.getnames()
24+
if len([f.endswith(".dat") for f in filelist]) < 10:
25+
raise ValueError(DAT_MESSAGE)
26+
27+
28+
class CustomBuildHook(BuildHookInterface):
29+
def finalize(self, version, build_data, artifact_path):
30+
if not os.environ.get("BABEL_NO_CHECK_BUILD"):
31+
check_babel_artifact(artifact_path)

pyproject.toml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,116 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "babel"
7+
dynamic = ["version"]
8+
description = "Internationalization utilities"
9+
readme = "README.rst"
10+
license = "BSD-3-Clause"
11+
license-files = ["LICENSE"]
12+
requires-python = ">=3.8"
13+
authors = [
14+
{ name = "Armin Ronacher", email = "[email protected]" },
15+
]
16+
maintainers = [
17+
{ name = "Aarni Koskela", email = "[email protected]" },
18+
]
19+
classifiers = [
20+
"Development Status :: 5 - Production/Stable",
21+
"Environment :: Web Environment",
22+
"Intended Audience :: Developers",
23+
"License :: OSI Approved :: BSD License",
24+
"Operating System :: OS Independent",
25+
"Programming Language :: Python :: 3 :: Only",
26+
"Programming Language :: Python :: 3",
27+
"Programming Language :: Python :: 3.8",
28+
"Programming Language :: Python :: 3.9",
29+
"Programming Language :: Python :: 3.10",
30+
"Programming Language :: Python :: 3.11",
31+
"Programming Language :: Python :: 3.12",
32+
"Programming Language :: Python :: 3.13",
33+
"Programming Language :: Python :: Implementation :: CPython",
34+
"Programming Language :: Python :: Implementation :: PyPy",
35+
"Programming Language :: Python",
36+
"Topic :: Software Development :: Internationalization",
37+
"Topic :: Software Development :: Libraries :: Python Modules",
38+
]
39+
40+
dependencies = [
41+
# This version identifier is currently necessary as
42+
# pytz otherwise does not install on pip 1.4 or higher.
43+
# Python 3.9 and later include zoneinfo which replaces pytz.
44+
'pytz>=2015.7; python_version<"3.9"',
45+
]
46+
47+
48+
[dependency-groups]
49+
dev = [
50+
"backports.zoneinfo; python_version<\"3.9\"",
51+
"freezegun~=1.0",
52+
"jinja2>=3.0",
53+
"pytest-cov",
54+
"pytest>=6.0",
55+
"pytz",
56+
"setuptools",
57+
"tzdata;sys_platform == 'win32'",
58+
]
59+
60+
[project.urls]
61+
Homepage = "https://babel.pocoo.org/"
62+
Source = "https://github.com/python-babel/babel"
63+
64+
[tool.hatch.version]
65+
path = "babel/__init__.py"
66+
67+
[tool.hatch.build.hooks.custom]
68+
69+
[tool.hatch.build.targets.sdist]
70+
include = [
71+
"/Makefile",
72+
"/babel",
73+
"/docs",
74+
"/scripts",
75+
"/tests",
76+
"AUTHORS",
77+
"CHANGES.rst",
78+
"conftest.py",
79+
"tox.ini",
80+
]
81+
82+
[tool.hatch.build.targets.wheel]
83+
include = [
84+
"/babel",
85+
]
86+
artifacts = [
87+
"**.dat",
88+
]
89+
exclude = [
90+
"/babel/locale-data/.gitignore",
91+
]
92+
93+
[project.scripts]
94+
pybabel = "babel.messages.frontend:main"
95+
96+
[project.entry-points."distutils.commands"]
97+
compile_catalog = "babel.messages.setuptools_frontend:compile_catalog"
98+
extract_messages = "babel.messages.setuptools_frontend:extract_messages"
99+
init_catalog = "babel.messages.setuptools_frontend:init_catalog"
100+
update_catalog = "babel.messages.setuptools_frontend:update_catalog"
101+
102+
[project.entry-points."distutils.setup_keywords"]
103+
message_extractors = "babel.messages.setuptools_frontend:check_message_extractors"
104+
105+
[project.entry-points."babel.checkers"]
106+
num_plurals = "babel.messages.checkers:num_plurals"
107+
python_format = "babel.messages.checkers:python_format"
108+
109+
[project.entry-points."babel.extractors"]
110+
ignore = "babel.messages.extract:extract_nothing"
111+
python = "babel.messages.extract:extract_python"
112+
javascript = "babel.messages.extract:extract_javascript"
113+
1114
[tool.ruff]
2115
target-version = "py38"
3116
extend-exclude = [

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)