aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/builder/build.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-11 16:51:44 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-12 11:34:59 +0100
commit9e71d383bf59573a1dd48964a2c7900a57161973 (patch)
tree8d4f2013815836ae4665825809b1f3bf8e9c4b77 /src/hydrilla/builder/build.py
parent4e46d7f7446b66e7f128169bb15b9cc88b03b3ba (diff)
downloadhydrilla-builder-9e71d383bf59573a1dd48964a2c7900a57161973.tar.gz
hydrilla-builder-9e71d383bf59573a1dd48964a2c7900a57161973.zip
internationalize using Babel
this commit also makes the sdist tarball generated by setuptools REUSE-compliant
Diffstat (limited to 'src/hydrilla/builder/build.py')
-rw-r--r--src/hydrilla/builder/build.py31
1 files changed, 26 insertions, 5 deletions
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):
+ """<this will be replaced by a localized docstring for Click to pick up>"""
+ 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)