Skip to content

Commit

Permalink
Move virtual environment construction to root directory
Browse files Browse the repository at this point in the history
The Protege catalog XML construction design involves review of the
transitive `owl:imports` closure of UCO's graph files.  To do this,
RDFLib needs to be available in a Python virtual environment before
descending into the `/ontology` directory.  Before this patch, a virtual
environment with RDFLib was constructed in `/tests` for testing, but not
for other ontology-related maintenance.

This patch moves the virtual environment construction to the UCO
repository root directory, and sets the dependency order of `all` and
`check` to include `/venv` being built before descent into `/ontology`
and `/tests.  All paths referencing `/tests/venv` under `/tests` have
been updated.

As one bit of code upgrading, the `PYTHON3` selector snippet, originally
written before Python 3.10's release, now looks only for the default
Python 3 if not supplied when calling Make (e.g. with
`make PYTHON3=python3.11 check`).

This patch isolates its effects to moving the virtual environment.
A follow-on patch will integrate catalog construction using the new
placement.

References:
* #449

Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
  • Loading branch information
ajnelson-nist committed Mar 15, 2023
1 parent f44e360 commit 66d0c38
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.*.ttl
.git_submodule_init.done.log
.lib.done.log
.venv.done.log
_*
venv
45 changes: 42 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

SHELL := /bin/bash

PYTHON3 ?= $(shell which python3)

all: \
.lib.done.log
$(MAKE) \
Expand Down Expand Up @@ -44,9 +46,31 @@ all: \
--directory lib
touch $@

# The two CASE-Utility... files are to trigger rebuilds based on command-line interface changes or version increments.
.venv.done.log: \
dependencies/CASE-Utility-SHACL-Inheritance-Reviewer/case_shacl_inheritance_reviewer/__init__.py \
dependencies/CASE-Utility-SHACL-Inheritance-Reviewer/setup.cfg \
requirements.txt
rm -rf venv
$(PYTHON3) -m venv \
venv
source venv/bin/activate \
&& pip install \
--upgrade \
pip \
setuptools \
wheel
source venv/bin/activate \
&& pip install \
dependencies/CASE-Utility-SHACL-Inheritance-Reviewer
source venv/bin/activate \
&& pip install \
--requirement requirements.txt
touch $@

check: \
.git_submodule_init.done.log \
.lib.done.log
.lib.done.log \
.venv.done.log
$(MAKE) \
--directory ontology \
check
Expand All @@ -59,7 +83,10 @@ clean: \
clean-ontology
@rm -f \
.git_submodule_init.done.log \
.lib.done.log
.lib.done.log \
.venv.done.log
@rm -rf \
venv

clean-ontology:
@$(MAKE) \
Expand All @@ -70,3 +97,15 @@ clean-tests:
@$(MAKE) \
--directory tests \
clean

# Maintain timestamp order.
dependencies/CASE-Utility-SHACL-Inheritance-Reviewer/case_shacl_inheritance_reviewer/__init__.py: \
.git_submodule_init.done.log
touch -c $@
test -r $@

# Maintain timestamp order.
dependencies/CASE-Utility-SHACL-Inheritance-Reviewer/setup.cfg: \
.git_submodule_init.done.log
touch -c $@
test -r $@
5 changes: 2 additions & 3 deletions ontology/uco/master/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ top_srcdir := $(shell cd ../../.. ; pwd)
all: \
catalog-v001.xml

# TODO - Move virtual environment creation up to root directory and re-order top_srcdir's descent.
catalog-v001.xml: \
$(top_srcdir)/src/create-catalog-v001.xml.py \
$(top_srcdir)/tests/.venv.done.log
$(top_srcdir)/.venv.done.log
rm -f _$@
source $(top_srcdir)/tests/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& python3 $(top_srcdir)/src/create-catalog-v001.xml.py \
_$@ \
domain_directories.tsv \
Expand Down
File renamed without changes.
3 changes: 0 additions & 3 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.shapes.done.log
.venv.done.log
_*
inheritance_review.ttl
uco_monolithic.ttl
venv
49 changes: 11 additions & 38 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ SHELL := /bin/bash

top_srcdir := $(shell cd .. ; pwd)

PYTHON3 ?= $(shell which python3.9 2>/dev/null || which python3.8 2>/dev/null || which python3.7 2>/dev/null || which python3.6 2>/dev/null || which python3)

uco_turtle_files := $(shell /bin/ls $(top_srcdir)/ontology/*/*.ttl $(top_srcdir)/ontology/*/*/*.ttl)

imported_ontology_files := \
Expand All @@ -31,42 +29,19 @@ all:
# Ensure the UCO-internal shapes pass their own tests.
.shapes.done.log: \
$(top_srcdir)/ontology/owl/owl.ttl \
.venv.done.log \
$(top_srcdir)/.venv.done.log \
shapes/uco-closure-qc.ttl \
shapes/uco-qc.ttl
$(MAKE) \
--directory shapes \
check
touch $@

# The two CASE-Utility... files are to trigger rebuilds based on command-line interface changes or version increments.
.venv.done.log: \
$(top_srcdir)/.git_submodule_init.done.log \
$(top_srcdir)/dependencies/CASE-Utility-SHACL-Inheritance-Reviewer/case_shacl_inheritance_reviewer/__init__.py \
$(top_srcdir)/dependencies/CASE-Utility-SHACL-Inheritance-Reviewer/setup.cfg \
requirements.txt
rm -rf venv
$(PYTHON3) -m venv \
venv
source venv/bin/activate \
&& pip install \
--upgrade \
pip \
setuptools \
wheel
source venv/bin/activate \
&& pip install \
$(top_srcdir)/dependencies/CASE-Utility-SHACL-Inheritance-Reviewer
source venv/bin/activate \
&& pip install \
--requirement requirements.txt
touch $@

check: \
check-dependencies \
inheritance_review.ttl \
uco_monolithic.ttl
source venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pytest \
--ignore examples \
--ignore shapes \
Expand All @@ -76,7 +51,7 @@ check: \
check

check-dependencies: \
.venv.done.log
$(top_srcdir)/.venv.done.log
$(MAKE) \
--directory dependencies \
check
Expand All @@ -91,14 +66,12 @@ clean:
@rm -f \
.*.done.log \
uco_monolithic.ttl
@rm -rf \
venv

inheritance_review.ttl: \
$(uco_turtle_files) \
.venv.done.log
$(top_srcdir)/.venv.done.log
rm -f _$@
source venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& case_shacl_inheritance_reviewer \
--strict \
_$@ \
Expand All @@ -112,19 +85,19 @@ uco_monolithic.ttl: \
$(uco_turtle_files) \
.shapes.done.log \
thing.ttl
source venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& rdfpipe \
--input-format ttl \
--output-format ttl \
$(uco_turtle_files) \
> __$@
# Review UCO closure for versioning consistency.
source venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& rdfpipe \
__$@ \
$(imported_ontology_files) \
> ___$@
source venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--data-file-format turtle \
--format turtle \
Expand All @@ -133,7 +106,7 @@ uco_monolithic.ttl: \
--shacl-file-format turtle \
___$@
# Review UCO closure with SHACL-SHACL.
source venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--data-file-format turtle \
--format turtle \
Expand All @@ -145,7 +118,7 @@ uco_monolithic.ttl: \
# Closure tests have passed; remove closure file.
rm ___$@
# Review UCO for practice conformance.
source venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--data-file-format turtle \
--format turtle \
Expand All @@ -154,7 +127,7 @@ uco_monolithic.ttl: \
--shacl-file-format turtle \
__$@
# Review UCO for OWL 2 DL conformance.
source venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--data-file-format turtle \
--format turtle \
Expand Down
10 changes: 4 additions & 6 deletions tests/dependencies/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ SHELL := /bin/bash

top_srcdir := $(shell cd ../.. ; pwd)

tests_srcdir := $(top_srcdir)/tests

all:

check: \
Expand All @@ -29,10 +27,10 @@ clean:

uco-owl-co.done.log: \
$(top_srcdir)/dependencies/collections-ontology/collections.owl \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/.venv.done.log \
$(top_srcdir)/ontology/owl/owl.ttl
# Review for OWL 2 DL conformance.
source $(tests_srcdir)/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--data-file-format xml \
--format turtle \
Expand All @@ -45,10 +43,10 @@ uco-owl-co.done.log: \

uco-owl-error.done.log: \
$(top_srcdir)/dependencies/error/docs/current/error.ttl \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/.venv.done.log \
$(top_srcdir)/ontology/owl/owl.ttl
# Review for OWL 2 DL conformance.
source $(tests_srcdir)/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--data-file-format turtle \
--format turtle \
Expand Down
6 changes: 3 additions & 3 deletions tests/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ all: \
# characteristics.
%_validation.ttl: \
%.json \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/.venv.done.log \
$(tests_srcdir)/uco_monolithic.ttl
source $(tests_srcdir)/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--allow-warnings \
--data-file-format json-ld \
Expand Down Expand Up @@ -116,7 +116,7 @@ check: \
thread_PASS_validation.ttl \
thread_XFAIL_validation.ttl \
uco_thing_XFAIL_validation.ttl
source $(tests_srcdir)/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pytest \
--log-level=DEBUG

Expand Down
8 changes: 3 additions & 5 deletions tests/shapes/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ SHELL := /bin/bash

top_srcdir := $(shell cd ../.. ; pwd)

tests_srcdir := $(top_srcdir)/tests

all: \
qc_monolithic.ttl
$(MAKE) \
Expand Down Expand Up @@ -51,7 +49,7 @@ check: \
$(MAKE) \
--directory examples_uco_qc \
check
source $(tests_srcdir)/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pytest \
--log-level=DEBUG \
--verbose \
Expand All @@ -77,12 +75,12 @@ clean:
qc_monolithic.ttl

qc_monolithic.ttl: \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/.venv.done.log \
$(top_srcdir)/.lib.done.log \
uco-closure-qc.ttl \
uco-qc.ttl
rm -f __$@ _$@
source $(tests_srcdir)/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& rdfpipe \
--output-format turtle \
uco-closure-qc.ttl \
Expand Down
8 changes: 3 additions & 5 deletions tests/shapes/examples_uco_owl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ SHELL := /bin/bash

top_srcdir := $(shell cd ../../.. ; pwd)

tests_srcdir := $(top_srcdir)/tests

shapes_srcdir := $(tests_srcdir)/shapes
shapes_srcdir := $(top_srcdir)/tests/shapes

sample_ttls := $(wildcard *_PASS.ttl *_XFAIL.ttl)

Expand All @@ -37,10 +35,10 @@ all: \
# characteristics.
%_validation.ttl: \
%.ttl \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/.venv.done.log \
$(top_srcdir)/ontology/owl/owl.ttl
rm -f __$@ _$@
source $(tests_srcdir)/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--allow-warnings \
--data-file-format turtle \
Expand Down
8 changes: 3 additions & 5 deletions tests/shapes/examples_uco_qc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ SHELL := /bin/bash

top_srcdir := $(shell cd ../../.. ; pwd)

tests_srcdir := $(top_srcdir)/tests

shapes_srcdir := $(tests_srcdir)/shapes
shapes_srcdir := $(top_srcdir)/tests/shapes

sample_ttls := $(wildcard *_PASS.ttl *_XFAIL.ttl)

Expand All @@ -37,10 +35,10 @@ all: \
# characteristics.
%_validation.ttl: \
%.ttl \
$(tests_srcdir)/.venv.done.log \
$(top_srcdir)/.venv.done.log \
$(shapes_srcdir)/qc_monolithic.ttl
rm -f __$@ _$@
source $(tests_srcdir)/venv/bin/activate \
source $(top_srcdir)/venv/bin/activate \
&& pyshacl \
--allow-warnings \
--data-file-format turtle \
Expand Down

0 comments on commit 66d0c38

Please sign in to comment.