Skip to content

Commit fee2f09

Browse files
committed
Adopt case-utils 0.9.0, CASE 1.1.0, and strict static type review
This patch does not apply `pre-commit`; that will be applied in a follow-on patch. Concept typo-checking is now delegated to the `case_validate` typo-checker. This removes the CASE-Examples-QC dependency. A follow-on patch will regenerate Make-managed files. References: * casework/CASE-Utilities-Python#77 Signed-off-by: Alex Nelson <[email protected]>
1 parent 761b276 commit fee2f09

25 files changed

+98
-499
lines changed

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "dependencies/CASE-Examples-QC"]
2-
path = dependencies/CASE-Examples-QC
3-
url = https://github.com/ajnelson-nist/CASE-Examples-QC.git
41
[submodule "dependencies/CASE-Utilities-Python"]
52
path = dependencies/CASE-Utilities-Python
63
url = https://github.com/casework/CASE-Utilities-Python.git

Makefile

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ all:
2727
cd dependencies \
2828
&& git diff . \
2929
| cat
30-
git submodule init
31-
git submodule update
30+
git submodule update --init
31+
$(MAKE) \
32+
--directory dependencies/CASE-Utilities-Python \
33+
.git_submodule_init.done.log
3234
touch $@
3335

3436
check: \
35-
dependencies/CASE-Examples-QC/tests/ontology_vocabulary.txt
37+
.git_submodule_init.done.log
3638
$(MAKE) \
3739
PYTHON3=$(PYTHON3) \
3840
--directory tests \
@@ -46,39 +48,11 @@ clean:
4648
@$(MAKE) \
4749
--directory tests \
4850
clean
49-
@#A full clean here erases test files and causes unnecessary rebuilding for the purposes of testing GNU Time mapping.
5051
@rm -f \
51-
dependencies/CASE-Examples-QC/.*.done.log
52-
@test ! -d dependencies/CASE-Examples-QC/tests \
53-
|| rm -f dependencies/CASE-Examples-QC/tests/ontology_vocabulary.txt
54-
55-
dependencies/CASE-Examples-QC/tests/ontology_vocabulary.txt: \
56-
.git_submodule_init.done.log
57-
test ! -z "$(PYTHON3)" \
58-
|| (echo "ERROR:Makefile:PYTHON3 not defined" >&2 ; exit 1)
59-
$(MAKE) \
60-
PYTHON3=$(PYTHON3) \
61-
--directory dependencies/CASE-Examples-QC \
62-
.git_submodule_init.done.log \
63-
.venv.done.log
64-
$(MAKE) \
65-
PYTHON3=$(PYTHON3) \
66-
--directory dependencies/CASE-Examples-QC/tests \
67-
ontology_vocabulary.txt
68-
test -r $@
69-
70-
distclean: \
71-
clean
72-
@rm -f \
73-
.git_submodule_init.done.log \
74-
dependencies/CASE-Examples-QC/.lib.done.log \
75-
dependencies/CASE-Examples-QC/lib/rdf-toolkit.jar
76-
@$(MAKE) \
77-
--directory tests \
78-
distclean
52+
.git_submodule_init.done.log
7953

