Skip to content

Commit

Permalink
Merge branch 'master' into ci/update-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
francescalb authored Oct 11, 2023
2 parents 1f4b8e9 + c6b2adc commit 4ded010
Show file tree
Hide file tree
Showing 110 changed files with 3,616 additions and 163 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/cd_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,23 @@ jobs:
- os: windows-2019
system_type: ["win", ""]
arch: amd64
py_minors: 7,8,9,10,11
py_minors: '7'
- os: windows-2019
system_type: ["win", ""]
arch: amd64
py_minors: '8'
- os: windows-2019
system_type: ["win", ""]
arch: amd64
py_minors: '9'
- os: windows-2019
system_type: ["win", ""]
arch: amd64
py_minors: '10'
- os: windows-2019
system_type: ["win", ""]
arch: amd64
py_minors: '11'

# See issue #221: https://github.com/SINTEF/dlite/issues/221
# # 64-bit (Intel) macOS
Expand All @@ -139,7 +155,8 @@ jobs:
- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: "3.${{ contains(matrix.py_minors, ',') && 'x' || matrix.py_minors }}"
architecture: ${{ matrix.arch == '' && 'x86' || 'x64' }}

- name: Login to GitHub Container Registry
if: startsWith(matrix.os, 'ubuntu')
Expand All @@ -161,7 +178,7 @@ jobs:
python -m cibuildwheel --print-build-identifiers python
python -m cibuildwheel --output-dir wheelhouse python
env:
CIBW_BUILD: cp3{${{ matrix.py_minors }}}-${{ matrix.system_type[0] }}${{ matrix.arch != '' && '_' || '' }}${{ matrix.arch }}
CIBW_BUILD: cp3${{ contains(matrix.py_minors, ',') && format('{{{0}}}', matrix.py_minors) || matrix.py_minors }}-${{ matrix.system_type[0] }}${{ matrix.arch != '' && '_' || '' }}${{ matrix.arch }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ env.CONTAINER_REGISTRY }}/sintef/dlite-python-manylinux${{ matrix.system_type[1] }}_x86_64:latest
CIBW_MANYLINUX_I686_IMAGE: ${{ env.CONTAINER_REGISTRY }}/sintef/dlite-python-manylinux${{ matrix.system_type[1] }}_i686:latest
CIBW_MUSLLINUX_X86_64_IMAGE: ${{ env.CONTAINER_REGISTRY }}/sintef/dlite-python-musllinux_1_1_x86_64:latest
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/ci_build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ jobs:
- os: windows-2019
system_type: ["win", ""]
arch: amd64
py_minors: 7,11
py_minors: '7'
- os: windows-2019
system_type: ["win", ""]
arch: amd64
py_minors: '11'

# See issue #221: https://github.com/SINTEF/dlite/issues/221
# # 64-bit (Intel) macOS
Expand All @@ -74,7 +78,8 @@ jobs:

- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: "3.${{ contains(matrix.py_minors, ',') && 'x' || matrix.py_minors }}"
architecture: ${{ matrix.arch == '' && 'x86' || 'x64' }}

- name: Login to GitHub Container Registry
if: startsWith(matrix.os, 'ubuntu')
Expand All @@ -96,7 +101,7 @@ jobs:
python -m cibuildwheel --print-build-identifiers python
python -m cibuildwheel --output-dir wheelhouse python
env:
CIBW_BUILD: cp3{${{ matrix.py_minors }}}-${{ matrix.system_type[0] }}${{ matrix.arch != '' && '_' || '' }}${{ matrix.arch }}
CIBW_BUILD: cp3${{ contains(matrix.py_minors, ',') && format('{{{0}}}', matrix.py_minors) || matrix.py_minors }}-${{ matrix.system_type[0] }}${{ matrix.arch != '' && '_' || '' }}${{ matrix.arch }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ env.container_registry }}/sintef/dlite-python-manylinux${{ matrix.system_type[1] }}_x86_64:latest
CIBW_MANYLINUX_I686_IMAGE: ${{ env.container_registry }}/sintef/dlite-python-manylinux${{ matrix.system_type[1] }}_i686:latest
CIBW_MUSLLINUX_X86_64_IMAGE: ${{ env.container_registry }}/sintef/dlite-python-musllinux_1_1_x86_64:latest
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ jobs:
- name: Install Python dependencies
run: |
which python3
python3 --version
python3 -m pip --version
python3 -m pip install --upgrade pip
python3 -m pip install -U setuptools wheel
python3 -m pip install -r requirements.txt -r requirements_full.txt -r requirements_dev.txt -r requirements_doc.txt
- name: Check numpy
run: |
which python3
python3 --version
python3 -m pip --version
python3 -c 'import numpy as np; print(np.get_include())'
- name: Workaround - install CMake 3.25.2 since 3.26.0 doesn't work
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cmake_minimum_required(VERSION 3.14)

