Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e6e5307
Start adding more validation
CasperWA Oct 15, 2023
938357f
Integrate metadata into SOFT7 instance
CasperWA Oct 17, 2023
7494a0f
Add tests for the SOFT7Entity pydantic model
CasperWA Sep 7, 2023
48dcd41
Update tests
CasperWA Oct 17, 2023
3a97e6a
Remove unused validator
CasperWA Oct 17, 2023
6655687
Use 'entity' instead of 'data_model' for var name
CasperWA Oct 17, 2023
21c956d
Add test for create_datasource()
CasperWA Oct 17, 2023
75dd10c
Create MixIn class for the special getattribute
CasperWA Oct 18, 2023
2436228
Copy over fixtures from oteapi-core
CasperWA Oct 18, 2023
83cbebb
New test for inspecting data source
CasperWA Oct 18, 2023
6149a9a
Add beginnings for JSON serialization tests
CasperWA Oct 18, 2023
a3399d6
Implement proper attributes serialization
CasperWA Oct 18, 2023
8e0cfe7
Finish serialization tests
CasperWA Oct 18, 2023
53e063b
Use otelib >=v0.4.0
CasperWA Oct 19, 2023
a1b2ac8
Use --cov-report=term-missing option for pytest
CasperWA Oct 19, 2023
013b8fd
Move stuff from factory to pydantic models
CasperWA Nov 7, 2023
c9824c3
Update pre-commit hooks, add pyupgrade hook
CasperWA Nov 7, 2023
0b02b10
Add public factory classes
CasperWA Nov 7, 2023
f45da32
Update docstring to not break URL
CasperWA Nov 7, 2023
97cedaa
Start progress on an example for SOFT7 Data Source
CasperWA Nov 7, 2023
9f21ef7
Use pydantic.AliasChoices to allow `identity` and `uri`
CasperWA Nov 8, 2023
71d11d1
Update ruff rules
CasperWA Nov 8, 2023
03a9d69
Further work on SOFT7 Entity instances
CasperWA Nov 13, 2023
3f84ace
Finalize soft7 generator oteapi function strategy
CasperWA Nov 13, 2023
9b11c1a
Finish everything
CasperWA Nov 14, 2023
e9891ea
Further test new datasource factory
CasperWA Nov 14, 2023
9fad8b5
Minor fixes - satisfying pre-commit
CasperWA Nov 14, 2023
f523644
Further upgrades
CasperWA Nov 15, 2023
5e3fb54
Will rely on SOFT7Generator only returning ONE instance
CasperWA Nov 15, 2023
acae39c
Further improvements
CasperWA Nov 16, 2023
9aee4e8
It works!! Amazingly - and most likely hackily
CasperWA Nov 16, 2023
743a642
Update create model class names
CasperWA Nov 17, 2023
d4864a4
Add a nicer error message for CallableAttributesMixin
CasperWA Nov 17, 2023
dc527ec
Fix tests for the new implementation
CasperWA Dec 6, 2023
0e80aeb
Ignore importlib.metadata deprecation warning
CasperWA Dec 6, 2023
f244adb
Merge branch 'main' into cwa/soft7-instance-factory
CasperWA Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,38 @@ jobs:

# Documentation
run_build_docs: false

pytest:
name: pytest
runs-on: ubuntu-latest

strategy:
matrix:
# Supported Python versions (according to pyproject.toml)
python-version: ['3.9', '3.10']

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install -U pip
pip install -U setuptools wheel flit
pip install -e .[dev]

- name: Run pytest
run: pytest -v -rs --cov=s7 --cov-report=xml --cov-report=term-missing

- name: Upload code coverage report
if: github.repository == 'SINTEF/soft7' && matrix.python-version == '3.9'
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
flags: pytest
token: ${{ secrets.CODECOV_TOKEN }}
25 changes: 17 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,27 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: ruff
args:
- "--fix"
- "--exit-non-zero-on-fix"
- id: pyupgrade
args: ["--py39-plus", "--keep-runtime-typing"]

- repo: https://github.com/ambv/black
rev: 23.9.1
rev: 23.11.0
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.5
hooks:
- id: ruff
args:
- "--fix"
- "--exit-non-zero-on-fix"
- "--show-fixes"
- "--no-unsafe-fixes"

- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
Expand All @@ -46,9 +54,10 @@ repos:
files: ^s7/.*$

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.6.0
rev: v1.7.0
hooks:
- id: mypy
exclude: ^tests/.*$
additional_dependencies:
- pydantic>=2,<3
- types-PyYAML
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 SINTEF
Copyright (c) 2023 SINTEF

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
72 changes: 72 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,73 @@
# SOFT7

