Project

General

Profile

Download (1.33 KB) Statistics
| Branch: | Tag: | Revision:

hydrilla-builder / setup.py @ debian-debian

1 6bc04f80 Wojtek Kosior
#!/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 22c722bf Wojtek Kosior
from setuptools.command.sdist import sdist
12
13
from pathlib import Path
14
15
here = Path(__file__).resolve().parent
16 6bc04f80 Wojtek Kosior
17
class CustomBuildCommand(build_py):
18 22c722bf Wojtek Kosior
    """The build command but runs babel before build."""
19 6bc04f80 Wojtek Kosior
    def run(self, *args, **kwargs):
20 22c722bf Wojtek Kosior
        """Wrapper around build_py's original run() method."""
21 6bc04f80 Wojtek Kosior
        self.run_command('compile_catalog')
22 22c722bf Wojtek Kosior
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 6bc04f80 Wojtek Kosior
        super().run(*args, **kwargs)
42
43 22c722bf Wojtek Kosior
        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
})