Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .github/actions/build/action.yml

This file was deleted.

11 changes: 9 additions & 2 deletions .github/actions/prepare_env/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ runs:
shell: bash
run: |
python -m pip install --upgrade pip
pip install flake8 pytest pip-tools
pip install flake8 pytest pytest-cov pip-tools
if [ -f pyproject.toml ]; then python -m piptools compile -o requirements.txt pyproject.toml; fi
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -e .
pip install -e .
- name: Lint with flake8
shell: bash
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
5 changes: 2 additions & 3 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: tests action
description: run tests against compiled package

runs:
using: composite
steps:
- name: Test output files in typical scenarios
- name: Run full test suite
shell: bash
run: |
python tests/syntax_semantic_check.py
python -m pytest --junitxml=junit/test-results.xml --cov=src/si_ref_point --cov-report=xml --cov-report=html
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches: [ "enable_ci_pipeline" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
workflow_call:

permissions:
Expand All @@ -18,5 +19,4 @@ jobs:
steps:
- uses: actions/checkout@v6
- uses: ./.github/actions/prepare_env
- uses: ./.github/actions/build
- uses: ./.github/actions/test
- uses: ./.github/actions/test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ JSONLD/
Testing/Vocabulary/Vocabulary.txt
*.zip

# related to tests
.coverage
.pytest_cache/
coverage.xml
junit/
htmlcov/

# cache files
__pycache__
Expand Down
2 changes: 1 addition & 1 deletion src/si_ref_point/aboxes/rb_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def meetings_sort_key(item):
return float(re.findall("[0-9]+[\-0-9]*", os.path.basename(item))[0].replace("-", "."))
return float(re.findall("[0-9]+[-0-9]*", os.path.basename(item))[0].replace("-", "."))


class MeetingsFileExtractor:
Expand Down
104 changes: 55 additions & 49 deletions src/si_ref_point/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@
from zipfile import ZipFile
from rdflib import Graph

file_generator = {
'si': cuq_tbox.main,
'units': units_abox.main,
'quantities': quantities_abox.main,
'constants': constants_abox.main,
'prefixes': prefixes_abox.main,
'decisions': decisions_abox.main,
'bodies': rb_tbox.main,
'cgpm': rb_abox_cgpm.main,
'cipm': rb_abox_cipm.main,
'cctf': rb_abox_cctf.main,
}

def get_parser():
""" Dedicated function to collect command line parameters, so it can
Expand Down Expand Up @@ -63,39 +75,54 @@ def get_parser():
return parser


def main(force_output_dir_to=None):
args = get_parser().parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)

file_generator = {
'si': cuq_tbox.main,
'units': units_abox.main,
'quantities': quantities_abox.main,
'constants': constants_abox.main,
'prefixes': prefixes_abox.main,
'decisions': decisions_abox.main,
'bodies': rb_tbox.main,
'cgpm': rb_abox_cgpm.main,
'cipm': rb_abox_cipm.main,
'cctf': rb_abox_cctf.main,
}
def load_graphs(only_this=None):
output = {}
for label, generator in file_generator.items():
if args.only and args.only not in label:
if only_this and only_this not in label:
continue
logging.info(f"generating {label} graph")
# Generator will return a rdflib.Graph object
output[label] = generator()
logging.info("..done")
return output

if force_output_dir_to:
ttl_dir = jsonld_dir = force_output_dir_to
def generate_hash_file(tgtfile: Path):
""" generate hash for file and write it next to it, with a different ext
"""
h = hashlib.new('sha256')
with open(tgtfile, encoding="UTF8") as fp:
h.update(fp.read().encode())
hashstr = h.hexdigest()
hashdest = tgtfile.with_suffix('.sha256')
with open(hashdest, 'w') as fp:
fp.write(hashstr)

def serialize_graphs(graphs={}, fmt="ttl", ext="ttl", tgtdir: Path=None,
generate_hash=False):
if not tgtdir.exists():
os.makedirs(tgtdir)
for label, g in graphs.items():
tgtfile = tgtdir / (label + '.' + ext)
g.serialize(format=fmt, destination=tgtfile)
if generate_hash:
generate_hash_file(tgtfile)

def non_interactive(ttl_path):
output = load_graphs()
serialize_graphs(graphs=output, fmt="ttl", ext="ttl", tgtdir=ttl_path)


def main():
args = get_parser().parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG)
else:
ttl_dir = args.output_dir / args.ttl_output_subdir
jsonld_dir = args.output_dir / args.jsonld_output_subdir
logging.basicConfig(level=logging.INFO)

output = load_graphs(only_this=args.only)

ttl_dir = args.output_dir / args.ttl_output_subdir
jsonld_dir = args.output_dir / args.jsonld_output_subdir

serializations = [{"fmt": "ttl",
"dir": ttl_dir,
Expand All @@ -106,20 +133,8 @@ def main(force_output_dir_to=None):

# Serialize all graphs in their respective output files
for srl in serializations:
if not os.path.exists(srl['dir']):
os.makedirs(srl['dir'])
for label, graph in output.items():
filedest = os.path.join(srl['dir'], label + '.' + srl['ext'])
graph.serialize(format=srl['fmt'], destination=filedest)

# generate hash for file and write it alongside
h = hashlib.new('sha256')
with open(filedest, encoding="UTF8") as fp:
h.update(fp.read().encode())
hashstr = h.hexdigest()
hashdest = os.path.join(srl['dir'], label + '.sha256')
with open(hashdest, 'w') as fp:
fp.write(hashstr)
serialize_graphs(graphs=output, fmt=srl['fmt'], ext=srl['ext'],
tgtdir=srl['dir'], generate_hash=True)

# Generate full graphs outputs
# Just merging graphs in memory could lead to blank-nodes collisions, so
Expand All @@ -131,20 +146,11 @@ def main(force_output_dir_to=None):
for ttl_file in file_generator.keys():
full_graph.parse(ttl_dir / (ttl_file + ".ttl"))
for srl in serializations:
filedest = os.path.join(srl['dir'], 'sirp_full.' + srl['ext'])
filedest = Path(srl['dir']) / ('sirp_full.' + srl['ext'])
full_graph.serialize(format=srl['fmt'], destination=filedest)
# generate hash for file and write it alongside
h = hashlib.new('sha256')
with open(filedest, encoding="UTF8") as fp:
h.update(fp.read().encode())
hashstr = h.hexdigest()
hashdest = os.path.join(srl['dir'], 'sirp_full.sha256')
with open(hashdest, 'w') as fp:
fp.write(hashstr)
generate_hash_file(filedest)
logging.info("..done")



logging.info(f"TTL and JSON-LD files written to ./{ttl_dir}/ and ./{jsonld_dir}/, respectively")
if args.generate_RDF:
output['si'].serialize(
Expand Down
Empty file added tests/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest
from pathlib import Path
from si_ref_point import main as sirpmain

@pytest.fixture(scope="session")
def TTLpath():
testrootdir = Path(__file__).parent
ttlpath = testrootdir / 'TTL'
sirpmain.non_interactive(ttlpath)
return ttlpath
138 changes: 0 additions & 138 deletions tests/reasoning/reasoner.py

This file was deleted.

Loading