Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hsolbrig committed Apr 22, 2021
1 parent 48c59a0 commit 7e2716b
Show file tree
Hide file tree
Showing 93 changed files with 1,168 additions and 1,110 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/main.yaml
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
27 changes: 27 additions & 0 deletions .github/workflows/pr-test.yaml
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
34 changes: 34 additions & 0 deletions .github/workflows/pypi-publish.yaml
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 }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ tests/test_config.ini

# Don't lock
Pipfile.lock

# No Pycharm
.idea/
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Harold Solbrig <[email protected]>
hsolbrig <[email protected]>
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CHANGES
=======

* Remove YAMLRoot dependency on JsonObj
* Checkpoint
* checkpoint
* Initial commit
19 changes: 19 additions & 0 deletions Pipfile
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 = "*"
3 changes: 3 additions & 0 deletions checkout_outputs.sh
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`
1 change: 1 addition & 0 deletions db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker image build . -t context_server
1 change: 1 addition & 0 deletions dr.sh
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
1 change: 1 addition & 0 deletions ds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker stop context_server
3 changes: 3 additions & 0 deletions hide_test_changes.sh
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`
10 changes: 0 additions & 10 deletions linkml_model/__init__.py

This file was deleted.

7 changes: 7 additions & 0 deletions linkml_runtime/dumpers/__init__.py
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()
27 changes: 27 additions & 0 deletions linkml_runtime/dumpers/dumper_root.py
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()
78 changes: 41 additions & 37 deletions linkml_runtime/dumpers/json_dumper.py
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 == {})}
Loading

0 comments on commit 7e2716b

Please sign in to comment.