aboutsummaryrefslogtreecommitdiff
path: root/setup.py
blob: 3aa9f749e49066d944ceaee77e1f8b034c71fd41 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# SPDX-License-Identifier: CC0-1.0

# Copyright (C) 2022 Wojtek Kosior <koszko@koszko.org>
#
# Available under the terms of Creative Commons Zero v1.0 Universal.

import setuptools

from setuptools.command.build_py import build_py
from setuptools.command.sdist import sdist

from pathlib import Path

here = Path(__file__).resolve().parent

class CustomBuildCommand(build_py):
    """The build command but runs babel before build."""
    def run(self, *args, **kwargs):
        """Wrapper around build_py's original run() method."""
        self.run_command('compile_catalog')

        super().run(*args, **kwargs)

class CustomSdistCommand(sdist):
    """
    The sdist command but prevents compiled message catalogs from being included
    in the archive.
    """
    def run(self, *args, **kwargs):
        """Wrapper around sdist's original run() method."""
        locales_dir = here / 'src/hydrilla/server/locales'
        locale_files = {}

        for path in locales_dir.rglob('*.mo'):
            locale_files[path] = path.read_bytes()

        for path in locale_files:
            path.unlink()

        super().run(*args, **kwargs)

        for path, contents in locale_files.items():
            path.write_bytes(contents)

setuptools.setup(cmdclass = {
    'build_py': CustomBuildCommand,
    'sdist': CustomSdistCommand
})