Skip to content
Commits on Source (3)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
include gittaggers.py Makefile
include gittaggers.py Makefile LICENSE.txt
include schema_salad/avro/*
include schema_salad/tests/*
include schema_salad/tests/test_schema/*.md
include schema_salad/tests/test_schema/*.yml
include schema_salad/tests/test_schema/*.cwl
include schema_salad/tests/foreign/*.cwl
recursive-include schema_salad/tests/test_real_cwl *
include schema_salad/metaschema/*
include schema_salad/tests/docimp/*
global-exclude *~
......
......@@ -15,25 +15,30 @@
#
# Contact: common-workflow-language@googlegroups.com
# make pep8 to check for basic Python code compliance
# make pycodestyle to check for basic Python code compliance
# make autopep8 to fix most pep8 errors
# make pylint to check Python code for enhanced compliance including naming
# and documentation
# make coverage-report to check coverage of the python scripts by the tests
MODULE=schema_salad
PACKAGE=schema-salad
# `SHELL=bash` Will break Titus's laptop, so don't use BASH-isms like
# `SHELL=bash` doesn't work for some, so don't use BASH-isms like
# `[[` conditional expressions.
PYSOURCES=$(wildcard ${MODULE}/**.py tests/*.py) setup.py
DEVPKGS=pep8 diff_cover autopep8 pylint coverage pep257 pytest flake8
DEVPKGS=pycodestyle diff_cover autopep8 pylint coverage pep257 pytest flake8
COVBASE=coverage run --branch --append --source=${MODULE} \
--omit=schema_salad/tests/*
VERSION=$(shell git describe --tags --dirty | sed s/v//)
# Updating the Major & Minor version below?
# Don't forget to update setup.py as well
VERSION=3.0.$(shell date +%Y%m%d%H%M%S --utc --date=`git log --first-parent \
--max-count=1 --format=format:%cI`)
## all : default task
all: ./setup.py develop
all:
pip install -e .
## help : print this help message and exit
help: Makefile
......@@ -54,7 +59,7 @@ install: FORCE
dist: dist/${MODULE}-$(VERSION).tar.gz
dist/${MODULE}-$(VERSION).tar.gz: $(SOURCES)
./setup.py sdist
./setup.py sdist bdist_wheel
## clean : clean up all temporary / machine-generated files
clean: FORCE
......@@ -63,25 +68,34 @@ clean: FORCE
rm -Rf .coverage
rm -f diff-cover.html
## pep8 : check Python code style
pep8: $(PYSOURCES)
pep8 --exclude=_version.py --show-source --show-pep8 $^ || true
# Linting and code style related targets
## sorting imports using isort: https://github.com/timothycrosley/isort
sort_imports:
isort ${MODULE}/*.py ${MODULE}/tests/*.py setup.py
pep8_report.txt: $(PYSOURCES)
pep8 --exclude=_version.py $^ > $@ || true
pep8: pycodestyle
## pycodestyle : check Python code style
pycodestyle: $(PYSOURCES)
pycodestyle --exclude=_version.py --show-source --show-pep8 $^ || true
diff_pep8_report: pep8_report.txt
diff-quality --violations=pep8 pep8_report.txt
pep8_report.txt: pycodestyle_report.txt
pycodestyle_report.txt: $(PYSOURCES)
pycodestyle --exclude=_version.py $^ > $@ || true
## pep257 : check Python code style
pep257: $(PYSOURCES)
pep257 --ignore=D100,D101,D102,D103 $^ || true
diff_pep8_report: diff_pycodestyle_report
diff_pycodestyle_report: pycodestyle_report.txt
diff-quality --violations=pycodestyle $^
pep257_report.txt: $(PYSOURCES)
pep257 setup.py $^ > $@ 2>&1 || true
pep257: pydocstyle
## pydocstyle : check Python code style
pydocstyle: $(PYSOURCES)
pydocstyle --ignore=D100,D101,D102,D103 $^ || true
diff_pep257_report: pep257_report.txt
diff-quality --violations=pep8 pep257_report.txt
pydocstyle_report.txt: $(PYSOURCES)
pydocstyle setup.py $^ > $@ 2>&1 || true
diff_pydocstyle_report: pydocstyle_report.txt
diff-quality --violations=pycodestyle $^
## autopep8 : fix most Python code indentation and formatting
autopep8: $(PYSOURCES)
......@@ -95,16 +109,16 @@ format: autopep8
## pylint : run static code analysis on Python code
pylint: $(PYSOURCES)
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
$^ || true
$^ -j$(nproc)|| true
pylint_report.txt: ${PYSOURCES}
pylint --msg-template="{path}:{line}: [{msg_id}({symbol}), {obj}] {msg}" \
$^ > $@ || true
$^ -j$(nproc)> $@ || true
diff_pylint_report: pylint_report.txt
diff-quality --violations=pylint pylint_report.txt
.coverage: $(PYSOURCES)
.coverage: $(PYSOURCES) all
rm -f .coverage
$(COVBASE) setup.py test
$(COVBASE) -m schema_salad.main \
......@@ -181,12 +195,12 @@ mypy3: ${PYSOURCES}
--warn-redundant-casts \
schema_salad
jenkins:
jenkins: FORCE
rm -Rf env && virtualenv env
. env/bin/activate ; \
pip install -U setuptools pip wheel ; \
${MAKE} install-dep coverage.html coverage.xml pep257_report.txt \
sloccount.sc pep8_report.txt pylint_report.txt
sloccount.sc pycodestyle_report.txt pylint_report.txt
if ! test -d env3 ; then virtualenv -p python3 env3 ; fi
. env3/bin/activate ; \
pip install -U setuptools pip wheel ; \
......@@ -194,4 +208,22 @@ jenkins:
pip install -U -r mypy_requirements.txt ; ${MAKE} mypy2
# pip install -U -r mypy_requirements.txt ; ${MAKE} mypy3
release-test: FORCE
git diff-index --quiet HEAD -- || ( echo You have uncommited changes, please commit them and try again; false )
PYVER=2.7 ./release-test.sh
PYVER=3 ./release-test.sh
release: release-test
. testenv2.7_2/bin/activate && \
testenv2.7_2/src/${PACKAGE}/setup.py sdist bdist_wheel
. testenv2.7_2/bin/activate && \
pip install twine && \
twine upload testenv2.7_2/src/${PACKAGE}/dist/* && \
git tag ${VERSION} && git push --tags
FORCE:
# Use this to print the value of a Makefile variable
# Example `make print-VERSION`
# From https://www.cmcrossroads.com/article/printing-value-makefile-variable
print-% : ; @echo $* = $($*)
Metadata-Version: 1.1
Name: schema-salad
Version: 2.6.20171201034858
Version: 3.0.20181129082112
Summary: Schema Annotations for Linked Avro Data (SALAD)
Home-page: https://github.com/common-workflow-language/common-workflow-language
Home-page: https://github.com/common-workflow-language/schema_salad
Author: Common workflow language working group
Author-email: common-workflow-language@googlegroups.com
License: Apache 2.0
Download-URL: https://github.com/common-workflow-language/common-workflow-language
Description-Content-Type: UNKNOWN
Download-URL: https://github.com/common-workflow-language/schema_salad/releases
Description: |Build Status| |Build status|
.. |Build Status| image:: https://img.shields.io/travis/common-workflow-language/schema_salad/master.svg?label=unix%20build
:target: https://travis-ci.org/common-workflow-language/schema_salad
.. |Build status| image:: https://img.shields.io/appveyor/ci/mr-c/schema-salad/master.svg?label=windows%20build
:target: https://ci.appveyor.com/project/mr-c/schema-salad/branch/master
.. |Code coverage| image:: https://codecov.io/gh/common-workflow-language/schema_salad/branch/master/graph/badge.svg
:target: https://codecov.io/gh/common-workflow-language/schema_salad
Schema Salad
------------
Salad is a schema language for describing JSON or YAML structured linked data
documents. Salad is based originally on JSON-LD_ and the Apache Avro_ data
serialization system.
Salad schema describes rules for preprocessing, structural validation, and link
checking for documents described by a Salad schema. Salad features for rich
data modeling such as inheritance, template specialization, object identifiers,
object references, documentation generation, and transformation to RDF_. Salad
provides a bridge between document and record oriented data modeling and the
Semantic Web.
Salad is a schema language for describing JSON or YAML structured
linked data documents. Salad schema describes rules for
preprocessing, structural validation, and hyperlink checking for
documents described by a Salad schema. Salad supports rich data
modeling with inheritance, template specialization, object
identifiers, object references, documentation generation, code
generation, and transformation to RDF_. Salad provides a bridge
between document and record oriented data modeling and the Semantic
Web.
Usage
-----
......@@ -35,14 +35,6 @@ Description: |Build Status| |Build status|
::
$ pip install schema_salad
$ schema-salad-tool
usage: schema-salad-tool [-h] [--rdf-serializer RDF_SERIALIZER]
[--print-jsonld-context | --print-doc | --print-rdfs | --print-avro | --print-rdf | --print-pre | --print-index | --print-metadata | --version]
[--strict | --non-strict]
[--verbose | --quiet | --debug]
schema [document]
$ python
>>> import schema_salad
To install from source::
......@@ -50,6 +42,44 @@ Description: |Build Status| |Build status|
cd schema_salad
python setup.py install
Commands
--------
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]
[--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]
[--strict | --non-strict] [--verbose | --quiet | --debug] [--version]
[schema] [document]
$ python
>>> import schema_salad
Validate a schema::
$ schema-salad-tool myschema.yml
Validate a document using a schema::
$ schema-salad-tool myschema.yml mydocument.yml
Get JSON-LD context::
$ schema-salad-tool --print-jsonld-context myschema.yml mydocument.yml
Convert a document to JSON-LD::
$ schema-salad-tool --print-pre myschema.yml mydocument.yml > mydocument.jsonld
Generate Python classes for loading/generating documents described by the schema::
$ schema-salad-tool --codegen=python myschema.yml > myschema.py
Display inheritance relationship between classes as a graphviz 'dot' file and render as SVG::
$ schema-salad-tool --print-inheritance-dot myschema.yml | dot -Tsvg > myschema.svg
Documentation
-------------
......@@ -57,6 +87,7 @@ Description: |Build Status| |Build status|
See the specification_ and the metaschema_ (salad schema for itself). For an
example application of Schema Salad see the Common Workflow Language_.
Rationale
---------
......@@ -101,11 +132,13 @@ Description: |Build Status| |Build status|
Platform: UNKNOWN
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: POSIX
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: Microsoft :: Windows
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
......@@ -4,20 +4,21 @@
:target: https://travis-ci.org/common-workflow-language/schema_salad
.. |Build status| image:: https://img.shields.io/appveyor/ci/mr-c/schema-salad/master.svg?label=windows%20build
:target: https://ci.appveyor.com/project/mr-c/schema-salad/branch/master
.. |Code coverage| image:: https://codecov.io/gh/common-workflow-language/schema_salad/branch/master/graph/badge.svg
:target: https://codecov.io/gh/common-workflow-language/schema_salad
Schema Salad
------------
Salad is a schema language for describing JSON or YAML structured linked data
documents. Salad is based originally on JSON-LD_ and the Apache Avro_ data
serialization system.
Salad schema describes rules for preprocessing, structural validation, and link
checking for documents described by a Salad schema. Salad features for rich
data modeling such as inheritance, template specialization, object identifiers,
object references, documentation generation, and transformation to RDF_. Salad
provides a bridge between document and record oriented data modeling and the
Semantic Web.
Salad is a schema language for describing JSON or YAML structured
linked data documents. Salad schema describes rules for
preprocessing, structural validation, and hyperlink checking for
documents described by a Salad schema. Salad supports rich data
modeling with inheritance, template specialization, object
identifiers, object references, documentation generation, code
generation, and transformation to RDF_. Salad provides a bridge
between document and record oriented data modeling and the Semantic
Web.
Usage
-----
......@@ -25,14 +26,6 @@ Usage
::
$ pip install schema_salad
$ schema-salad-tool
usage: schema-salad-tool [-h] [--rdf-serializer RDF_SERIALIZER]
[--print-jsonld-context | --print-doc | --print-rdfs | --print-avro | --print-rdf | --print-pre | --print-index | --print-metadata | --version]
[--strict | --non-strict]
[--verbose | --quiet | --debug]
schema [document]
$ python
>>> import schema_salad
To install from source::
......@@ -40,6 +33,44 @@ To install from source::
cd schema_salad
python setup.py install
Commands
--------
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]
[--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]
[--strict | --non-strict] [--verbose | --quiet | --debug] [--version]
[schema] [document]
$ python
>>> import schema_salad
Validate a schema::
$ schema-salad-tool myschema.yml
Validate a document using a schema::
$ schema-salad-tool myschema.yml mydocument.yml
Get JSON-LD context::
$ schema-salad-tool --print-jsonld-context myschema.yml mydocument.yml
Convert a document to JSON-LD::
$ schema-salad-tool --print-pre myschema.yml mydocument.yml > mydocument.jsonld
Generate Python classes for loading/generating documents described by the schema::
$ schema-salad-tool --codegen=python myschema.yml > myschema.py
Display inheritance relationship between classes as a graphviz 'dot' file and render as SVG::
$ schema-salad-tool --print-inheritance-dot myschema.yml | dot -Tsvg > myschema.svg
Documentation
-------------
......@@ -47,6 +78,7 @@ Documentation
See the specification_ and the metaschema_ (salad schema for itself). For an
example application of Schema Salad see the Common Workflow Language_.
Rationale
---------
......
from setuptools.command.egg_info import egg_info
import subprocess
import time
from setuptools.command.egg_info import egg_info
class EggInfoFromGit(egg_info):
"""Tag the build with git commit timestamp.
......@@ -21,3 +23,4 @@ class EggInfoFromGit(egg_info):
except (subprocess.CalledProcessError, OSError):
pass
return egg_info.tags(self)
vtags = property(tags)
Metadata-Version: 1.1
Name: schema-salad
Version: 2.6.20171201034858
Version: 3.0.20181129082112
Summary: Schema Annotations for Linked Avro Data (SALAD)
Home-page: https://github.com/common-workflow-language/common-workflow-language
Home-page: https://github.com/common-workflow-language/schema_salad
Author: Common workflow language working group
Author-email: common-workflow-language@googlegroups.com
License: Apache 2.0
Download-URL: https://github.com/common-workflow-language/common-workflow-language
Description-Content-Type: UNKNOWN
Download-URL: https://github.com/common-workflow-language/schema_salad/releases
Description: |Build Status| |Build status|
.. |Build Status| image:: https://img.shields.io/travis/common-workflow-language/schema_salad/master.svg?label=unix%20build
:target: https://travis-ci.org/common-workflow-language/schema_salad
.. |Build status| image:: https://img.shields.io/appveyor/ci/mr-c/schema-salad/master.svg?label=windows%20build
:target: https://ci.appveyor.com/project/mr-c/schema-salad/branch/master
.. |Code coverage| image:: https://codecov.io/gh/common-workflow-language/schema_salad/branch/master/graph/badge.svg
:target: https://codecov.io/gh/common-workflow-language/schema_salad
Schema Salad
------------
Salad is a schema language for describing JSON or YAML structured linked data
documents. Salad is based originally on JSON-LD_ and the Apache Avro_ data
serialization system.
Salad schema describes rules for preprocessing, structural validation, and link
checking for documents described by a Salad schema. Salad features for rich
data modeling such as inheritance, template specialization, object identifiers,
object references, documentation generation, and transformation to RDF_. Salad
provides a bridge between document and record oriented data modeling and the
Semantic Web.
Salad is a schema language for describing JSON or YAML structured
linked data documents. Salad schema describes rules for
preprocessing, structural validation, and hyperlink checking for
documents described by a Salad schema. Salad supports rich data
modeling with inheritance, template specialization, object
identifiers, object references, documentation generation, code
generation, and transformation to RDF_. Salad provides a bridge
between document and record oriented data modeling and the Semantic
Web.
Usage
-----
......@@ -35,14 +35,6 @@ Description: |Build Status| |Build status|
::
$ pip install schema_salad
$ schema-salad-tool
usage: schema-salad-tool [-h] [--rdf-serializer RDF_SERIALIZER]
[--print-jsonld-context | --print-doc | --print-rdfs | --print-avro | --print-rdf | --print-pre | --print-index | --print-metadata | --version]
[--strict | --non-strict]
[--verbose | --quiet | --debug]
schema [document]
$ python
>>> import schema_salad
To install from source::
......@@ -50,6 +42,44 @@ Description: |Build Status| |Build status|
cd schema_salad
python setup.py install
Commands
--------
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]
[--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]
[--strict | --non-strict] [--verbose | --quiet | --debug] [--version]
[schema] [document]
$ python
>>> import schema_salad
Validate a schema::
$ schema-salad-tool myschema.yml
Validate a document using a schema::
$ schema-salad-tool myschema.yml mydocument.yml
Get JSON-LD context::
$ schema-salad-tool --print-jsonld-context myschema.yml mydocument.yml
Convert a document to JSON-LD::
$ schema-salad-tool --print-pre myschema.yml mydocument.yml > mydocument.jsonld
Generate Python classes for loading/generating documents described by the schema::
$ schema-salad-tool --codegen=python myschema.yml > myschema.py
Display inheritance relationship between classes as a graphviz 'dot' file and render as SVG::
$ schema-salad-tool --print-inheritance-dot myschema.yml | dot -Tsvg > myschema.svg
Documentation
-------------
......@@ -57,6 +87,7 @@ Description: |Build Status| |Build status|
See the specification_ and the metaschema_ (salad schema for itself). For an
example application of Schema Salad see the Common Workflow Language_.
Rationale
---------
......@@ -101,11 +132,13 @@ Description: |Build Status| |Build status|
Platform: UNKNOWN
Classifier: Environment :: Console
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: POSIX :: Linux
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: POSIX
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: Microsoft :: Windows
Classifier: Development Status :: 5 - Production/Stable
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
LICENSE.txt
MANIFEST.in
Makefile
README.rst
......@@ -24,10 +25,13 @@ schema_salad.egg-info/PKG-INFO
schema_salad.egg-info/SOURCES.txt
schema_salad.egg-info/dependency_links.txt
schema_salad.egg-info/entry_points.txt
schema_salad.egg-info/pbr.json
schema_salad.egg-info/requires.txt
schema_salad.egg-info/top_level.txt
schema_salad.egg-info/zip-safe
schema_salad/avro/LICENSE
schema_salad/avro/NOTICE
schema_salad/avro/__init__.py
schema_salad/avro/schema.py
schema_salad/metaschema/field_name.yml
schema_salad/metaschema/field_name_proc.yml
schema_salad/metaschema/field_name_schema.yml
......@@ -45,9 +49,7 @@ schema_salad/metaschema/map_res.yml
schema_salad/metaschema/map_res_proc.yml
schema_salad/metaschema/map_res_schema.yml
schema_salad/metaschema/map_res_src.yml
schema_salad/metaschema/metaschema.html
schema_salad/metaschema/metaschema.yml
schema_salad/metaschema/metaschema2.yml
schema_salad/metaschema/metaschema_base.yml
schema_salad/metaschema/salad.md
schema_salad/metaschema/typedsl_res.yml
......@@ -58,14 +60,11 @@ schema_salad/metaschema/vocab_res.yml
schema_salad/metaschema/vocab_res_proc.yml
schema_salad/metaschema/vocab_res_schema.yml
schema_salad/metaschema/vocab_res_src.yml
schema_salad/tests/#cg_metaschema.py#
schema_salad/tests/.coverage
schema_salad/tests/EDAM.owl
schema_salad/tests/Process.yml
schema_salad/tests/__init__.py
schema_salad/tests/bad_schema.yml
schema_salad/tests/cwl-pre.yml
schema_salad/tests/df
schema_salad/tests/df2
schema_salad/tests/frag.yml
schema_salad/tests/hello.txt
schema_salad/tests/hellofield.yml
......@@ -78,9 +77,10 @@ schema_salad/tests/test_cli_args.py
schema_salad/tests/test_errors.py
schema_salad/tests/test_examples.py
schema_salad/tests/test_fetch.py
schema_salad/tests/test_fp.py
schema_salad/tests/test_print_oneline.py
schema_salad/tests/test_real_cwl.py
schema_salad/tests/test_ref_resolver.py
schema_salad/tests/test_validate.pyx
schema_salad/tests/util.py
schema_salad/tests/docimp/d1.yml
schema_salad/tests/docimp/d2.md
......@@ -88,6 +88,20 @@ schema_salad/tests/docimp/d3.yml
schema_salad/tests/docimp/d4.yml
schema_salad/tests/docimp/d5.md
schema_salad/tests/docimp/dpre.json
schema_salad/tests/foreign/foreign_prop1.cwl
schema_salad/tests/foreign/foreign_prop2.cwl
schema_salad/tests/foreign/foreign_prop3.cwl
schema_salad/tests/foreign/foreign_prop4.cwl
schema_salad/tests/foreign/foreign_prop5.cwl
schema_salad/tests/foreign/foreign_prop6.cwl
schema_salad/tests/foreign/foreign_prop7.cwl
schema_salad/tests/test_real_cwl/ICGC-TCGA-PanCancer/PreprocessedFilesType.yaml
schema_salad/tests/test_real_cwl/ICGC-TCGA-PanCancer/preprocess_util.js
schema_salad/tests/test_real_cwl/ICGC-TCGA-PanCancer/preprocess_vcf.cwl
schema_salad/tests/test_real_cwl/ICGC-TCGA-PanCancer/vcf_merge_util.js
schema_salad/tests/test_real_cwl/h3agatk/GATK-Sub-Workflow-h3abionet-snp.cwl
schema_salad/tests/test_real_cwl/h3agatk/GATK-complete-WES-Workflow-h3abionet.cwl
schema_salad/tests/test_real_cwl/topmed/topmed_variant_calling_pipeline.cwl
schema_salad/tests/test_schema/CommandLineTool.yml
schema_salad/tests/test_schema/CommonWorkflowLanguage.yml
schema_salad/tests/test_schema/Process.yml
......
{"is_release": false, "git_version": "c7f3140"}
\ No newline at end of file
setuptools
requests>=1.0
ruamel.yaml<0.15,>=0.12.4
ruamel.yaml<0.16,>=0.12.4
rdflib<4.3.0,>=4.2.2
rdflib-jsonld<0.5.0,>=0.3.0
mistune<0.8,>=0.7.3
typing>=3.5.3
mistune<0.9,>=0.8.1
CacheControl<0.12,>=0.11.7
lockfile>=0.9
six>=1.8.0
typing-extensions
[:python_version<"3"]
avro==1.8.1
[:python_version>="3"]
future
avro-cwl==1.8.4
[:python_version<"3.7"]
typing>=3.6.4
......@@ -3,6 +3,7 @@ import logging
import os
import sys
import typing
import threading
import six
......@@ -12,21 +13,3 @@ __author__ = 'peter.amstutz@curoverse.com'
_logger = logging.getLogger("salad")
_logger.addHandler(logging.StreamHandler())
_logger.setLevel(logging.INFO)
if six.PY3:
if onWindows:
# create '/tmp' folder if not present
# required by autotranslate module
# TODO: remove when https://github.com/PythonCharmers/python-future/issues/295
# is fixed
if not os.path.exists("/tmp"):
try:
os.makedirs("/tmp")
except OSError as exception:
_logger.error(u"Cannot create '\\tmp' folder in root needed for",
"'cwltool' Python 3 installation.")
exit(1)
from past import autotranslate # type: ignore
autotranslate(['avro', 'avro.schema'])
"""Default entry point for the schema-salad module."""
from __future__ import absolute_import
from . import main
import sys
import typing
from . import main
sys.exit(main.main())
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Apache Avro
Copyright 2010-2015 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__all__ = ['schema']
This diff is collapsed.
import json
"""Generate langauge specific loaders for a particular SALAD schema."""
import sys
from six.moves import urllib, cStringIO
import collections
import logging
from pkg_resources import resource_stream
from .utils import aslist, flatten
from typing import Any, Dict, List, MutableMapping, Optional, Union
from typing_extensions import Text # pylint: disable=unused-import
# move to a regular typing import when Python 3.3-3.6 is no longer supported
from . import schema
from .codegen_base import shortname, CodeGenBase
from .python_codegen import PythonCodeGen
from .codegen_base import CodeGenBase
from .java_codegen import JavaCodeGen
from .ref_resolver import Loader
from typing import List, Dict, Text, Any, Union, Text
from ruamel.yaml.comments import CommentedSeq, CommentedMap
class GoCodeGen(object):
pass
from .python_codegen import PythonCodeGen
from .ref_resolver import Loader # pylint: disable=unused-import
from .schema import shortname
from .utils import aslist
def codegen(lang, # type: str
i, # type: List[Dict[Text, Any]]
schema_metadata, # type: Dict[Text, Any]
loader # type: Loader
):
# type: (...) -> None
): # type: (...) -> None
"""Generate classes with loaders for the given Schema Salad description."""
j = schema.extend_and_specialize(i, loader)
cg = None # type: CodeGenBase
gen = None # type: Optional[CodeGenBase]
if lang == "python":
cg = PythonCodeGen(sys.stdout)
gen = PythonCodeGen(sys.stdout)
elif lang == "java":
cg = JavaCodeGen(schema_metadata.get("$base", schema_metadata.get("id")))
gen = JavaCodeGen(schema_metadata.get("$base", schema_metadata.get("id")))
else:
raise Exception("Unsupported code generation language '%s'" % lang)
assert gen is not None
cg.prologue()
gen.prologue()
documentRoots = []
document_roots = []
for rec in j:
if rec["type"] in ("enum", "record"):
cg.type_loader(rec)
cg.add_vocab(shortname(rec["name"]), rec["name"])
gen.type_loader(rec)
gen.add_vocab(shortname(rec["name"]), rec["name"])
for rec in j:
if rec["type"] == "enum":
for s in rec["symbols"]:
cg.add_vocab(shortname(s), s)
for symbol in rec["symbols"]:
gen.add_vocab(shortname(symbol), symbol)
if rec["type"] == "record":
if rec.get("documentRoot"):
documentRoots.append(rec["name"])
cg.begin_class(rec["name"], aslist(rec.get("extends", [])), rec.get("doc"),
rec.get("abstract"))
cg.add_vocab(shortname(rec["name"]), rec["name"])
for f in rec.get("fields", []):
if f.get("jsonldPredicate") == "@id":
fieldpred = f["name"]
tl = cg.uri_loader(cg.type_loader(f["type"]), True, False, None)
cg.declare_id_field(fieldpred, tl, f.get("doc"))
document_roots.append(rec["name"])
field_names = []
for field in rec.get("fields", []):
field_names.append(shortname(field["name"]))
idfield = ""
for field in rec.get("fields", []):
if field.get("jsonldPredicate") == "@id":
idfield = field.get("name")
gen.begin_class(rec["name"], aslist(rec.get("extends", [])), rec.get("doc", ""),
rec.get("abstract", False), field_names, idfield)
gen.add_vocab(shortname(rec["name"]), rec["name"])
for field in rec.get("fields", []):
if field.get("jsonldPredicate") == "@id":
fieldpred = field["name"]
optional = bool("https://w3id.org/cwl/salad#null" in field["type"])
uri_loader = gen.uri_loader(gen.type_loader(field["type"]), True, False, None)
gen.declare_id_field(fieldpred, uri_loader, field.get("doc"), optional)
break
for f in rec.get("fields", []):
optional = bool("https://w3id.org/cwl/salad#null" in f["type"])
tl = cg.type_loader(f["type"])
jld = f.get("jsonldPredicate")
fieldpred = f["name"]
if isinstance(jld, dict):
refScope = jld.get("refScope")
for field in rec.get("fields", []):
optional = bool("https://w3id.org/cwl/salad#null" in field["type"])
type_loader = gen.type_loader(field["type"])
jld = field.get("jsonldPredicate")
fieldpred = field["name"]
if isinstance(jld, MutableMapping):
ref_scope = jld.get("refScope")
if jld.get("typeDSL"):
tl = cg.typedsl_loader(tl, refScope)
type_loader = gen.typedsl_loader(type_loader, ref_scope)
elif jld.get("_type") == "@id":
tl = cg.uri_loader(tl, jld.get("identity"), False, refScope)
type_loader = gen.uri_loader(type_loader, jld.get("identity", False),
False, ref_scope)
elif jld.get("_type") == "@vocab":
tl = cg.uri_loader(tl, False, True, refScope)
type_loader = gen.uri_loader(type_loader, False, True, ref_scope)
mapSubject = jld.get("mapSubject")
if mapSubject:
tl = cg.idmap_loader(f["name"], tl, mapSubject, jld.get("mapPredicate"))
map_subject = jld.get("mapSubject")
if map_subject:
type_loader = gen.idmap_loader(
field["name"], type_loader, map_subject, jld.get("mapPredicate"))
if "_id" in jld and jld["_id"][0] != "@":
fieldpred = jld["_id"]
......@@ -87,14 +98,14 @@ def codegen(lang, # type: str
if jld == "@id":
continue
cg.declare_field(fieldpred, tl, f.get("doc"), optional)
gen.declare_field(fieldpred, type_loader, field.get("doc"), optional)
cg.end_class(rec["name"])
gen.end_class(rec["name"], field_names)
rootType = list(documentRoots)
rootType.append({
root_type = list(document_roots)
root_type.append({
"type": "array",
"items": documentRoots
"items": document_roots
})
cg.epilogue(cg.type_loader(rootType))
gen.epilogue(gen.type_loader(root_type))
"""Base class for the generation of loaders from schema-salad definitions."""
import collections
from six.moves import urllib
from typing import List, Text, Dict, Union, Any
from typing import (Any, Dict, List, MutableSequence, Optional, Union)
from typing_extensions import Text # pylint: disable=unused-import
# move to a regular typing import when Python 3.3-3.6 is no longer supported
from . import schema
def shortname(inputid):
# type: (Text) -> Text
d = urllib.parse.urlparse(inputid)
if d.fragment:
return d.fragment.split(u"/")[-1]
else:
return d.path.split(u"/")[-1]
class TypeDef(object):
def __init__(self, name, init):
# type: (Text, Text) -> None
class TypeDef(object): # pylint: disable=too-few-public-methods
"""Schema Salad type description."""
# switch to class-style typing.NamedTuple once support for Python < 3.6
# is dropped
def __init__(self, # pylint: disable=too-many-arguments
name, # type: Text
init, # type: Text
is_uri=False, # type: bool
scoped_id=False, # type: bool
ref_scope=0 # type: Optional[int]
): # type: (...) -> None
self.name = name
self.init = init
self.is_uri = is_uri
self.scoped_id = scoped_id
self.ref_scope = ref_scope
class CodeGenBase(object):
def __init__(self):
# type: () -> None
"""Abstract base class for schema salad code generators."""
def __init__(self): # type: () -> None
self.collected_types = collections.OrderedDict() # type: collections.OrderedDict[Text, TypeDef]
self.vocab = {} # type: Dict[Text, Text]
def declare_type(self, t):
# type: (TypeDef) -> TypeDef
if t not in self.collected_types:
self.collected_types[t.name] = t
return t
def declare_type(self, declared_type): # type: (TypeDef) -> TypeDef
"""Add this type to our collection, if needed."""
if declared_type not in self.collected_types:
self.collected_types[declared_type.name] = declared_type
return declared_type
def add_vocab(self, name, uri):
# type: (Text, Text) -> None
def add_vocab(self, name, uri): # type: (Text, Text) -> None
"""Add the given name as an abbreviation for the given URI."""
self.vocab[name] = uri
def prologue(self):
# type: () -> None
def prologue(self): # type: () -> None
"""Trigger to generate the prolouge code."""
raise NotImplementedError()
def safe_name(self, n):
# type: (Text) -> Text
return schema.avro_name(n)
def begin_class(self, classname, extends, doc, abstract):
# type: (Text, List[Text], Text, bool) -> None
@staticmethod
def safe_name(name): # type: (Text) -> Text
"""Generate a safe version of the given name."""
return schema.avro_name(name)
def begin_class(self, # pylint: disable=too-many-arguments
classname, # type: Text
extends, # type: MutableSequence[Text]
doc, # type: Text
abstract, # type: bool
field_names, # type: MutableSequence[Text]
idfield # type: Text
): # type: (...) -> None
"""Produce the header for the given class."""
raise NotImplementedError()
def end_class(self, classname):
# type: (Text) -> None
def end_class(self, classname, field_names):
# type: (Text, List[Text]) -> None
"""Signal that we are done with this class."""
raise NotImplementedError()
def type_loader(self, t):
def type_loader(self, type_declaration):
# type: (Union[List[Any], Dict[Text, Any]]) -> TypeDef
"""Parse the given type declaration and declare its components."""
raise NotImplementedError()
def declare_field(self, name, typedef, doc, optional):
def declare_field(self, name, fieldtype, doc, optional):
# type: (Text, TypeDef, Text, bool) -> None
"""Output the code to load the given field."""
raise NotImplementedError()
def declare_id_field(self, name, typedef, doc):
# type: (Text, TypeDef, Text) -> None
def declare_id_field(self, name, fieldtype, doc, optional):
# type: (Text, TypeDef, Text, bool) -> None
"""Output the code to handle the given ID field."""
raise NotImplementedError()
def uri_loader(self, inner, scoped_id, vocab_term, refScope):
def uri_loader(self, inner, scoped_id, vocab_term, ref_scope):
# type: (TypeDef, bool, bool, Union[int, None]) -> TypeDef
"""Construct the TypeDef for the given URI loader."""
raise NotImplementedError()
def idmap_loader(self, field, inner, mapSubject, mapPredicate):
def idmap_loader(self, field, inner, map_subject, map_predicate):
# type: (Text, TypeDef, Text, Union[Text, None]) -> TypeDef
"""Construct the TypeDef for the given mapped ID loader."""
raise NotImplementedError()
def typedsl_loader(self, inner, refScope):
def typedsl_loader(self, inner, ref_scope):
# type: (TypeDef, Union[int, None]) -> TypeDef
"""Construct the TypeDef for the given DSL loader."""
raise NotImplementedError()
def epilogue(self, rootLoader):
# type: (TypeDef) -> None
def epilogue(self, root_loader): # type: (TypeDef) -> None
"""Trigger to generate the epilouge code."""
raise NotImplementedError()
import json
import sys
import six
from six.moves import urllib, cStringIO
import collections
import logging
from pkg_resources import resource_stream
from .utils import aslist, flatten
from . import schema
from .codegen_base import TypeDef, CodeGenBase, shortname
from typing import Text
"""Work-in-progress Java code generator for a given schema salad definition."""
import os
from typing import MutableSequence
from six import string_types
from six.moves import cStringIO, urllib
from typing_extensions import Text # pylint: disable=unused-import
# move to a regular typing import when Python 3.3-3.6 is no longer supported
from . import schema
from .codegen_base import CodeGenBase, TypeDef
class JavaCodeGen(CodeGenBase):
def __init__(self, base):
......@@ -20,21 +20,30 @@ class JavaCodeGen(CodeGenBase):
self.package = ".".join(list(reversed(sp.netloc.split("."))) + sp.path.strip("/").split("/"))
self.outdir = self.package.replace(".", "/")
def prologue(self):
def prologue(self): # type: () -> None
if not os.path.exists(self.outdir):
os.makedirs(self.outdir)
def safe_name(self, n):
avn = schema.avro_name(n)
@staticmethod
def safe_name(name): # type: (Text) -> Text
avn = schema.avro_name(name)
if avn in ("class", "extends", "abstract"):
# reserved words
avn = avn+"_"
return avn
def interface_name(self, n):
# type: (Text) -> Text
return self.safe_name(n)
def begin_class(self, classname, extends, doc, abstract):
def begin_class(self,
classname, # type: Text
extends, # type: MutableSequence[Text]
doc, # type: Text
abstract, # type: bool
field_names, # type: MutableSequence[Text]
idfield # type: Text
): # type: (...) -> None
cls = self.interface_name(classname)
self.current_class = cls
self.current_class_is_abstract = abstract
......@@ -68,7 +77,7 @@ public class {cls}Impl implements {cls} {{
void Load() {
""")
def end_class(self, classname):
def end_class(self, classname, field_names):
with open(os.path.join(self.outdir, "%s.java" % self.current_class), "a") as f:
f.write("""
}
......@@ -98,16 +107,16 @@ public class {cls}Impl implements {cls} {{
u"https://w3id.org/cwl/salad#Any": TypeDef("Any_type", "Support.AnyLoader()")
}
def type_loader(self, t):
if isinstance(t, list) and len(t) == 2:
if t[0] == "https://w3id.org/cwl/salad#null":
t = t[1]
if isinstance(t, basestring):
if t in self.prims:
return self.prims[t]
def type_loader(self, type_declaration):
if isinstance(type_declaration, MutableSequence) and len(type_declaration) == 2:
if type_declaration[0] == "https://w3id.org/cwl/salad#null":
type_declaration = type_declaration[1]
if isinstance(type_declaration, string_types):
if type_declaration in self.prims:
return self.prims[type_declaration]
return TypeDef("Object", "")
def declare_field(self, name, typedef, doc, optional):
def declare_field(self, name, fieldtype, doc, optional):
fieldname = self.safe_name(name)
with open(os.path.join(self.outdir, "%s.java" % self.current_class), "a") as f:
f.write("""
......@@ -115,7 +124,7 @@ public class {cls}Impl implements {cls} {{
""".
format(fieldname=fieldname,
capfieldname=fieldname[0].upper() + fieldname[1:],
type=typedef.name))
type=fieldtype.name))
if self.current_class_is_abstract:
return
......@@ -128,7 +137,7 @@ public class {cls}Impl implements {cls} {{
""".
format(fieldname=fieldname,
capfieldname=fieldname[0].upper() + fieldname[1:],
type=typedef.name))
type=fieldtype.name))
self.current_loader.write("""
this.{fieldname} = null; // TODO: loaders
......@@ -136,17 +145,18 @@ public class {cls}Impl implements {cls} {{
format(fieldname=fieldname))
def declare_id_field(self, name, typedef, doc):
def declare_id_field(self, name, fieldtype, doc, optional):
pass
def uri_loader(self, inner, scoped_id, vocab_term, refScope):
def uri_loader(self, inner, scoped_id, vocab_term, ref_scope):
return inner
def idmap_loader(self, field, inner, mapSubject, mapPredicate):
def idmap_loader(self, field, inner, map_subject, map_predicate):
return inner
def typedsl_loader(self, inner, refScope):
def typedsl_loader(self, inner, ref_scope):
return inner
def epilogue(self, rootLoader):
def epilogue(self, root_loader):
pass
from __future__ import absolute_import
import collections
import shutil
import json
import six
from six.moves import urllib
import logging
from typing import (Any, Dict, Iterable, List, # pylint: disable=unused-import
MutableMapping, MutableSequence, Optional, Tuple, Union,
cast)
import ruamel.yaml as yaml
try:
from ruamel.yaml import CSafeLoader as SafeLoader
except ImportError:
from ruamel.yaml import SafeLoader # type: ignore
import os
import subprocess
import copy
import pprint
import re
import sys
import rdflib
from rdflib import Graph, URIRef
import rdflib.namespace
from rdflib import Graph, URIRef
from rdflib.namespace import RDF, RDFS
import logging
from schema_salad.utils import aslist
from typing import (cast, Any, Dict, Iterable, List, Optional, Text, Tuple,
Union)
from .ref_resolver import Loader, ContextType
import six
from six.moves import urllib
from typing_extensions import Text # pylint: disable=unused-import
# move to a regular typing import when Python 3.3-3.6 is no longer supported
from .ref_resolver import ContextType # pylint: disable=unused-import
from .utils import aslist, json_dumps
_logger = logging.getLogger("salad")
def pred(datatype, # type: Dict[str, Union[Dict, str]]
def pred(datatype, # type: MutableMapping[Text, Union[Dict, Text]]
field, # type: Optional[Dict]
name, # type: str
context, # type: ContextType
defaultBase, # type: str
namespaces # type: Dict[str, rdflib.namespace.Namespace]
):
# type: (...) -> Union[Dict, Text]
namespaces # type: Dict[Text, rdflib.namespace.Namespace]
): # type: (...) -> Union[Dict, Text]
split = urllib.parse.urlsplit(name)
vee = None # type: Optional[Text]
......@@ -53,7 +43,7 @@ def pred(datatype, # type: Dict[str, Union[Dict, str]]
v = None # type: Optional[Dict]
if field is not None and "jsonldPredicate" in field:
if isinstance(field["jsonldPredicate"], dict):
if isinstance(field["jsonldPredicate"], MutableMapping):
v = {}
for k, val in field["jsonldPredicate"].items():
v[("@" + k[1:] if k.startswith("_") else k)] = val
......@@ -62,9 +52,9 @@ def pred(datatype, # type: Dict[str, Union[Dict, str]]
else:
v = field["jsonldPredicate"]
elif "jsonldPredicate" in datatype:
if isinstance(datatype["jsonldPredicate"], collections.Iterable):
if isinstance(datatype["jsonldPredicate"], Iterable):
for d in datatype["jsonldPredicate"]:
if isinstance(d, dict):
if isinstance(d, MutableMapping):
if d["symbol"] == name:
v = d["predicate"]
else:
......@@ -90,18 +80,20 @@ def pred(datatype, # type: Dict[str, Union[Dict, str]]
return ret
def process_type(t, # type: Dict[str, Any]
def process_type(t, # type: MutableMapping[Text, Any]
g, # type: Graph
context, # type: ContextType
defaultBase, # type: str
namespaces, # type: Dict[str, rdflib.namespace.Namespace]
namespaces, # type: Dict[Text, rdflib.namespace.Namespace]
defaultPrefix # type: str
):
# type: (...) -> None
if t["type"] == "record":
): # type: (...) -> None
if t["type"] not in ("record", "enum"):
return
if "name" in t:
recordname = t["name"]
_logger.debug("Processing record %s\n", t)
_logger.debug("Processing %s %s\n", t.get("type"), t)
classnode = URIRef(recordname)
g.add((classnode, RDF.type, RDFS.Class))
......@@ -127,6 +119,7 @@ def process_type(t, # type: Dict[str, Any]
recordname, predicate, type(predicate))
context[recordname] = predicate
if t["type"] == "record":
for i in t.get("fields", []):
fieldname = i["name"]
......@@ -152,7 +145,7 @@ def process_type(t, # type: Dict[str, Any]
# TODO generate range from datatype.
if isinstance(i["type"], dict) and "name" in i["type"]:
if isinstance(i["type"], MutableMapping):
process_type(i["type"], g, context, defaultBase,
namespaces, defaultPrefix)
......@@ -160,14 +153,14 @@ def process_type(t, # type: Dict[str, Any]
for e in aslist(t["extends"]):
g.add((classnode, RDFS.subClassOf, URIRef(e)))
elif t["type"] == "enum":
_logger.debug("Processing enum %s", t["name"])
_logger.debug("Processing enum %s", t.get("name"))
for i in t["symbols"]:
pred(t, None, i, context, defaultBase, namespaces)
def salad_to_jsonld_context(j, schema_ctx):
# type: (Iterable, Dict[str, Any]) -> Tuple[ContextType, Graph]
# type: (Iterable, MutableMapping[Text, Any]) -> Tuple[ContextType, Graph]
context = {} # type: ContextType
namespaces = {}
g = Graph()
......@@ -184,7 +177,7 @@ def salad_to_jsonld_context(j, schema_ctx):
defaultBase = ""
for k, v in namespaces.items():
g.bind(k, v)
g.bind(str(k), v)
for t in j:
process_type(t, g, context, defaultBase, namespaces, defaultPrefix)
......@@ -194,15 +187,14 @@ def salad_to_jsonld_context(j, schema_ctx):
def fix_jsonld_ids(obj, # type: Union[Dict[Text, Any], List[Dict[Text, Any]]]
ids # type: List[Text]
):
# type: (...) -> None
if isinstance(obj, dict):
): # type: (...) -> None
if isinstance(obj, MutableMapping):
for i in ids:
if i in obj:
obj["@id"] = obj[i]
for v in obj.values():
fix_jsonld_ids(v, ids)
if isinstance(obj, list):
if isinstance(obj, MutableSequence):
for entry in obj:
fix_jsonld_ids(entry, ids)
......@@ -211,12 +203,11 @@ def makerdf(workflow, # type: Text
wf, # type: Union[List[Dict[Text, Any]], Dict[Text, Any]]
ctx, # type: ContextType
graph=None # type: Graph
):
# type: (...) -> Graph
): # type: (...) -> Graph
prefixes = {}
idfields = []
for k, v in six.iteritems(ctx):
if isinstance(v, dict):
if isinstance(v, MutableMapping):
url = v["@id"]
else:
url = v
......@@ -234,13 +225,13 @@ def makerdf(workflow, # type: Text
else:
g = graph
if isinstance(wf, list):
if isinstance(wf, MutableSequence):
for w in wf:
w["@context"] = ctx
g.parse(data=json.dumps(w), format='json-ld', publicID=str(workflow))
g.parse(data=json_dumps(w), format='json-ld', publicID=str(workflow))
else:
wf["@context"] = ctx
g.parse(data=json.dumps(wf), format='json-ld', publicID=str(workflow))
g.parse(data=json_dumps(wf), format='json-ld', publicID=str(workflow))
# Bug in json-ld loader causes @id fields to be added to the graph
for sub, pred, obj in g.triples((None, URIRef("@id"), None)):
......