Skip to content

Commit ba3c6a2

Browse files
committed
Merge branch 'develop' into release-0.14.1
2 parents 0ae98b4 + 02dab3a commit ba3c6a2

File tree

5 files changed

+43
-157
lines changed

5 files changed

+43
-157
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ This repository can be installed from PyPI or from source.
1919
pip install case-utils
2020
```
2121

22-
Users who wish to install from PyPI should be aware that while CASE's ontology is in its pre-1.0.0 release state, backwards-incompatible ontology changes may occur. This may manifest as [`case_validate`](#case_validate) reporting data review errors after installing an updated `case_utils` version. Users may wish to pin `case_utils` within any dependent code bases to be less than the next unreleased SEMVER-minor version. (E.g. if `case_utils` version `0.8.0` is currently available, a newly adopting project might wish to track `case_utils<0.9.0` among its dependencies.)
22+
Users who wish to install from PyPI should be aware that though CASE's ontology is in its post-1.0.0 release state, this Python project is in a pre-1.0.0 release state. Backwards-incompatible ontology changes will only occur in accordance with [SEMVER](https://semver.org/). This Python project is not yet committed to its API, and backwards-incompatiable changes may occur. They are likely to occur with advance notice.
23+
24+
Users may wish to pin `case-utils` within any dependent code bases to be less than the next unreleased SEMVER-minor version. (E.g. if `case-utils` version `0.14.0` is currently available, a newly adopting project might wish to track `case-utils<0.15.0` among its dependencies.)
2325

2426

2527
### Installing from source
@@ -120,7 +122,7 @@ case_sparql_select output.md input.sparql input.json [input-2.json ...]
120122

121123
### `local_uuid`
122124

123-
This [module](case_utils/local_uuid.py) provides a wrapper UUID generator, `local_uuid()`. Its main purpose is making example data generate consistent identifiers, and intentionally includes mechanisms to make it difficult to activate this mode without awareness of the caller.
125+
_Migration:_ Functionality previously in [`case_utils.local_uuid`](case_utils/local_uuid.py) has been exported to [`cdo-local-uuid`](https://github.com/Cyber-Domain-Ontology/CDO-Utility-Local-UUID). A future `case-utils` release will drop this re-export.
124126

125127

126128
### Built versions

case_utils/case_validate/validate_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def disable_tbox_review(graph: rdflib.Graph) -> None:
197197
"Disjointedness-AP-OP-shape",
198198
"Disjointedness-C-DT-shape",
199199
"Disjointedness-DP-OP-shape",
200+
"List-shape",
200201
"ObjectProperty-shacl-constraints-shape",
201202
"ontologyIRI-versionIRI-prerequisite-shape",
202203
"versionIRI-nodeKind-shape",

case_utils/local_uuid.py

Lines changed: 6 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -15,167 +15,18 @@
1515
# We would appreciate acknowledgement if the software is used.
1616

1717
"""
18-
This library is a wrapper for uuid, provided to generate repeatable UUIDs if requested.
19-
20-
The function local_uuid() should be used in code where a user could be expected to opt in to non-random UUIDs.
18+
This library was a wrapper for uuid, provided to generate repeatable UUIDs if requested. It is now a temporary re-export of functionality migrated to cdo_local_uuid.
2119
"""
2220

2321
__version__ = "0.4.0"
2422

2523
__all__ = ["configure", "local_uuid"]
2624

27-
import logging
28-
import os
29-
import pathlib
30-
import sys
31-
import typing
32-
import uuid
3325
import warnings
3426

35-
DEMO_UUID_BASE: typing.Optional[str] = None
36-
37-
DEMO_UUID_COUNTER: int = 0
38-
39-
_logger = logging.getLogger(pathlib.Path(__file__).name)
40-
41-
42-
def _is_relative_to(p1: pathlib.Path, p2: pathlib.Path) -> bool:
43-
"""
44-
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.
45-
"""
46-
if sys.version_info < (3, 9):
47-
try:
48-
_ = p1.relative_to(p2)
49-
return True
50-
except ValueError:
51-
return False
52-
else:
53-
return p1.is_relative_to(p2)
54-
55-
56-
def configure() -> None:
57-
"""
58-
This function is part of setting up _demo_uuid() to generate non-random UUIDs. See _demo_uuid() documentation for further setup notes.
59-
"""
60-
global DEMO_UUID_BASE
61-
62-
# _logger.debug("sys.argv = %r.", sys.argv)
63-
64-
if os.getenv("DEMO_UUID_REQUESTING_NONRANDOM") == "NONRANDOM_REQUESTED":
65-
warnings.warn(
66-
"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.",
67-
FutureWarning,
68-
)
69-
return
70-
71-
env_base_dir_name = os.getenv("CASE_DEMO_NONRANDOM_UUID_BASE")
72-
if env_base_dir_name is None:
73-
return
74-
75-
base_dir_original_path = pathlib.Path(env_base_dir_name)
76-
if not base_dir_original_path.exists():
77-
warnings.warn(
78-
"Environment variable CASE_DEMO_NONRANDOM_UUID_BASE is expected to refer to an existing directory. Proceeding with random UUIDs.",
79-
RuntimeWarning,
80-
)
81-
return
82-
if not base_dir_original_path.is_dir():
83-
warnings.warn(
84-
"Environment variable CASE_DEMO_NONRANDOM_UUID_BASE is expected to refer to a directory. Proceeding with random UUIDs.",
85-
RuntimeWarning,
86-
)
87-
return
88-
89-
# Component: An emphasis this is an example.
90-
demo_uuid_base_parts = ["example.org"]
91-
92-
# Component: Present working directory, relative to CASE_DEMO_NONRANDOM_UUID_BASE if that environment variable is an ancestor of pwd.
93-
base_dir_resolved_path = base_dir_original_path.resolve()
94-
srcdir_original_path = pathlib.Path(os.getcwd())
95-
srcdir_resolved_path = srcdir_original_path.resolve()
96-
# _logger.debug("base_dir_resolved_path = %r.", base_dir_resolved_path)
97-
# _logger.debug("srcdir_resolved_path = %r.", srcdir_resolved_path)
98-
try:
99-
srcdir_relative_path = srcdir_resolved_path.relative_to(base_dir_resolved_path)
100-
# _logger.debug("srcdir_relative_path = %r.", srcdir_relative_path)
101-
demo_uuid_base_parts.append(str(srcdir_relative_path))
102-
except ValueError:
103-
# If base_dir is not an ancestor directory of srcdir, default to srcdir.
104-
# _logger.debug("PWD is not relative to base path.")
105-
demo_uuid_base_parts.append(str(srcdir_resolved_path))
106-
107-
# Component: Command of argument vector.
108-
env_venv_name = os.getenv("VIRTUAL_ENV")
109-
if env_venv_name is None:
110-
demo_uuid_base_parts.append(sys.argv[0])
111-
else:
112-
command_original_path = pathlib.Path(sys.argv[0])
113-
# _logger.debug("command_original_path = %r.", command_original_path)
114-
command_resolved_path = command_original_path.resolve()
115-
# _logger.debug("command_resolved_path = %r.", command_resolved_path)
116-
117-
# The command could be a command embedded in a virtual
118-
# environment, or it could be a script external to any virtual
119-
# environment.
120-
venv_original_path = pathlib.Path(env_venv_name)
121-
venv_resolved_path = venv_original_path.resolve()
122-
if _is_relative_to(command_resolved_path, venv_resolved_path):
123-
command_relative_path = command_resolved_path.relative_to(
124-
venv_resolved_path
125-
)
126-
# _logger.debug("command_relative_path = %r.", command_relative_path)
127-
demo_uuid_base_parts.append(str(command_relative_path))
128-
else:
129-
demo_uuid_base_parts.append(str(command_original_path))
130-
131-
if len(sys.argv) > 1:
132-
# Component: Arguments of argument vector.
133-
demo_uuid_base_parts.extend(sys.argv[1:])
134-
135-
# _logger.debug("demo_uuid_base_parts = %r.", demo_uuid_base_parts)
136-
137-
DEMO_UUID_BASE = "/".join(demo_uuid_base_parts)
138-
139-
140-
def _demo_uuid() -> str:
141-
"""
142-
This function generates a repeatable UUID, drawing on non-varying elements of the environment and process call for entropy.
143-
144-
This function is not intended to be called outside of this module. Instead, local_uuid() should be called.
145-
146-
WARNING: This function was developed for use ONLY for reducing (but not eliminating) version-control edits to identifiers when generating sample data. It creates UUIDs that are decidedly NOT random, and should remain consistent on repeated calls to the importing script.
147-
148-
To prevent accidental non-random UUID usage, two setup steps need to be done before calling this function:
149-
150-
* An environment variable, CASE_DEMO_NONRANDOM_UUID_BASE, must be set to a string provided by the caller. The variable's required value is the path to some directory. The variable's recommended value is the equivalent of the Make variable "top_srcdir" - that is, the root directory of the containing Git repository, some parent of the current process's current working directory.
151-
* The configure() function in this module must be called.
152-
"""
153-
global DEMO_UUID_BASE
154-
global DEMO_UUID_COUNTER
155-
156-
if os.getenv("CASE_DEMO_NONRANDOM_UUID_BASE") is None:
157-
raise ValueError(
158-
"demo_uuid() called without CASE_DEMO_NONRANDOM_UUID_BASE in environment."
159-
)
160-
161-
if DEMO_UUID_BASE is None:
162-
raise ValueError("demo_uuid() called with DEMO_UUID_BASE unset.")
163-
164-
parts = [DEMO_UUID_BASE]
165-
166-
# Component: Incrementing counter.
167-
DEMO_UUID_COUNTER += 1
168-
parts.append(str(DEMO_UUID_COUNTER))
169-
170-
return str(uuid.uuid5(uuid.NAMESPACE_URL, "/".join(parts)))
171-
27+
from cdo_local_uuid import configure, local_uuid
17228

173-
def local_uuid() -> str:
174-
"""
175-
Generate either a UUID4, or if requested via environment configuration, a non-random demo UUID.
176-
"""
177-
global DEMO_UUID_BASE
178-
if DEMO_UUID_BASE is None:
179-
return str(uuid.uuid4())
180-
else:
181-
return _demo_uuid()
29+
warnings.warn(
30+
"case_utils.local_uuid has exported its functionality to cdo_local_uuid. Imports should be changed to use cdo_local_uuid. case_utils currently re-exports that functionality, but this will cease in a future release.",
31+
DeprecationWarning,
32+
)

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ license_files =
1919
[options]
2020
include_package_data = true
2121
install_requires =
22+
cdo-local-uuid >= 0.4.0, < 0.5.0
2223
pandas
2324
pyshacl >= 0.24.0
2425
rdflib < 8

tests/case_utils/case_validate/uco_test_examples/Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,37 @@ all: \
100100
rm __$@
101101
mv _$@ $@
102102

103+
# NOTE - this more-specific recipe enables "tbox" review, but otherwise
104+
# matches the wildcarded recipe.
105+
rdf_list_XFAIL_validation.ttl: \
106+
$(examples_srcdir)/rdf_list_XFAIL.json \
107+
$(tests_srcdir)/.venv.done.log \
108+
$(top_srcdir)/.ontology.done.log \
109+
$(top_srcdir)/case_utils/case_validate/__init__.py \
110+
$(top_srcdir)/case_utils/case_validate/validate_types.py \
111+
$(top_srcdir)/case_utils/case_validate/validate_utils.py \
112+
$(top_srcdir)/case_utils/ontology/__init__.py
113+
source $(tests_srcdir)/venv/bin/activate \
114+
&& case_validate \
115+
--allow-warnings \
116+
--debug \
117+
--format turtle \
118+
--review-tbox \
119+
$< \
120+
> __$@ \
121+
; rc=$$? ; test 0 -eq $$rc -o 1 -eq $$rc
122+
@#Fail if output is empty.
123+
@test -s __$@ \
124+
|| exit 1
125+
java -jar $(RDF_TOOLKIT_JAR) \
126+
--inline-blank-nodes \
127+
--source __$@ \
128+
--source-format turtle \
129+
--target _$@ \
130+
--target-format turtle
131+
rm __$@
132+
mv _$@ $@
133+
103134
# NOTE - this more-specific recipe enables "tbox" review, but otherwise
104135
# matches the wildcarded recipe.
105136
owl_properties_XFAIL_validation.ttl: \

0 commit comments

Comments
 (0)