## OTEAPI plugin

The `soft7` packages comes with an [OTEAPI](https://github.com/EMMC-ASBL/oteapi-core) plugin that allows one to convert any core parser data to a SOFT7 Entity instance.

To use the plugin, call the `'soft7'` `functionType` function strategy.

### Test the plugin

At the root of the repository is a [Docker Compose](https://docs.docker.com/compose/) file, which, when run, will start an [OTEAPI Service](https://github.com/EMMC-ASBL/oteapi-services#readme) that includes the `soft7` OTEAPI plugin.

To start the service, run:

```bash
docker compose pull
docker compose up -d
```

To follow along with the installation of the `soft7` package and startup of the OTEAPI Service, run:

```bash
docker logs -f soft7-oteapi-1
```

Press Ctrl+C to stop following the logs.

To eventually stop the services, run:

```bash
docker compose down
```

But first, let's test the plugin.

Open a Python shell, an [IPython shell](https://ipython.org/), or a [Jupyter Notebook](https://jupyter.org/), and run:

```python
from s7.factories import create_datasource

# Let us use an OPTIMADE structure from the Materials Project as our "raw" data source.
# The chosen structure is mp-1228448 (Al2O3):
# https://materialsproject.org/materials/mp-1228448/
# For more information about OPTIMADE, see https://www.optimade.org/
# For more information about the Materials Project, see https://materialsproject.org/
dataresource_config = {
"downloadUrl": (
"https://optimade.materialsproject.org/v1/structures/mp-1228448?"
"response_format=json"
),
"mediaType": "application/json",
}

# We need to setup a mapping configuration to tell the plugin how to map the OPTIMADE
# structure to a SOFT7 Entity instance.
# This requires knowledge of the OPTIMADE structure and the SOFT7 Entity.
# In our case the OPTIMADE structure specification is available at
# https://github.com/Materials-Consortia/OPTIMADE/blob/v1.1.0/optimade.rst#structures-entries
# and the SOFT7 Entity of choice is the `OPTIMADEStructure` Entity, which can be found
# at http://onto-ns.com/meta/1.0/OPTIMADEStructure
mapping_config = {
"mappingType": "triples",
"prefixes": {
"optimade": "https://optimade.materialsproject.org/v1/structures/mp-1228448#",
"soft7": "http://onto-ns.com/meta/1.0/OPTIMADEStructure#",
},
"triples": {
("optimade:data.id", "", "soft7:properties.id"),
("optimade:data.type", "", "soft7:properties.type"),
("optimade:data.attributes", "", "soft7:properties."),
}
}
```
17 changes: 17 additions & 0 deletions agraph.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# AllegroGraph configuration file
RunAs agraph
SessionPorts 10000-10034
Port 10035
SettingsDirectory /agraph/data/settings
LogDir /agraph/data
PidFile /agraph/data/agraph.pid
InstanceTimeout 604800
SuperUser dbuser:test123
<RootCatalog>
Main /agraph/data/rootcatalog
</RootCatalog>

<SystemCatalog>
Main /agraph/data/systemcatalog
InstanceTimeout 10
</SystemCatalog>
48 changes: 48 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: "3"

services:
oteapi:
image: ghcr.io/emmc-asbl/oteapi:${DOCKER_OTEAPI_VERSION:-latest}
ports:
- "${PORT:-8080}:8080"
environment:
OTEAPI_REDIS_TYPE: redis
OTEAPI_REDIS_HOST: redis
OTEAPI_REDIS_PORT: 6379
OTEAPI_prefix: "${OTEAPI_prefix:-/api/v1}"
OTEAPI_INCLUDE_REDISADMIN: "${OTEAPI_INCLUDE_REDISADMIN:-False}"
OTEAPI_EXPOSE_SECRETS: "${OTEAPI_EXPOSE_SECRETS:-True}"
OTEAPI_AUTHENTICAION_DEPENDENCIES:
OTEAPI_PLUGIN_PACKAGES: "-v -e /soft7"
depends_on:
- redis
networks:
- otenet
volumes:
- "${PWD}:/soft7"

redis:
image: redis:latest
volumes:
- redis-persist:/data
networks:
- otenet

agraph:
image: franzinc/agraph:v7.2.0
volumes:
- agraph-data:/agraph/data
- ./agraph.cfg:/agraph/etc/agraph.cfg
ports:
- "10000-10035:10000-10035"
restart: on-failure
shm_size: 4g
networks:
- otenet

volumes:
redis-persist:
agraph-data:

networks:
otenet:
Loading