-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
93 changed files
with
1,168 additions
and
1,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
jobs: | ||
update-requirements: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Update requirements file | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pipenv-to-requirements | ||
pipenv_to_requirements | ||
- name: Check in requirements.txt and requirements-dev.txt | ||
run: | | ||
git add requirements*.txt | ||
if [[ ! -z $(git status -s requirements*.txt) ]] | ||
then | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git commit -m 'Automatically generated requirements.txt and requirements-dev.txt' requirements*.txt | ||
git push | ||
fi | ||
unittests-n-commits: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.7.1, 3.8, 3.9] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pipenv | ||
pipenv install --dev | ||
- name: Test with unittest | ||
run: | | ||
pipenv run python -m unittest | ||
- name: Check in test outputs | ||
if: ${{ matrix.python-version == '3.9' }} | ||
run: | | ||
find tests -name output -exec git add --force {} \; | ||
if [[ ! -z $(git status -s tests) ]] | ||
then | ||
git config --local user.email "[email protected]" | ||
git config --local user.name "GitHub Action" | ||
git commit -m 'Automated adding outputs from tests' tests | ||
git push | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Pull request unit tests | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
build-pipenv: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
python-version: [3.7.1, 3.8, 3.9] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install pipenv | ||
uses: dschep/install-pipenv-action@v1 | ||
- name: Install dependencies and test | ||
run: | | ||
pipenv install --dev | ||
pipenv run python -m unittest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Publish Python Package | ||
|
||
on: | ||
release: | ||
types: [created] | ||
|
||
jobs: | ||
build-n-publish: | ||
name: Build and publish Python 🐍 distributions 📦 to PyPI | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install wheel | ||
- name: build a binary wheel dist | ||
run: | | ||
rm -fr dist | ||
python setup.py bdist_wheel sdist | ||
- name: Publish distribution 📦 to PyPI | ||
uses: pypa/[email protected] | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.pypi_password }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,3 +137,6 @@ tests/test_config.ini | |
|
||
# Don't lock | ||
Pipfile.lock | ||
|
||
# No Pycharm | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Harold Solbrig <[email protected]> | ||
hsolbrig <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CHANGES | ||
======= | ||
|
||
* Remove YAMLRoot dependency on JsonObj | ||
* Checkpoint | ||
* checkpoint | ||
* Initial commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[[source]] | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
name = "pypi" | ||
|
||
[packages] | ||
hbreader = "*" | ||
pyld = { git = "https://github.com/hsolbrig/pyld"} | ||
jsonasobj = { git = "https://github.com/hsolbrig/jsonasobj"} | ||
pyyaml = ">=5.1" | ||
rdflib = "*" | ||
rdflib-pyld-compat = "*" | ||
rdflib-jsonld = "*" | ||
click = "*" | ||
prefixcommons = "*" | ||
shexjsg = "*" | ||
|
||
[dev-packages] | ||
requests = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
# checkout (update) all of the outputs to revert to what is on github | ||
git checkout `find tests -name output | xargs` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker image build . -t context_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker run -it --rm -d -p 8000:80 -p 8443:443 --name context_server -v `pwd`/:/usr/share/nginx/html context_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker stop context_server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
# Make all of the test output files invisible to git | ||
git update-index --assume-unchanged `git status -s | grep tests | grep \/output\/ | sed 's/.* tests\//tests\//' | xargs` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from linkml_runtime.dumpers.json_dumper import JSONDumper | ||
from linkml_runtime.dumpers.rdf_dumper import RDFDumper | ||
from linkml_runtime.dumpers.yaml_dumper import YAMLDumper | ||
|
||
json_dumper = JSONDumper() | ||
rdf_dumper = RDFDumper() | ||
yaml_dumper = YAMLDumper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
from linkml_runtime.utils.yamlutils import YAMLRoot | ||
|
||
|
||
class Dumper(ABC): | ||
""" Abstract base class for all dumpers """ | ||
|
||
def dump(self, element: YAMLRoot, to_file: str, **_) -> None: | ||
""" | ||
Write element to to_file | ||
:param element: LinkML object to be dumped | ||
:param to_file: file to dump to | ||
:@param _: method specific arguments | ||
""" | ||
with open(to_file, 'w') as output_file: | ||
output_file.write(self.dumps(element, **_)) | ||
|
||
@abstractmethod | ||
def dumps(self, element: YAMLRoot, **_) -> str: | ||
""" | ||
Convert element to a string | ||
@param element: YAMLRoot object to be rendered | ||
@param _: method specific arguments | ||
@return: stringified representation of element | ||
""" | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,51 @@ | ||
import json | ||
from typing import Dict | ||
|
||
from linkml_runtime.dumpers.dumper_root import Dumper | ||
from linkml_runtime.utils.context_utils import CONTEXTS_PARAM_TYPE | ||
from linkml_runtime.utils.yamlutils import YAMLRoot, as_json_object | ||
from jsonasobj import as_json | ||
|
||
|
||
def remove_empty_items(obj: Dict) -> Dict: | ||
""" | ||
Remove empty items from obj | ||
:param obj: | ||
:return: copy of dictionary with empty lists/dicts and Nones removed | ||
""" | ||
return {k: v for k, v in obj.items() if not (v is None or v == [] or v == {})} | ||
class JSONDumper(Dumper): | ||
|
||
def dump(self, element: YAMLRoot, to_file: str, contexts: CONTEXTS_PARAM_TYPE = None) -> None: | ||
""" | ||
Write element as json to to_file | ||
:param element: LinkML object to be serialized as YAML | ||
:param to_file: file to write to | ||
:param contexts: JSON-LD context(s) in the form of: | ||
* file name | ||
* URL | ||
* JSON String | ||
* dict | ||
* JSON Object | ||
* A list containing elements of any type named above | ||
""" | ||
super().dump(element, to_file, contexts=contexts) | ||
|
||
def dump(element: YAMLRoot, to_file: str, contexts: CONTEXTS_PARAM_TYPE = None) -> None: | ||
""" | ||
Write element as json to to_file | ||
:param element: LinkML object to be serialized as YAML | ||
:param to_file: file to write to | ||
:param contexts: JSON-LD context(s) in the form of: | ||
* file name | ||
* URL | ||
* JSON String | ||
* dict | ||
* JSON Object | ||
* A list containing elements of any type named above | ||
""" | ||
with open(to_file, 'w') as outf: | ||
outf.write(dumps(element, contexts)) | ||
def dumps(self, element: YAMLRoot, contexts: CONTEXTS_PARAM_TYPE = None) -> str: | ||
""" | ||
Return element as a JSON or a JSON-LD string | ||
:param element: LinkML object to be emitted | ||
:param contexts: JSON-LD context(s) in the form of: | ||
* file name | ||
* URL | ||
* JSON String | ||
* dict | ||
* JSON Object | ||
* A list containing elements of any type named above | ||
:return: JSON Object representing the element | ||
""" | ||
return json.dumps(as_json_object(element, contexts), | ||
default=lambda o: self.remove_empty_items(o) if isinstance(o, YAMLRoot) else json.JSONDecoder().decode(o), | ||
indent=' ') | ||
|
||
|
||
def dumps(element: YAMLRoot, contexts: CONTEXTS_PARAM_TYPE = None) -> str: | ||
""" | ||
Return element as a JSON or a JSON-LD string | ||
:param element: LinkML object to be emitted | ||
:param contexts: JSON-LD context(s) in the form of: | ||
* file name | ||
* URL | ||
* JSON String | ||
* dict | ||
* JSON Object | ||
* A list containing elements of any type named above | ||
:return: JSON Object representing the element | ||
""" | ||
return as_json(as_json_object(element, contexts), filtr=remove_empty_items, indent=' ') | ||
@staticmethod | ||
def remove_empty_items(obj: Dict) -> Dict: | ||
""" | ||
Remove empty items from obj | ||
:param obj: | ||
:return: copy of dictionary with empty lists/dicts and Nones removed | ||
""" | ||
return {k: v for k, v in obj.__dict__.items() if not (v is None or v == [] or v == {})} |
Oops, something went wrong.