| 1 |
#!/usr/bin/env python |
| 2 |
# BSD 2-Clause License |
| 3 |
# |
| 4 |
# Apprise - Push Notification Library. |
| 5 |
# Copyright (c) 2026, Chris Caron <[email protected]> |
| 6 |
# |
| 7 |
# Redistribution and use in source and binary forms, with or without |
| 8 |
# modification, are permitted provided that the following conditions are met: |
| 9 |
# |
| 10 |
# 1. Redistributions of source code must retain the above copyright notice, |
| 11 |
# this list of conditions and the following disclaimer. |
| 12 |
# |
| 13 |
# 2. Redistributions in binary form must reproduce the above copyright notice, |
| 14 |
# this list of conditions and the following disclaimer in the documentation |
| 15 |
# and/or other materials provided with the distribution. |
| 16 |
# |
| 17 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 |
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 |
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 21 |
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 |
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 |
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 |
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 |
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 |
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 |
# POSSIBILITY OF SUCH DAMAGE. |
| 28 |
|
| 29 |
# |
| 30 |
# 2025.07.10 NOTE: |
| 31 |
# setup.py (Temporary shim for RHEL9 Package Building Only) |
| 32 |
# Refer to tox for everything else; this will be removed once RHEL9 support |
| 33 |
# is dropped. |
| 34 |
# |
| 35 |
import glob |
| 36 |
import os |
| 37 |
import re |
| 38 |
|
| 39 |
from setuptools import find_packages, setup |
| 40 |
from setuptools.command.build_py import build_py |
| 41 |
|
| 42 |
|
| 43 |
class BuildPyWithTranslations(build_py): |
| 44 |
"""Compile the translation catalogs before building the package. |
| 45 |
|
| 46 |
The ``.mo`` files are not kept in git, so without this a build from a |
| 47 |
git checkout ships no translations. |
| 48 |
""" |
| 49 |
|
| 50 |
def run(self) -> None: |
| 51 |
# Babel is already a build requirement (see pyproject.toml) |
| 52 |
from babel.messages.mofile import write_mo |
| 53 |
from babel.messages.pofile import read_po |
| 54 |
|
| 55 |
# Compile each language's catalog next to its source |
| 56 |
pattern = os.path.join("apprise", "i18n", "*", "LC_MESSAGES", "*.po") |
| 57 |
for po_path in glob.glob(pattern): |
| 58 |
# Read our human-editable catalog |
| 59 |
with open(po_path, "rb") as po_file: |
| 60 |
catalog = read_po(po_file) |
| 61 |
|
| 62 |
# Write the compiled copy that gettext actually reads |
| 63 |
with open(po_path[:-3] + ".mo", "wb") as mo_file: |
| 64 |
write_mo(mo_file, catalog) |
| 65 |
|
| 66 |
# Now build as normal; package_data picks up the .mo files |
| 67 |
super().run() |
| 68 |
|
| 69 |
|
| 70 |
def read_version() -> str: |
| 71 |
with open(os.path.join("apprise", "__init__.py"), encoding="utf-8") as f: |
| 72 |
for line in f: |
| 73 |
m = re.match(r'^__version__\s*=\s*[\'"]([^\'"]+)', line) |
| 74 |
if m: |
| 75 |
return m.group(1) |
| 76 |
raise RuntimeError("Version not found") |
| 77 |
|
| 78 |
|
| 79 |
# tox is not supported well in RHEL9 so this stub file is the only way to |
| 80 |
# successfully build the RPM; packaging/redhat/python-apprise.spec has |
| 81 |
# been updated accordingly to accommodate reference to this for older |
| 82 |
# versions of the distribution only |
| 83 |
setup( |
| 84 |
name="apprise", |
| 85 |
cmdclass={"build_py": BuildPyWithTranslations}, |
| 86 |
version=read_version(), |
| 87 |
packages=find_packages(exclude=["tests*", "packaging*"]), |
| 88 |
entry_points={ |
| 89 |
"console_scripts": [ |
| 90 |
"apprise = apprise.cli:main", |
| 91 |
], |
| 92 |
}, |
| 93 |
package_data={ |
| 94 |
"apprise": [ |
| 95 |
"assets/NotifyXML-*.xsd", |
| 96 |
"assets/themes/default/*.png", |
| 97 |
"assets/themes/default/*.ico", |
| 98 |
"i18n/*.py", |
| 99 |
"i18n/*/LC_MESSAGES/*.mo", |
| 100 |
"py.typed", |
| 101 |
"*.pyi", |
| 102 |
"*/*.pyi", |
| 103 |
], |
| 104 |
}, |
| 105 |
) |