8054
download: \
81-
dependencies/CASE-Examples-QC/tests/ontology_vocabulary.txt
55+
.git_submodule_init.done.log
8256
test ! -z "$(PYTHON3)" \
8357
|| (echo "ERROR:Makefile:PYTHON3 not defined" >&2 ; exit 1)
8458
$(MAKE) \

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ This project follows [SEMVER 2.0.0](https://semver.org/) where versions are decl
4747

4848
This repository supports the CASE and UCO ontology versions that are distributed with the [CASE-Utilities-Python repository](https://github.com/casework/CASE-Utilities-Python), at its submodule-tracked state [here](dependencies/CASE-Utilities-Python). Currently, those ontology versions are:
4949

50-
* CASE 0.5.0
51-
* UCO 0.7.0
50+
* CASE 1.1.0
51+
* UCO 1.1.0
5252

5353

5454
## Repository locations
@@ -65,8 +65,7 @@ Releases and issue tracking will be handled at the [casework location](https://g
6565
Some `make` targets are defined for this repository:
6666
* `all` - No effect.
6767
* `check` - Run unit tests. *NOTE*: The tests entail downloading some software to assist with formatting and conversion, from PyPI and from a [third party](https://github.com/edmcouncil/rdf-toolkit). `make download` retrieves these files.
68-
* `clean` - Remove test build files, but not downloaded files or the `tests/venv` virtual environment.
69-
* `distclean` - Run `make clean` and further delete downloaded files and the `tests/venv` virtual environment. Neither `clean` nor `distclean` will remove downloaded submodules.
68+
* `clean` - Remove test build files, but not downloaded files or the `tests/venv` virtual environment. Will not remove downloaded submodules.
7069
* `download` - Download files sufficiently to run the unit tests offline. This will *not* include the ontology repositories tracked as submodules. Note if you do need to work offline, be aware touching the `setup.py` file in the root, or `tests/requirements.txt`, will trigger a virtual environment rebuild.
7170

7271

case_gnu_time/__init__.py

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,32 @@
2929
import rdflib.util
3030

3131
import case_utils
32+
from case_utils.namespace import NS_RDF, NS_UCO_CORE, NS_UCO_OBSERVABLE, NS_XSD
3233

3334
_logger = logging.getLogger(os.path.basename(__file__))
3435

35-
NS_RDF = rdflib.RDF
36-
NS_UCO_CORE = rdflib.Namespace("https://unifiedcyberontology.org/ontology/uco/core#")
37-
NS_UCO_OBSERVABLE = rdflib.Namespace("https://unifiedcyberontology.org/ontology/uco/observable#")
38-
NS_XSD = rdflib.namespace.XSD
3936

4037
class ProcessUCOObject(object):
41-
def __init__(self, graph, ns_base, **kwargs) -> None:
38+
def __init__(self, graph: rdflib.Graph, ns_base: rdflib.Namespace, *args: typing.Any, prefix_slug:str = "process-", **kwargs: typing.Any) -> None:
4239
"""
4340
Initializing a ProcessUCOObject will create one triple in the graph. To add data to the new node, call populate_from_gnu_time_log().
4441
"""
4542

4643
assert isinstance(graph, rdflib.Graph)
4744

4845
self.graph = graph
49-
50-
prefix_slug = kwargs.get("prefix_slug", "process-")
46+
self._ns_base = ns_base
5147

5248
# Guarantee at least one triple enters the graph.
53-
self._node = rdflib.URIRef(ns_base[prefix_slug + case_utils.local_uuid.local_uuid()])
49+
self._node = ns_base[prefix_slug + case_utils.local_uuid.local_uuid()]
5450
self.graph.add((self.node, NS_RDF.type, NS_UCO_OBSERVABLE.Process))
5551

56-
self._bnode_process: typing.Optional[rdflib.BNode] = None
52+
self._n_process_facet: typing.Optional[rdflib.URIRef] = None
5753
self._created_time: typing.Optional[str] = None
5854
self._exit_status: typing.Optional[int] = None
5955
self._exit_time: typing.Optional[str] = None
6056

61-
def populate_from_gnu_time_log(self, gnu_time_log) -> None:
57+
def populate_from_gnu_time_log(self, gnu_time_log: str) -> None:
6258
"""
6359
This method populates Process data from a GNU Time log file. If self.exit_time is not set before this method is called, it will be set by reading the modification time of gnu_time_log.
6460
"""
@@ -107,17 +103,6 @@ def populate_from_gnu_time_log(self, gnu_time_log) -> None:
107103

108104
self.created_time = created_time_datetime.isoformat()
109105

110-
@property
111-
def bnode_process(self) -> rdflib.BNode:
112-
"""
113-
Created on first access.
114-
"""
115-
if self._bnode_process is None:
116-
self._bnode_process = rdflib.BNode()
117-
self.graph.add((self._bnode_process, NS_RDF.type, NS_UCO_OBSERVABLE.ProcessFacet))
118-
self.graph.add((self.node, NS_UCO_CORE.hasFacet, self._bnode_process))
119-
return self._bnode_process
120-
121106
@property
122107
def created_time(self) -> typing.Optional[str]:
123108
return self._created_time
@@ -132,7 +117,7 @@ def created_time(self, value: str) -> None:
132117
str_value = str(value) # For e.g. datetime objects.
133118
# Confirm text is ISO-8601.
134119
check_value = dateutil.parser.isoparse(str_value)
135-
self.graph.add((self.bnode_process, NS_UCO_OBSERVABLE.observableCreatedTime, rdflib.Literal(str_value, datatype=NS_XSD.dateTime)))
120+
self.graph.add((self.n_process_facet, NS_UCO_OBSERVABLE.observableCreatedTime, rdflib.Literal(str_value, datatype=NS_XSD.dateTime)))
136121
self._created_time = value
137122

138123
@property
@@ -142,7 +127,7 @@ def exit_status(self) -> typing.Optional[int]:
142127
@exit_status.setter
143128
def exit_status(self, value: int) -> None:
144129
assert isinstance(value, int)
145-
self.graph.add((self.bnode_process, NS_UCO_OBSERVABLE.exitStatus, rdflib.Literal(value)))
130+
self.graph.add((self.n_process_facet, NS_UCO_OBSERVABLE.exitStatus, rdflib.Literal(value)))
146131

147132
@property
148133
def exit_time(self) -> typing.Optional[str]:
@@ -159,17 +144,42 @@ def exit_time(self, value: str) -> None:
159144
# Confirm text is ISO-8601.
160145
check_value = dateutil.parser.isoparse(str_value)
161146
literal_time = rdflib.Literal(str_value, datatype=NS_XSD.dateTime)
162-
self.graph.add((self.bnode_process, NS_UCO_OBSERVABLE.exitTime, literal_time))
147+
self.graph.add((self.n_process_facet, NS_UCO_OBSERVABLE.exitTime, literal_time))
163148
self._exit_time = value
164149

150+
@property
151+
def n_process_facet(self) -> rdflib.URIRef:
152+
"""
153+
Created on first access.
154+
"""
155+
if self._n_process_facet is None:
156+
self._n_process_facet = self.ns_base["process-facet-" + case_utils.local_uuid.local_uuid()]
157+
self.graph.add((self._n_process_facet, NS_RDF.type, NS_UCO_OBSERVABLE.ProcessFacet))
158+
self.graph.add((self.node, NS_UCO_CORE.hasFacet, self._n_process_facet))
159+
return self._n_process_facet
160+
165161
@property
166162
def node(self) -> rdflib.URIRef:
167163
"""
168164
Read-only property.
169165
"""
170166
return self._node
171167

172-
def build_process_object(graph, ns_base, gnu_time_log, mtime=None, prefix_slug=None) -> ProcessUCOObject:
168+
@property
169+
def ns_base(self) -> rdflib.Namespace:
170+
"""
171+
No setter.
172+
"""
173+
return self._ns_base
174+
175+
176+
def build_process_object(
177+
graph: rdflib.Graph,
178+
ns_base: rdflib.Namespace,
179+
gnu_time_log: str,
180+
mtime: typing.Optional[str] = None,
181+
prefix_slug: typing.Optional[str] = None
182+
) -> ProcessUCOObject:
173183
"""
174184
This function builds a Process UCO Object from a file that contains the output of GNU Time's --verbose flag.
175185
@@ -212,6 +222,7 @@ def main() -> None:
212222
graph.namespace_manager.bind("kb", NS_BASE)
213223
graph.namespace_manager.bind("uco-core", NS_UCO_CORE)
214224
graph.namespace_manager.bind("uco-observable", NS_UCO_OBSERVABLE)
225+
graph.namespace_manager.bind("xsd", NS_XSD)
215226

216227
mtime_str = None
217228
if args.done_log:

dependencies/CASE-Examples-QC

Lines changed: 0 additions & 1 deletion
This file was deleted.

dependencies/CASE-Utilities-Python

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ classifiers =
1717

1818
[options]
1919
install_requires =
20-
case_utils >= 0.3.0
20+
case_utils >= 0.9.0, < 0.10.0
2121
python-dateutil
2222
packages = find:
2323
python_requires = >=3.7

tests/Makefile

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ all: \
4040

4141
.venv.done.log: \
4242
$(top_srcdir)/.git_submodule_init.done.log \
43-
$(top_srcdir)/case_gnu_time/__init__.py \
4443
$(top_srcdir)/dependencies/CASE-Utilities-Python/tests/requirements.txt \
4544
$(top_srcdir)/setup.cfg \
4645
$(top_srcdir)/setup.py \
@@ -54,21 +53,16 @@ all: \
5453
pip \
5554
setuptools \
5655
wheel
57-
source venv/bin/activate \
58-
&& cd $(top_srcdir)/dependencies/CASE-Utilities-Python \
59-
&& pip install \
60-
.
6156
source venv/bin/activate \
6257
&& pip install \
6358
--requirement $(top_srcdir)/dependencies/CASE-Utilities-Python/tests/requirements.txt
6459
source venv/bin/activate \
65-
&& cd $(top_srcdir) \
66-
&& pip install \
67-
--editable \
68-
.
60+
&& pip install \
61+
--editable \
62+
$(top_srcdir)
6963
source venv/bin/activate \
7064
&& pip install \
71-
-r requirements.txt
65+
--requirement requirements.txt
7266
touch $@
7367

7468
.venv_minimal.done.log: \
@@ -86,16 +80,12 @@ all: \
8680
pip \
8781
setuptools \
8882
wheel
89-
source venv_minimal/bin/activate \
90-
&& cd $(top_srcdir)/dependencies/CASE-Utilities-Python \
91-
&& pip install \
92-
.
9383
source venv_minimal/bin/activate \
9484
&& pip install \
9585
--requirement $(top_srcdir)/dependencies/CASE-Utilities-Python/tests/requirements.txt
9686
source venv_minimal/bin/activate \
9787
&& pip install \
98-
-r requirements.txt
88+
--requirement requirements.txt
9989
touch $@
10090

10191
all-as_import: \
@@ -154,11 +144,9 @@ check-mypy: \
154144
.venv.done.log
155145
source venv/bin/activate \
156146
&& mypy \
147+
--strict \
157148
$(top_srcdir)/case_gnu_time \
158-
as_import \
159-
from_pip \
160-
gtime_and_done_log \
161-
gtime_log
149+
as_import
162150

163151
clean:
164152
@$(MAKE) \
@@ -175,9 +163,6 @@ clean:
175163
clean
176164
@rm -rf \
177165
.pytest_cache
178-
179-
distclean: \
180-
clean
181166
@rm -f \
182167
.venv.done.log \
183168
.venv_minimal.done.log

0 commit comments

Comments
 (0)