1
|
#!/usr/bin/env python3
|
2
|
# SPDX-License-Identifier: CC0-1.0
|
3
|
|
4
|
# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
|
5
|
#
|
6
|
# Available under the terms of Creative Commons Zero v1.0 Universal.
|
7
|
|
8
|
import setuptools
|
9
|
|
10
|
from setuptools.command.build_py import build_py
|
11
|
from setuptools.command.sdist import sdist
|
12
|
|
13
|
from pathlib import Path
|
14
|
|
15
|
here = Path(__file__).resolve().parent
|
16
|
|
17
|
class CustomBuildCommand(build_py):
|
18
|
"""The build command but runs babel before build."""
|
19
|
def run(self, *args, **kwargs):
|
20
|
"""Wrapper around build_py's original run() method."""
|
21
|
self.run_command('compile_catalog')
|
22
|
|
23
|
super().run(*args, **kwargs)
|
24
|
|
25
|
class CustomSdistCommand(sdist):
|
26
|
"""
|
27
|
The sdist command but prevents compiled message catalogs from being included
|
28
|
in the archive.
|
29
|
"""
|
30
|
def run(self, *args, **kwargs):
|
31
|
"""Wrapper around sdist's original run() method."""
|
32
|
locales_dir = here / 'src/hydrilla/builder/locales'
|
33
|
locale_files = {}
|
34
|
|
35
|
for path in locales_dir.rglob('*.mo'):
|
36
|
locale_files[path] = path.read_bytes()
|
37
|
|
38
|
for path in locale_files:
|
39
|
path.unlink()
|
40
|
|
41
|
super().run(*args, **kwargs)
|
42
|
|
43
|
for path, contents in locale_files.items():
|
44
|
path.write_bytes(contents)
|
45
|
|
46
|
setuptools.setup(cmdclass = {
|
47
|
'build_py': CustomBuildCommand,
|
48
|
'sdist': CustomSdistCommand
|
49
|
})
|