Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6
with:
fail_ci_if_error: true
fail_ci_if_error: false
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ diff_pylint_report: pylint_report.txt
diff-quality --compare-branch=origin/main --violations=pylint pylint_report.txt

.coverage:
pytest --cov --cov-config=.coveragerc --cov-report= ${PYTEST_EXTRA}
pytest --cov --cov-config=.coveragerc --cov-report= --junitxml=junit.xml -o junit_family=legacy ${PYTEST_EXTRA}
$(COVBASE) -m schema_salad.main \
--print-jsonld-context src/schema_salad/metaschema/metaschema.yml \
> /dev/null
Expand Down Expand Up @@ -226,7 +226,7 @@ release:
flake8: FORCE
flake8 $(PYSOURCES)

src/schema_salad/metaschema.py: src/schema_salad/codegen_base.py src/schema_salad/python_codegen_support.py src/schema_salad/python_codegen.py src/schema_salad/metaschema/*.yml
src/schema_salad/metaschema.py: src/schema_salad/codegen_base.py src/schema_salad/runtime.py src/schema_salad/python_codegen.py src/schema_salad/metaschema/*.yml
schema-salad-tool --codegen python src/schema_salad/metaschema/metaschema.yml > $@

vpath %.yml src/schema_salad/tests/cpp_tests
Expand Down
21 changes: 12 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@ Schema salad can be used as a command line tool or imported as a Python module::

$ schema-salad-tool
usage: schema-salad-tool [-h] [--rdf-serializer RDF_SERIALIZER] [--skip-schemas]
[--strict-foreign-properties] [--print-jsonld-context]
[--print-rdfs] [--print-avro] [--print-rdf] [--print-pre]
[--print-index] [--print-metadata] [--print-inheritance-dot]
[--print-fieldrefs-dot] [--codegen language] [--codegen-target CODEGEN_TARGET]
[--codegen-examples directory] [--codegen-package dotted.package]
[--codegen-copyright copyright_string] [--print-oneline]
[--print-doc] [--strict | --non-strict]
[--strict-foreign-properties] [--version]
[--print-jsonld-context | --print-rdfs | --print-avro |
--print-rdf | --print-pre | --print-index | --print-metadata |
--print-inheritance-dot | --print-fieldrefs-dot | --codegen LANGUAGE |
--print-oneline | --print-doc]
[--codegen-target CODEGEN_TARGET] [--codegen-examples DIRECTORY]
[--codegen-package DOTTED.PACKAGE] [--codegen-parent PARENTS_MAP]
[--codegen-copyright COPYRIGHT_STRING]
[--codegen-spdx-copyright-text SPDX_COPYRIGHT_TEXT [SPDX_COPYRIGHT_TEXT ...]]
[--codegen-spdx-license-identifier SPDX_LICENSE_IDENTIFIER]
[--codegen-parser-info PARSER_INFO] [--strict | --non-strict]
[--verbose | --quiet | --debug] [--only ONLY] [--redirect REDIRECT]
[--brand BRAND] [--brandlink BRANDLINK] [--brandstyle BRANDSTYLE]
[--brandinverse] [--primtype PRIMTYPE] [--version]
[schema] [document]
[--brandinverse] [--primtype PRIMTYPE] [schema] [document ...]

$ python
>>> import schema_salad
Expand Down
7 changes: 6 additions & 1 deletion src/schema_salad/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def codegen(
examples: str | None = None,
package: str | None = None,
copyright: str | None = None,
parents_map: dict[str, str] | None = None,
spdx_copyright_text: list[str] | None = None,
spdx_license_identifier: str | None = None,
parser_info: str | None = None,
Expand Down Expand Up @@ -87,7 +88,11 @@ def codegen(
return
case "python":
gen = PythonCodeGen(
dest, copyright=copyright, parser_info=info, salad_version=salad_version
dest,
copyright=copyright,
parents_map=parents_map,
parser_info=info,
salad_version=salad_version,
)
case "java":
gen = JavaCodeGen(
Expand Down
19 changes: 19 additions & 0 deletions src/schema_salad/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
_logger: Final = logging.getLogger("salad")


def parse_kv(pair: str) -> tuple[str, str]:
Comment thread
mr-c marked this conversation as resolved.
"""Parse `key=value` arguments into a tuple of `key` and `value`."""
try:
k, v = pair.split("=", 1)
return k, v
except ValueError as e:
raise argparse.ArgumentTypeError(f"Invalid format: '{pair}', expected key=value") from e


def printrdf(
workflow: str,
wf: CommentedMap | CommentedSeq,
Expand Down Expand Up @@ -147,6 +156,15 @@ def arg_parser() -> argparse.ArgumentParser:
"from the base URL (Java/TypeScript/.Net/Dlang only).",
)

codegen_opts.add_argument(
"--codegen-parent",
type=parse_kv,
metavar="PARENTS_MAP",
action="append",
default=None,
help="Optional mapping of prefix into parent package for generated classes (Python only).",
)

codegen_opts.add_argument(
"--codegen-copyright",
type=str,
Expand Down Expand Up @@ -351,6 +369,7 @@ def main(argsl: list[str] | None = None) -> int:
examples=args.codegen_examples,
package=args.codegen_package,
copyright=args.codegen_copyright,
parents_map=dict(args.codegen_parent or []),
spdx_license_identifier=args.codegen_spdx_license_identifier,
spdx_copyright_text=args.codegen_spdx_copyright_text,
parser_info=args.codegen_parser_info,
Expand Down
Loading
Loading