From 9e71d383bf59573a1dd48964a2c7900a57161973 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Fri, 11 Feb 2022 16:51:44 +0100 Subject: internationalize using Babel this commit also makes the sdist tarball generated by setuptools REUSE-compliant --- src/hydrilla/builder/__main__.py | 51 ++++------------------------------------ src/hydrilla/builder/build.py | 31 ++++++++++++++++++++---- 2 files changed, 31 insertions(+), 51 deletions(-) (limited to 'src/hydrilla/builder') diff --git a/src/hydrilla/builder/__main__.py b/src/hydrilla/builder/__main__.py index e60c50d..87dc9e2 100644 --- a/src/hydrilla/builder/__main__.py +++ b/src/hydrilla/builder/__main__.py @@ -1,50 +1,9 @@ -# SPDX-License-Identifier: AGPL-3.0-or-later +# SPDX-License-Identifier: CC0-1.0 -# Command line interface of Hydrilla package builder. +# Copyright (C) 2022 Wojtek Kosior # -# This file is part of Hydrilla -# -# Copyright (C) 2022 Wojtek Kosior -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -# -# I, Wojtek Kosior, thereby promise not to sue for violation of this -# file's license. Although I request that you do not make use this code -# in a proprietary program, I am not going to enforce this in court. - -from pathlib import Path - -import click - -from .build import Build - -dir_type = click.Path(exists=True, file_okay=False, resolve_path=True) +# Available under the terms of Creative Commons Zero v1.0 Universal. -@click.command() -@click.option('-s', '--srcdir', default='./', type=dir_type, show_default=True, - help='Source directory to build from.') -@click.option('-i', '--index-json', default='index.json', type=click.Path(), - help='Path to file to be processed instead of index.json (if not absolute, resolved relative to srcdir).') -@click.option('-d', '--dstdir', type=dir_type, required=True, - help='Destination directory to write built package files to.') -def preform_build(srcdir, index_json, dstdir): - """ - Build Hydrilla package from scrdir and write the resulting files under - dstdir. - """ - build = Build(Path(srcdir), Path(index_json)) - build.write_package_files(Path(dstdir)) +from . import build -preform_build() +build.perform() diff --git a/src/hydrilla/builder/build.py b/src/hydrilla/builder/build.py index cdbfad3..8d25b19 100644 --- a/src/hydrilla/builder/build.py +++ b/src/hydrilla/builder/build.py @@ -32,9 +32,12 @@ from hashlib import sha256 from sys import stderr import jsonschema +import click from .. import util +_ = util.get_gettext('hydrilla_builder') + index_validator = util.validator_for('package_source-1.schema.json') class FileReferenceError(Exception): @@ -99,12 +102,12 @@ def generate_spdx_report(root): try: from reuse._main import main as reuse_main except ModuleNotFoundError: - ReuseError("Could not import 'reuse'. Is the tool installed and visible to this Python instance?") + ReuseError(_('couldnt_import_reuse_is_it_installed')) mocked_output = FileBuffer() if reuse_main(args=['--root', str(root), 'lint'], out=mocked_output) != 0: stderr.write(mocked_output.get_bytes().decode()) - raise ReuseError('Attempt to generate an SPDX report for a REUSE-incompliant package.') + raise ReuseError(_('spdx_report_from_reuse_incompliant')) mocked_output = FileBuffer() if reuse_main(args=['--root', str(root), 'spdx'], out=mocked_output) != 0: @@ -188,10 +191,11 @@ class Build: path = path.resolve() if not path.is_relative_to(self.srcdir): - raise FileReferenceError(f"Attempt to load '{filename}' which lies outside package source directory.") + raise FileReferenceError(_('loading_{}_outside_package_dir') + .format(filename)) if str(path.relative_to(self.srcdir)) == 'index.json': - raise FileReferenceError("Attempt to load 'index.json' which is a reserved filename.") + raise FileReferenceError(_('loading_reserved_index_json')) file_ref = self.files_by_path.get(path) if file_ref is None: @@ -305,7 +309,7 @@ class Build: [self._process_file(f['file']) for f in index_obj['copyright']] if generate_spdx and not spdx_ref.include_in_distribution: - raise FileReferenceError("Told to generate 'report.spdx' but 'report.spdx' is not listed among copyright files. Refusing to proceed.") + raise FileReferenceError(_('report_spdx_not_in_copyright_list')) item_refs = [self._process_item(d) for d in index_obj['definitions']] @@ -373,3 +377,20 @@ class Build: version = '.'.join([str(n) for n in item_def['version']]) with open(item_dir_path / version, 'wt') as output: json.dump(item_def, output) + +dir_type = click.Path(exists=True, file_okay=False, resolve_path=True) + +@click.option('-s', '--srcdir', default='./', type=dir_type, show_default=True, + help=_('source_directory_to_build_from')) +@click.option('-i', '--index-json', default='index.json', type=click.Path(), + help=_('path_instead_of_index_json')) +@click.option('-d', '--dstdir', type=dir_type, required=True, + help=_('built_package_files_destination')) +def perform(srcdir, index_json, dstdir): + """""" + build = Build(Path(srcdir), Path(index_json)) + build.write_package_files(Path(dstdir)) + +perform.__doc__ = _('build_package_from_srcdir_to_dstdir') + +perform = click.command()(perform) -- cgit v1.2.3