-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switches to using a python package that can be published to PyPi
- Loading branch information
Showing
9 changed files
with
187 additions
and
62 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,36 @@ | ||
--- | ||
name: Upload Python Package | ||
on: | ||
- push | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
- name: Build package | ||
run: python -m build | ||
|
||
- name: Publish distribution to Test PyPI | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | ||
repository_url: https://test.pypi.org/legacy/ | ||
skip_existing: true | ||
|
||
- name: Publish distribution to PyPI | ||
if: startsWith(github.ref, 'refs/tags') | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
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,35 @@ | ||
--- | ||
name: Test shacl2code | ||
on: | ||
- push | ||
- pull_request | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
- "3.12" | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
- name: Build package | ||
run: | | ||
python -m build | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: psf/black@stable |
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,4 @@ | ||
# Convert SHACL Model to code bindings | ||
|
||
This tool can be used to convert a JSONLD SHACL model into various code | ||
bindings |
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,37 @@ | ||
[project] | ||
name = "shacl2code" | ||
description = "Convert SHACL model file to code bindings" | ||
version = "0.0.1" | ||
dependencies = [ | ||
"jinja2 >= 3.1.2", | ||
"pyld >= 2.0.3", | ||
] | ||
required-python = ">= 3.8" | ||
authors = [ | ||
{name = "Joshua Watt", email = "[email protected]"}, | ||
] | ||
readme = "README.md" | ||
classifiers = [ | ||
"Development Status :: 4 - Beta", | ||
"Intended Audience :: Developers", | ||
"Topic :: Software Development :: Build Tools", | ||
"License :: OSI Approved :: MIT License", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.9", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
] | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/JPEWdev/shacl2code" | ||
Repository = "https://github.com/JPEWdev/shacl2code.git" | ||
Issues = "https://github.com/JPEWdev/shacl2code/issues" | ||
|
||
[project.scripts] | ||
shacl2code = "shacl2code:main" | ||
|
||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" |
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 @@ | ||
from .model import Model | ||
from .main import main |
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,5 @@ | ||
from pathlib import Path | ||
|
||
THIS_FILE = Path(__file__) | ||
THIS_DIR = THIS_FILE.parent | ||
TEMPLATE_DIR = THIS_DIR / "templates" |
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,66 @@ | ||
#! /usr/bin/env python3 | ||
# | ||
# Copyright (c) 2024 Joshua Watt | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import argparse | ||
import json | ||
import sys | ||
import urllib.request | ||
from pathlib import Path | ||
|
||
from . import Model | ||
from .const import TEMPLATE_DIR | ||
|
||
|
||
def get_langs(): | ||
langs = [] | ||
for child in TEMPLATE_DIR.iterdir(): | ||
if child.suffixes and child.suffixes[-1] == ".j2": | ||
langs.append(child.stem) | ||
return langs | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Convert JSON-LD model to python") | ||
parser.add_argument( | ||
"--lang", | ||
help="Output Language", | ||
choices=get_langs(), | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"input", | ||
help="Input JSON-LD model (path, URL, or '-')", | ||
) | ||
parser.add_argument( | ||
"output", | ||
help="Output file name or '-' for stdout", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
if "://" in args.input: | ||
with urllib.request.urlopen(args.input) as url: | ||
model_data = json.load(url) | ||
elif args.input == "-": | ||
model_data = json.load(sys.stdin) | ||
else: | ||
with Path(args.input).open("r") as f: | ||
model_data = json.load(f) | ||
|
||
m = Model(model_data) | ||
render = m.render_template(args.lang) | ||
|
||
if args.output == "-": | ||
print(render) | ||
else: | ||
with Path(args.output).open("w") as f: | ||
f.write(render) | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
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
File renamed without changes.