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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/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 setuptools import Command
from pathlib import Path
here = Path(__file__).resolve().parent
class CustomBuildCommand(build_py):
"""The build command but performs some important tasks before the build."""
def run(self, *args, **kwargs):
"""Wrapper around build_py's original run() method."""
self.run_command('compile_catalog')
self.run_command('copy_licenses')
super().run(*args, **kwargs)
class CopyLicenseFilesCommand(Command):
"""
Command to copy some resources from beneath `LICENSES/` so that they get
included in the wheel and are accessible to Flask.
"""
user_options = []
def run (self, *args, **kwargs):
"""Copy the relevant license files"""
import shutil
static_dir = here / 'src' / 'koszko_org_website' / 'static'
licenses_dir = here / 'LICENSES'
for in_name, out_name in [
('LicenseRef-Yahoo-BSD-3', 'yahoo-bsd-license'),
('LicenseRef-Normalize-CSS-MIT', 'normalize-mit-license'),
('CC0-1.0', 'cc0-1.0'),
('CC-BY-3.0', 'cc-by-3.0')
]:
shutil.copy(
licenses_dir / f'{in_name}.txt',
static_dir / f'{out_name}.txt'
)
def initialize_options(self):
pass
def finalize_options(self):
pass
setuptools.setup(cmdclass = {
'build_py': CustomBuildCommand,
'copy_licenses': CopyLicenseFilesCommand
})
|