project(dlite
VERSION 0.4.0
VERSION 0.4.1
DESCRIPTION "Lightweight data-centric framework for semantic interoperability"
HOMEPAGE_URL "https://github.com/SINTEF/dlite"
LANGUAGES C
Expand Down
58 changes: 43 additions & 15 deletions bindings/python/dlite-misc-python.i
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,57 @@

%pythoncode %{

class err():
"""Context manager for temporary turning off or redirecting errors.
By default errors are skipped within the err context. But if
`filename` is provided, the error messages are written to that file.
Special file names includes:
- "None" or empty: No output is written.
- "<stderr>": Write errors to stderr (default).
- "<stdout>": Write errors to stdout.
class errctl():
"""Context manager for temporary disabling specific DLite error
messages or redirecting them.
Arguments:
hide: Sequence of DLiteException subclasses or exception names
corresponding to error messages to hide. A single class or
name is also allowed.
show: Sequence of DLiteException subclasses or exception names
corresponding to error messages to show. A single class or
name is also allowed.
filename: Filename to redirect errors to. The following values
are handled specially:
- "None" or empty: No output is written.
- "<stderr>": Write errors to stderr (default).
- "<stdout>": Write errors to stdout.
"""
def __init__(self, filename=None):
def __init__(self, hide=(), show=(), filename="<stderr>"):
self.hide = self._as_codes(hide)
self.show = self._as_codes(show)
self.filename = filename

def __enter__(self):
self.mask = _dlite._err_mask_get()
for code in self.hide:
_dlite._err_ignore_set(code, 1)
for code in self.show:
_dlite._err_ignore_set(code, 0)
self.f = _dlite.err_get_stream()
_dlite.err_set_file(self.filename)
return self.f

def __exit__(self, *exc):
_dlite.errclr()
ignored = _dlite._err_ignore_get(_dlite.errval())
_dlite._err_mask_set(self.mask)
_dlite.err_set_stream(self.f)

silent = err()
if ignored or self.filename is None:
_dlite.errclr()

@staticmethod
def _as_codes(seq):
"""Return sequence of exceptions/exception names as a sequence of
DLite error coces. `seq` may also be a single exception or name."""
sequence = [seq] if isinstance(seq, (str, type)) else seq
return [
_dlite._err_getcode(
exc.__name__ if isinstance(exc, type) else str(exc)
)
for exc in sequence
]


silent = errctl(filename="None")
%}
29 changes: 29 additions & 0 deletions bindings/python/dlite-misc.i
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@
return atob(str);
}

int64_t _err_mask_get(void) {
return *_dlite_err_mask_get();
}

%}

%include <stdint.i>

%feature("docstring", "\
Returns the current version of DLite.
") dlite_get_version;
Expand Down Expand Up @@ -158,6 +164,29 @@ All other values are treated as a filename that will be opened in append mode.
") dlite_err_set_file;
void dlite_err_set_file(const char *filename);

%feature("docstring", "\
Return DLite error code corresponding to `name`. Unknown names will return
`dliteUnknownError`.
") dlite_errcode;
%rename(_err_getcode) dlite_errcode;
int dlite_errcode(const char *name);

/* Private help functions */
%feature("docstring", "\
Set whether to ignore printing given error code.
") dlite_err_ignored_set;
%rename(_err_ignore_set) dlite_err_ignored_set;
void dlite_err_ignored_set(int code, int value);

%feature("docstring", "\
Return whether printing is ignored for given error code.
") dlite_err_ignored_get;
%rename(_err_ignore_get) dlite_err_ignored_get;
int dlite_err_ignored_get(int code);

int64_t _err_mask_get(void);
%rename(_err_mask_set) _dlite_err_mask_set;
void _dlite_err_mask_set(int64_t mask);


/* ------------------------------
Expand Down
34 changes: 24 additions & 10 deletions bindings/python/dlite-storage-python.i
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@
"hold multiple instances, including both data and metadata."
)

@classmethod
def from_url(cls, url):
"""Create a new storage from `url`."""
return cls(url)

@classmethod
def load_plugins(cls):
"""Load all storage plugins."""
Expand Down Expand Up @@ -85,9 +80,28 @@

%extend StorageIterator {
%pythoncode %{

# Override default __init__()
def __init__(self, s, pattern=None):
"""Iterates over instances in storage `s`.
If `pattern` is given, only instances whos metadata URI
matches glob pattern `pattern` are returned.
"""
_dlite.StorageIterator_swiginit(
self, _dlite.new_StorageIterator(s, pattern))

# Keep a reference to self, such that it is not garbage-collected
# before end of iterations
if not hasattr(_dlite, "_storage_iters"):
_dlite._storage_iters = {}
_dlite._storage_iters[id(self.state)] = self

def __next__(self):
inst = self.next()
if not inst:
# Delete reference to iterator object stored away in __init__()
_dlite._storage_iters.pop(id(self.this), None)
raise StopIteration()
return inst
%}
Expand All @@ -97,20 +111,20 @@
%pythoncode %{
# Override default __init__()
def __init__(self):
"""Iterates over loaded storage plugins."""
"""Iterator over loaded storage plugins."""
_dlite.StoragePluginIter_swiginit(
self, _dlite.new_StoragePluginIter())
# Keep a reference to self, such that it is not garbage-collected
# before end of iterations
if not hasattr(_dlite, "_storage_plugin_iters"):
_dlite._storage_plugin_iters = {}
_dlite._storage_plugin_iters[id(self.iter)] = self
if not hasattr(_dlite, "_storage_iters"):
_dlite._storage_iters = {}
_dlite._storage_iters[id(self.iter)] = self

def __next__(self):
name = self.next()
if not name:
# Delete reference to iterator object stored away in __init__()
del _dlite._storage_plugin_iters[id(self.this)]
_dlite._storage_iters.pop(id(self.this), None)
raise StopIteration()
return name
%}
Expand Down
8 changes: 6 additions & 2 deletions bindings/python/dlite-storage.i
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ Returns next instance or None if exhausted.") next;
%newobject next;
struct _DLiteInstance *next(void) {
char uuid[DLITE_UUID_LENGTH+1];
if (dlite_storage_iter_next($self->s, $self->state, uuid) == 0)
return dlite_instance_load($self->s, uuid);
if (dlite_storage_iter_next($self->s, $self->state, uuid) == 0) {
DLiteInstance *inst = dlite_instance_load($self->s, uuid);
// Why isn't the refcount already increased?
dlite_instance_incref(inst);
return inst;
}
return NULL;
}

Expand Down
14 changes: 10 additions & 4 deletions bindings/python/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ def get_values(
else value
)
elif isinstance(input_value, Value):
values[key] = quantity(input_value.value, input_value.unit)
if isinstance(input_value.value, str):
values[key] = input_value.value
else:
values[key] = quantity(input_value.value, input_value.unit)
else:
raise TypeError(
"Expected values in inputs to be either MappingStep or Value objects."
Expand Down Expand Up @@ -742,9 +745,12 @@ def instance_routes(
for inst in instances:
props = {prop.name: prop for prop in inst.meta["properties"]}
for key, value in inst.properties.items():
sources[f"{inst.meta.uri}#{key}"] = quantity(
value, props[key].unit
)
if isinstance(value, str):
sources[f"{inst.meta.uri}#{key}"] = value
else:
sources[f"{inst.meta.uri}#{key}"] = quantity(
value, props[key].unit
)

routes = {}
for prop in meta["properties"]:
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ test_success(
)
test_success(
dlite-validate-persons
dlite-validate -p ../tests/Person.json -i 51c0d700-9ab0-43ea-9183-6ea22012ebee
dlite-validate -p ../tests/Person.json -i a1d8d35f-723c-5ea1-abaf-8fc8f1d0982f
../tests/persons.json
)
test_success(
dlite-validate-persons2
dlite-validate
--storage-path=../tests/Person.json
--id=13c5007b-c665-4709-a11c-255919306547
--storage-path=../tests
--id=Ada
--show
../tests/persons.json
)
Expand Down
1 change: 1 addition & 0 deletions bindings/python/tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ xxx2.json
yyy.json

myentity.json
persons2.json

db.xml
16 changes: 6 additions & 10 deletions bindings/python/tests/SimplePerson.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{
"name": "SimplePerson",
"version": "0.1",
"namespace": "http://onto-ns.com/meta",
"uri": "http://onto-ns.com/meta/0.1/SimplePerson",
"meta": "http://onto-ns.com/meta/0.3/EntitySchema",
"description": "A simple person representation.",
"dimensions": [],
"properties": [
{
"name": "name",
"dimensions": {},
"properties": {
"name": {
"type": "string",
"description": "Full name."
},
{
"name": "age",
"age": {
"type": "float",
"unit": "years",
"description": "Age of person."
}
]
}
}
Loading

0 comments on commit 4ded010

Please sign in to comment.