diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index 97df165..383e214 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -13,9 +13,18 @@ name: Continuous Integration on: push: - branches: [ main, develop ] + branches: + - main + - develop + - support-* pull_request: - branches: [ main, develop ] + branches: + - main + - develop + - support-* + release: + types: + - published jobs: build: @@ -23,14 +32,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ '3.7', '3.10' ] + python-version: + - '3.8' + - '3.10' steps: - uses: actions/checkout@v2 - - uses: actions/setup-java@v2 + - uses: actions/setup-java@v3 with: - distribution: 'adopt' - java-version: '8' + distribution: 'temurin' + java-version: '11' - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: @@ -43,7 +54,7 @@ jobs: run: make clean - name: Run tests run: make PYTHON3=python check - + # Build the binary wheel as well as the source tar - name: Build Objects run: | @@ -65,5 +76,5 @@ jobs: # If this commit is the result of a Git tag, push the wheel and tar packages # to the PyPi registry - name: Publish to PyPI - if: startsWith(github.ref, 'refs/tags') + if: github.event_name == 'release' && github.event.action == 'published' run: twine upload --repository-url https://upload.pypi.org/legacy/ -u __token__ -p ${{ secrets.PYPI_API_TOKEN }} --skip-existing --verbose dist/* diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8bf5f39..033942d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.12.0 hooks: - id: black diff --git a/case_utils/__init__.py b/case_utils/__init__.py index e8bc7ac..b2eab35 100644 --- a/case_utils/__init__.py +++ b/case_utils/__init__.py @@ -11,6 +11,6 @@ # # We would appreciate acknowledgement if the software is used. -__version__ = "0.5.0" +__version__ = "0.5.1" from . import local_uuid diff --git a/case_utils/case_file/__init__.py b/case_utils/case_file/__init__.py index 61e2bb7..9dfccbd 100644 --- a/case_utils/case_file/__init__.py +++ b/case_utils/case_file/__init__.py @@ -32,6 +32,7 @@ DEFAULT_PREFIX = "http://example.org/kb/" + # Shortcut syntax for defining an immutable named tuple is noted here: # https://docs.python.org/3/library/typing.html#typing.NamedTuple # via the "See also" box here: https://docs.python.org/3/library/collections.html#collections.namedtuple diff --git a/case_utils/case_sparql_construct/__init__.py b/case_utils/case_sparql_construct/__init__.py index 88c5877..723cfd4 100644 --- a/case_utils/case_sparql_construct/__init__.py +++ b/case_utils/case_sparql_construct/__init__.py @@ -96,7 +96,7 @@ def main() -> None: construct_query_result = in_graph.query(construct_query_object) _logger.debug("type(construct_query_result) = %r." % type(construct_query_result)) _logger.debug("len(construct_query_result) = %d." % len(construct_query_result)) - for (row_no, row) in enumerate(construct_query_result): + for row_no, row in enumerate(construct_query_result): if row_no == 0: _logger.debug("row[0] = %r." % (row,)) out_graph.add(row) diff --git a/case_utils/case_sparql_select/__init__.py b/case_utils/case_sparql_select/__init__.py index fcb58a0..fab92a2 100644 --- a/case_utils/case_sparql_select/__init__.py +++ b/case_utils/case_sparql_select/__init__.py @@ -109,10 +109,10 @@ def main() -> None: select_query_object = rdflib.plugins.sparql.prepareQuery( select_query_text, initNs=nsdict ) - for (row_no, row) in enumerate(graph.query(select_query_object)): + for row_no, row in enumerate(graph.query(select_query_object)): tally = row_no + 1 record = [] - for (column_no, column) in enumerate(row): + for column_no, column in enumerate(row): if column is None: column_value = "" elif ( diff --git a/case_utils/local_uuid.py b/case_utils/local_uuid.py index dd1e6cb..8041343 100644 --- a/case_utils/local_uuid.py +++ b/case_utils/local_uuid.py @@ -32,9 +32,25 @@ _logger = logging.getLogger(pathlib.Path(__file__).name) +def _is_relative_to(p1: pathlib.Path, p2: pathlib.Path) -> bool: + """ + This function provides pathlib.is_relative_to to Pythons before 3.9. After the End of Life of Python 3.8, this function can be removed. + """ + if sys.version_info < (3, 9): + try: + _ = p1.relative_to(p2) + return True + except ValueError: + return False + else: + return p1.is_relative_to(p2) + + def configure() -> None: global DEMO_UUID_BASE + # _logger.debug("sys.argv = %r.", sys.argv) + if os.getenv("DEMO_UUID_REQUESTING_NONRANDOM") == "NONRANDOM_REQUESTED": warnings.warn( "Environment variable DEMO_UUID_REQUESTING_NONRANDOM is deprecated. See case_utils.local_uuid.demo_uuid for usage notes on its replacement, CASE_DEMO_NONRANDOM_UUID_BASE. Proceeding with random UUIDs.", @@ -82,18 +98,23 @@ def configure() -> None: demo_uuid_base_parts.append(sys.argv[0]) else: command_original_path = pathlib.Path(sys.argv[0]) + # _logger.debug("command_original_path = %r.", command_original_path) command_resolved_path = command_original_path.resolve() + # _logger.debug("command_resolved_path = %r.", command_resolved_path) + + # The command could be a command embedded in a virtual + # environment, or it could be a script external to any virtual + # environment. venv_original_path = pathlib.Path(env_venv_name) venv_resolved_path = venv_original_path.resolve() - try: + if _is_relative_to(command_resolved_path, venv_resolved_path): command_relative_path = command_resolved_path.relative_to( venv_resolved_path ) # _logger.debug("command_relative_path = %r.", command_relative_path) demo_uuid_base_parts.append(str(command_relative_path)) - except ValueError: - # _logger.debug("Command path is not relative to virtual environment path.") - demo_uuid_base_parts.append(str(command_resolved_path)) + else: + demo_uuid_base_parts.append(str(command_original_path)) if len(sys.argv) > 1: # Component: Arguments of argument vector. diff --git a/setup.cfg b/setup.cfg index d8a7051..3431a5e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,11 +21,11 @@ include_package_data = true install_requires = pandas pyshacl - rdflib >= 6.0.2 + rdflib >= 6.0.2, < 6.3.0 requests tabulate packages = find: -python_requires = >=3.7 +python_requires = >=3.8 [options.entry_points] console_scripts = diff --git a/tests/Makefile b/tests/Makefile index b75a75a..ab1d2b6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -22,6 +22,7 @@ all: \ .PHONY: \ all-case_utils \ + all-lib \ check-case_utils \ check-isomorphic_diff \ check-mypy \ @@ -53,10 +54,15 @@ all: \ touch $@ all-case_utils: \ - .venv.done.log + .venv.done.log \ + all-lib $(MAKE) \ --directory case_utils +all-lib: + $(MAKE) \ + --directory lib + # These check calls are provided in preferred run-order. check: \ check-mypy \ @@ -68,7 +74,8 @@ check: \ --log-level=DEBUG check-case_utils: \ - .venv.done.log + .venv.done.log \ + all-lib $(MAKE) \ --directory case_utils \ check diff --git a/tests/case_utils/case_file/Makefile b/tests/case_utils/case_file/Makefile index 0ce744a..a561325 100644 --- a/tests/case_utils/case_file/Makefile +++ b/tests/case_utils/case_file/Makefile @@ -17,9 +17,7 @@ top_srcdir := $(shell cd ../../.. ; pwd) tests_srcdir := $(top_srcdir)/tests -case_srcdir := $(top_srcdir)/dependencies/CASE - -RDF_TOOLKIT_JAR := $(case_srcdir)/lib/rdf-toolkit.jar +RDF_TOOLKIT_JAR := $(tests_srcdir)/lib/rdf-toolkit.jar all: \ kb.json \ diff --git a/tests/case_utils/case_validate/case_test_examples/Makefile b/tests/case_utils/case_validate/case_test_examples/Makefile index 913bd3a..8dbfe44 100644 --- a/tests/case_utils/case_validate/case_test_examples/Makefile +++ b/tests/case_utils/case_validate/case_test_examples/Makefile @@ -15,13 +15,11 @@ SHELL := /bin/bash top_srcdir := $(shell cd ../../../.. ; pwd) -case_srcdir := $(top_srcdir)/dependencies/CASE - -examples_srcdir := $(case_srcdir)/tests/examples +examples_srcdir := $(top_srcdir)/dependencies/CASE/tests/examples tests_srcdir := $(top_srcdir)/tests -RDF_TOOLKIT_JAR := $(case_srcdir)/lib/rdf-toolkit.jar +RDF_TOOLKIT_JAR := $(tests_srcdir)/lib/rdf-toolkit.jar all: \ investigative_action_PASS_validation.ttl \ diff --git a/tests/case_utils/case_validate/cli/Makefile b/tests/case_utils/case_validate/cli/Makefile index f61d421..5cfaeef 100644 --- a/tests/case_utils/case_validate/cli/Makefile +++ b/tests/case_utils/case_validate/cli/Makefile @@ -21,7 +21,7 @@ examples_srcdir := $(case_srcdir)/tests/examples tests_srcdir := $(top_srcdir)/tests -RDF_TOOLKIT_JAR := $(case_srcdir)/lib/rdf-toolkit.jar +RDF_TOOLKIT_JAR := $(tests_srcdir)/lib/rdf-toolkit.jar files_to_generate := \ format_human_output_jsonld.jsonld \ diff --git a/tests/case_utils/case_validate/uco_test_examples/Makefile b/tests/case_utils/case_validate/uco_test_examples/Makefile index 08fa853..04a6dc3 100644 --- a/tests/case_utils/case_validate/uco_test_examples/Makefile +++ b/tests/case_utils/case_validate/uco_test_examples/Makefile @@ -15,15 +15,11 @@ SHELL := /bin/bash top_srcdir := $(shell cd ../../../.. ; pwd) -case_srcdir := $(top_srcdir)/dependencies/CASE - -uco_srcdir := $(case_srcdir)/dependencies/UCO - -examples_srcdir := $(uco_srcdir)/tests/examples +examples_srcdir := $(top_srcdir)/dependencies/CASE/dependencies/UCO/tests/examples tests_srcdir := $(top_srcdir)/tests -RDF_TOOLKIT_JAR := $(case_srcdir)/lib/rdf-toolkit.jar +RDF_TOOLKIT_JAR := $(tests_srcdir)/lib/rdf-toolkit.jar all: \ action_inheritance_PASS_validation.ttl \ diff --git a/tests/lib/.gitignore b/tests/lib/.gitignore new file mode 100644 index 0000000..d392f0e --- /dev/null +++ b/tests/lib/.gitignore @@ -0,0 +1 @@ +*.jar diff --git a/tests/lib/Makefile b/tests/lib/Makefile new file mode 100644 index 0000000..75c4342 --- /dev/null +++ b/tests/lib/Makefile @@ -0,0 +1,38 @@ +#!/usr/bin/make -f + +# Portions of this file contributed by NIST are governed by the +# following statement: +# +# This software was developed at the National Institute of Standards +# and Technology by employees of the Federal Government in the course +# of their official duties. Pursuant to Title 17 Section 105 of the +# United States Code, this software is not subject to copyright +# protection within the United States. NIST assumes no responsibility +# whatsoever for its use by other parties, and makes no guarantees, +# expressed or implied, about its quality, reliability, or any other +# characteristic. +# +# We would appreciate acknowledgement if the software is used. + +# This Makefile is incorporated to support versions of case-utils since +# 0.5.0 that had not yet incorporated rdf-toolkit-1.11.0.jar into their +# testing process. The Makefile is adapted from the `/lib` directory of +# UCO at version 1.2.0. + +SHELL := /bin/bash + +all: \ + rdf-toolkit.jar + +rdf-toolkit.jar: + test -r rdf-toolkit.jar.sha512 + rm -f $@_ + # Try retrieval from files.caseontology.org. + wget \ + --output-document $@_ \ + https://files.caseontology.org/rdf-toolkit-1.11.0.jar + test \ + "x$$(openssl dgst -sha512 $@_ | awk '{print($$NF)}')" \ + == \ + "x$$(head -n1 rdf-toolkit.jar.sha512)" + mv $@_ $@ diff --git a/tests/lib/rdf-toolkit.jar.sha512 b/tests/lib/rdf-toolkit.jar.sha512 new file mode 100644 index 0000000..39fbb64 --- /dev/null +++ b/tests/lib/rdf-toolkit.jar.sha512 @@ -0,0 +1 @@ +8131e5515da63f099a89a3ce2c7587fb6b228f1ec7c5eb49ff35710509e8511921bfc847e182ee994e575b1f7895c04ae5bed7e1b7826bb32c9475b43b74dc17