Skip to content

Commit 7e2716b

Browse files
committed
Checkpoint
1 parent 48c59a0 commit 7e2716b

File tree

93 files changed

+1168
-1110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1168
-1110
lines changed

.github/workflows/main.yaml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
update-requirements:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Set up Python 3.8
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: 3.8
17+
18+
- name: Update requirements file
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install pipenv-to-requirements
22+
pipenv_to_requirements
23+
24+
- name: Check in requirements.txt and requirements-dev.txt
25+
run: |
26+
git add requirements*.txt
27+
if [[ ! -z $(git status -s requirements*.txt) ]]
28+
then
29+
git config --local user.email "[email protected]"
30+
git config --local user.name "GitHub Action"
31+
git commit -m 'Automatically generated requirements.txt and requirements-dev.txt' requirements*.txt
32+
git push
33+
fi
34+
35+
unittests-n-commits:
36+
runs-on: ubuntu-latest
37+
strategy:
38+
matrix:
39+
python-version: [3.7.1, 3.8, 3.9]
40+
41+
steps:
42+
- uses: actions/checkout@v2
43+
44+
- name: Set up Python ${{ matrix.python-version }}
45+
uses: actions/setup-python@v2
46+
with:
47+
python-version: ${{ matrix.python-version }}
48+
49+
- name: Install dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
pip install pipenv
53+
pipenv install --dev
54+
55+
- name: Test with unittest
56+
run: |
57+
pipenv run python -m unittest
58+
59+
- name: Check in test outputs
60+
if: ${{ matrix.python-version == '3.9' }}
61+
run: |
62+
find tests -name output -exec git add --force {} \;
63+
if [[ ! -z $(git status -s tests) ]]
64+
then
65+
git config --local user.email "[email protected]"
66+
git config --local user.name "GitHub Action"
67+
git commit -m 'Automated adding outputs from tests' tests
68+
git push
69+
fi

.github/workflows/pr-test.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Pull request unit tests
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
jobs:
8+
9+
build-pipenv:
10+
11+
runs-on: ubuntu-latest
12+
strategy:
13+
python-version: [3.7.1, 3.8, 3.9]
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install pipenv
23+
uses: dschep/install-pipenv-action@v1
24+
- name: Install dependencies and test
25+
run: |
26+
pipenv install --dev
27+
pipenv run python -m unittest

