#!/usr/bin/env python3 # SPDX-License-Identifier: CC0-1.0 # Copyright (C) 2022 Wojtek Kosior # # 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 })