|
| 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 | + ] |
0 commit comments