.github/workflows/pypi-publish.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Publish Python Package
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
build-n-publish:
9+
name: Build and publish Python 🐍 distributions 📦 to PyPI
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: 3.8
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install wheel
24+
25+
- name: build a binary wheel dist
26+
run: |
27+
rm -fr dist
28+
python setup.py bdist_wheel sdist
29+
30+
- name: Publish distribution 📦 to PyPI
31+
uses: pypa/[email protected]
32+
with:
33+
user: __token__
34+
password: ${{ secrets.pypi_password }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,6 @@ tests/test_config.ini
137137

138138
# Don't lock
139139
Pipfile.lock
140+
141+
# No Pycharm
142+
.idea/

AUTHORS

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Harold Solbrig <[email protected]>
2+

ChangeLog

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CHANGES
2+
=======
3+
4+
* Remove YAMLRoot dependency on JsonObj
5+
* Checkpoint
6+
* checkpoint
7+
* Initial commit

Pipfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
hbreader = "*"
8+
pyld = { git = "https://github.com/hsolbrig/pyld"}
9+
jsonasobj = { git = "https://github.com/hsolbrig/jsonasobj"}
10+
pyyaml = ">=5.1"
11+
rdflib = "*"
12+
rdflib-pyld-compat = "*"
13+
rdflib-jsonld = "*"
14+
click = "*"
15+
prefixcommons = "*"
16+
shexjsg = "*"
17+
18+
[dev-packages]
19+
requests = "*"

checkout_outputs.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# checkout (update) all of the outputs to revert to what is on github
3+
git checkout `find tests -name output | xargs`

db.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker image build . -t context_server

dr.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker run -it --rm -d -p 8000:80 -p 8443:443 --name context_server -v `pwd`/:/usr/share/nginx/html context_server

ds.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker stop context_server

hide_test_changes.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
# Make all of the test output files invisible to git
3+
git update-index --assume-unchanged `git status -s | grep tests | grep \/output\/ | sed 's/.* tests\//tests\//' | xargs`

linkml_model/__init__.py

-10
This file was deleted.

linkml_runtime/dumpers/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from linkml_runtime.dumpers.json_dumper import JSONDumper
2+
from linkml_runtime.dumpers.rdf_dumper import RDFDumper
3+
from linkml_runtime.dumpers.yaml_dumper import YAMLDumper
4+
5+
json_dumper = JSONDumper()
6+
rdf_dumper = RDFDumper()
7+
yaml_dumper = YAMLDumper()

linkml_runtime/dumpers/dumper_root.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from abc import ABC, abstractmethod
2+
3+
from linkml_runtime.utils.yamlutils import YAMLRoot
4+
5+
6+
class Dumper(ABC):
7+
""" Abstract base class for all dumpers """
8+
9+
def dump(self, element: YAMLRoot, to_file: str, **_) -> None:
10+
"""
11+
Write element to to_file
12+
:param element: LinkML object to be dumped
13+
:param to_file: file to dump to
14+
:@param _: method specific arguments
15+
"""
16+
with open(to_file, 'w') as output_file:
17+
output_file.write(self.dumps(element, **_))
18+
19+
@abstractmethod
20+
def dumps(self, element: YAMLRoot, **_) -> str:
21+
"""
22+
Convert element to a string
23+
@param element: YAMLRoot object to be rendered
24+
@param _: method specific arguments
25+
@return: stringified representation of element
26+
"""
27+
raise NotImplementedError()

linkml_runtime/dumpers/json_dumper.py

+41-37
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,51 @@
1+
import json
12
from typing import Dict
23

4+
from linkml_runtime.dumpers.dumper_root import Dumper
35
from linkml_runtime.utils.context_utils import CONTEXTS_PARAM_TYPE
46
from linkml_runtime.utils.yamlutils import YAMLRoot, as_json_object
5-
from jsonasobj import as_json
67

78

8-
def remove_empty_items(obj: Dict) -> Dict:
9-
"""
10-
Remove empty items from obj
11-
:param obj:
12-
:return: copy of dictionary with empty lists/dicts and Nones removed
13-
"""
14-
return {k: v for k, v in obj.items() if not (v is None or v == [] or v == {})}
9+
class JSONDumper(Dumper):
1510

11+
def dump(self, element: YAMLRoot, to_file: str, contexts: CONTEXTS_PARAM_TYPE = None) -> None:
12+
"""
13+
Write element as json to to_file
14+
:param element: LinkML object to be serialized as YAML
15+
:param to_file: file to write to
16+
:param contexts: JSON-LD context(s) in the form of:
17+
* file name
18+
* URL
19+
* JSON String
20+
* dict
21+
* JSON Object
22+
* A list containing elements of any type named above
23+
"""
24+
super().dump(element, to_file, contexts=contexts)
1625

17-
def dump(element: YAMLRoot, to_file: str, contexts: CONTEXTS_PARAM_TYPE = None) -> None:
18-
"""
19-
Write element as json to to_file
20-
:param element: LinkML object to be serialized as YAML
21-
:param to_file: file to write to
22-
:param contexts: JSON-LD context(s) in the form of:
23-
* file name
24-
* URL
25-
* JSON String
26-
* dict
27-
* JSON Object
28-
* A list containing elements of any type named above
29-
"""
30-
with open(to_file, 'w') as outf:
31-
outf.write(dumps(element, contexts))
26+
def dumps(self, element: YAMLRoot, contexts: CONTEXTS_PARAM_TYPE = None) -> str:
27+
"""
28+
Return element as a JSON or a JSON-LD string
29+
:param element: LinkML object to be emitted
30+
:param contexts: JSON-LD context(s) in the form of:
31+
* file name
32+
* URL
33+
* JSON String
34+
* dict
35+
* JSON Object
36+
* A list containing elements of any type named above
37+
:return: JSON Object representing the element
38+
"""
39+
return json.dumps(as_json_object(element, contexts),
40+
default=lambda o: self.remove_empty_items(o) if isinstance(o, YAMLRoot) else json.JSONDecoder().decode(o),
41+
indent=' ')
3242

3343

34-
def dumps(element: YAMLRoot, contexts: CONTEXTS_PARAM_TYPE = None) -> str:
35-
"""
36-
Return element as a JSON or a JSON-LD string
37-
:param element: LinkML object to be emitted
38-
:param contexts: JSON-LD context(s) in the form of:
39-
* file name
40-
* URL
41-
* JSON String
42-
* dict
43-
* JSON Object
44-
* A list containing elements of any type named above
45-
:return: JSON Object representing the element
46-
"""
47-
return as_json(as_json_object(element, contexts), filtr=remove_empty_items, indent=' ')
44+
@staticmethod
45+
def remove_empty_items(obj: Dict) -> Dict:
46+
"""
47+
Remove empty items from obj
48+
:param obj:
49+
:return: copy of dictionary with empty lists/dicts and Nones removed
50+
"""
51+
return {k: v for k, v in obj.__dict__.items() if not (v is None or v == [] or v == {})}

0 commit comments

Comments
 (0)