Skip to content

Commit 8ad7613

Browse files
committed
Use hatch as backend build system
1 parent 129ac8c commit 8ad7613

File tree

6 files changed

+159
-161
lines changed

6 files changed

+159
-161
lines changed

.gitignore

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ sdist
1818
develop-eggs
1919
.installed.cfg
2020
lib64
21-
.eggs/*
21+
.eggs/
2222

2323
# Installer logs
2424
pip-log.txt
@@ -40,21 +40,21 @@ nosetests.xml
4040
*.DS_Store
4141

4242
# Mkdocs
43-
site/*
43+
site/
4444

4545
# Pytest
46-
.pytest_cache/*
46+
.pytest_cache/
4747

4848
# Miscellaneous
4949
.cache
50-
.idea/*
50+
.idea/
5151
*.log
5252
*.bak
5353
*.patch
54-
rummage/lib/gui/data/docs/_snippets/*
54+
rummage/lib/gui/data/docs/_snippets/
5555
rummage/lib/gui/data/docs/sitemap.xml
5656
rummage/lib/gui/data/docs/sitemap.xml.gz
5757
docs/src/dictionary/hunspell/
5858

5959
# Virtual environments
60-
venv/*
60+
venv/

MANIFEST.in

-17
This file was deleted.

hatch_build.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""Dynamically define some metadata."""
2+
import os
3+
import sys
4+
from hatchling.metadata.plugin.interface import MetadataHookInterface
5+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
6+
7+
8+
def get_version_dev_status(root):
9+
"""Get version_info without importing the entire module."""
10+
11+
import importlib.util
12+
13+
path = os.path.join(root, 'rummage', 'lib', '__meta__.py')
14+
spec = importlib.util.spec_from_file_location("__meta__", path)
15+
module = importlib.util.module_from_spec(spec)
16+
spec.loader.exec_module(module)
17+
return module.__version_info__._get_dev_status()
18+
19+
20+
def get_requirements(root, requirements):
21+
"""Load list of dependencies."""
22+
23+
install_requires = []
24+
with open(os.path.join(root, requirements)) as f:
25+
for line in f:
26+
if not line.startswith("#"):
27+
install_requires.append(line.strip())
28+
return install_requires
29+
30+
31+
class CustomBuildHook(BuildHookInterface):
32+
def initialize(self, version, build_data):
33+
if self.target_name != 'wheel':
34+
return
35+
36+
# Lazily import in case hook is disabled but file is still loaded
37+
from babel.messages.frontend import compile_catalog
38+
39+
compiled_catalog = compile_catalog()
40+
compiled_catalog.directory = os.path.join(self.root, 'rummage', 'lib', 'gui', 'localization', 'locale')
41+
42+
compiled_catalog.finalize_options()
43+
compiled_catalog.run()
44+
45+
46+
class CustomMetadataHook(MetadataHookInterface):
47+
"""Our metadata hook."""
48+
49+
def update(self, metadata):
50+
"""See https://ofek.dev/hatch/latest/plugins/metadata-hook/ for more information."""
51+
52+
metadata['gui_scripts'] = {
53+
'rummage': 'rummage.__main__:main',
54+
f'rummage{".".join(sys.version_info[:2])}': 'rummage.__main__:main'
55+
}
56+
metadata["dependencies"] = get_requirements(self.root, "requirements/project.txt")
57+
metadata['optional-dependencies'] = get_requirements(self.root, "requirements/extras.txt")
58+
metadata["classifiers"] = [
59+
f"Development Status :: {get_version_dev_status(self.root)}",
60+
"Environment :: Console",
61+
"Intended Audience :: Developers",
62+
"License :: OSI Approved :: MIT License",
63+
"Operating System :: OS Independent",
64+
"Programming Language :: Python :: 3",
65+
"Programming Language :: Python :: 3.7",
66+
"Programming Language :: Python :: 3.8",
67+
"Programming Language :: Python :: 3.9",
68+
"Programming Language :: Python :: 3.10",
69+
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
70+
"Topic :: Software Development :: Libraries :: Python Modules",
71+
"Topic :: Text Processing :: Filters",
72+
"Topic :: Text Processing :: Markup :: HTML",
73+
]

pyproject.toml

+80-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,84 @@
11
[build-system]
22
requires = [
3-
"setuptools>=42",
4-
"wheel"
3+
"hatchling>=0.21.0",
54
]
5+
build-backend = "hatchling.build"
66

7-
build-backend = "setuptools.build_meta"
7+
[project]
8+
name = "rummage"
9+
description = "A GUI search and replace app."
10+
readme = "README.md"
11+
license = "MIT"
12+
requires-python = ">=3.7"
13+
authors = [
14+
{ name = "Isaac Muse", email = "Isaac.Muse@gmail.com" },
15+
]
16+
keywords = [
17+
"grep",
18+
"search",
19+
"find",
20+
"replace",
21+
"gui"
22+
]
23+
dynamic = [
24+
"classifiers",
25+
"dependencies",
26+
"version",
27+
"entry_points"
28+
]
29+
zip_safe = false
30+
include_package_data = true
31+
32+
[project.urls]
33+
Homepage = "https://github.com/facelessuser/Rummage"
34+
35+
[tool.hatch.build.targets.wheel.hooks.custom]
36+
dependencies = [
37+
"babel",
38+
]
39+
40+
[tool.hatch.version]
41+
source = "code"
42+
path = "rummage/lib/__meta__.py"
43+
44+
[tool.hatch.build.targets.sdist]
45+
include = [
46+
"/rummage/*.py",
47+
"/rummage/lib/gui/data/*.md",
48+
"/rummage/lib/gui/data/*.png",
49+
"/rummage/lib/gui/data/*.gif",
50+
"/rummage/lib/gui/data/*.js",
51+
"/rummage/lib/gui/data/*.css",
52+
"/rummage/lib/gui/data/*.html",
53+
"/rummage/lib/gui/data/*.svg",
54+
"/tests/*.txt",
55+
"/tests/*.py",
56+
"/tests/*.hidden_file",
57+
"/tests/*.rum-bak",
58+
"/tools/*.py",
59+
"/rummage/lib/gui/localization/locale/*.po",
60+
"/docs/src/markdown/*.md",
61+
"/docs/src/markdown/*.png",
62+
"/docs/src/markdown/*.svg",
63+
"/docs/src/markdown/*.gif",
64+
"/docs/src/markdown/*.icns",
65+
"/docs/src/markdown/*.ico",
66+
"/docs/src/markdown/*.js",
67+
"/docs/src/markdown/*.css",
68+
"/docs/src/markdown/*.html",
69+
"/docs/src/markdown/*.svg",
70+
"/docs/theme/*.js",
71+
"/docs/theme/*.html",
72+
"/docs/theme/*.css",
73+
"/tox.ini",
74+
"/gui.fbp",
75+
"/mkdocs.yml",
76+
"/mkdocs-internal.yml",
77+
"/.coveragerc",
78+
"/LICENSE.md"
79+
]
80+
81+
[tool.hatch.build.targets.wheel]
82+
include = [
83+
"/rummage",
84+
]

setup.cfg

-20
This file was deleted.

setup.py

-115
This file was deleted.

0 commit comments

Comments
 (0)