Skip to content

Commit

Permalink
Merge pull request #769 from simphony/dev
Browse files Browse the repository at this point in the history
 Merge release 3.8.0
  • Loading branch information
kysrpex authored Apr 7, 2022
2 parents 638fc6a + 820c90e commit f2d15e4
Show file tree
Hide file tree
Showing 146 changed files with 9,112 additions and 5,236 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
4 changes: 2 additions & 2 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Performance check
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# - uses: actions/setup-python@v1 # (not needed for self-hosted runner)
# with:
# python-version: '3.8'
Expand All @@ -38,4 +38,4 @@ jobs:
alert-threshold: '150%'
comment-on-alert: true
alert-comment-cc-users: '@yoavnash,@pablo-de-andres,@kysrpex'
fail-on-alert: true
fail-on-alert: true
33 changes: 23 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,39 @@ name: CI
on: pull_request

jobs:
code_analysis:
PEP8:
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Flake8
run: flake8 . --exclude=*/__init__.py,osp/core/ontology/docs/EMMO/* --ignore=W503 --docstring-convention=google
run: flake8 . --exclude=*/__init__.py,osp/core/ontology/docs/EMMO/* --ignore=E203,W503 --docstring-convention=google

# Includes isort, black and other checks, see `.pre-commit.config.yaml`.
- name: pre-commit
run: pre-commit run --all-files

complexity:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3

- name: Radon
run: |
radon cc -s -a .,
radon mi -s .
- name: bandit
security:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3

- name: Bandit
run: bandit -r osp --skip B101
test:

testing:
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: unittesting
- uses: actions/checkout@v3
- name: tox
run: tox

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ osp/core/java/target
osp/core/packageinfo.py
*.jar
*.so
osp/core/java/lib/so/FaCT++
osp/core/java/lib/so/FaCT++
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-json
- id: check-yaml
- id: pretty-format-json
args:
- --autofix
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
args: [--profile, black, --filter-files, --line-length, "79"]

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
args: [--line-length, "79"]
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
RUN python -m pip install --upgrade pip

ADD . /simphony/osp-core
RUN pip install /simphony/osp-core
RUN pip install /simphony/osp-core
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ Redistribution and use in source and binary forms, with or without modification,

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include packageinfo.py
include osp/core/ontology/docs/*.yml
include osp/core/ontology/docs/*.xml
include osp/core/ontology/docs/*.ttl
include osp/core/ontology/docs/EMMO/emmo-inferred.owl
include osp/core/ontology/docs/EMMO/emmo-inferred.owl
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ From our experience, this will not happen if you use the virtual environements o

## Acknowledgements

The OSP-core Python package originates from the European Project [SimPhoNy](https://www.simphony-project.eu/) (Project Nr. 604005). We would like to acknowledge and thank our project partners, especially [Enthought, Inc](https://www.enthought.com/), [Centre Internacional de Mètodes Numèrics a l'Enginyeria (CIMNE)](https://cimne.com/) and the [University of Jyväskylä](https://www.jyu.fi/en), for their important contributions to some of the core concepts of OSP-core, which were originally demonstrated under the project https://github.com/simphony/simphony-common.
The OSP-core Python package originates from the European Project [SimPhoNy](https://www.simphony-project.eu/) (Project Nr. 604005). We would like to acknowledge and thank our project partners, especially [Enthought, Inc](https://www.enthought.com/), [Centre Internacional de Mètodes Numèrics a l'Enginyeria (CIMNE)](https://cimne.com/) and the [University of Jyväskylä](https://www.jyu.fi/en), for their important contributions to some of the core concepts of OSP-core, which were originally demonstrated under the project https://github.com/simphony/simphony-common.
5 changes: 2 additions & 3 deletions examples/api_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@
print("\nAdding neighborhoods to Cuds object in a loop:")
for i in range(6):
print("Added neighborhood %s" % i)
c.add(city.Neighborhood(
name="neighborhood %s" % i))
c.add(city.Neighborhood(name="neighborhood %s" % i))
print("internal dict of c:", c._neighbors, "\n")

print('Trying out the `is_a` method trivially with the new neighborhoods.')
print("Trying out the `is_a` method trivially with the new neighborhoods.")
print(all(n.is_a(city.Neighborhood) for n in c.get(oclass=city.Neighborhood)))
40 changes: 25 additions & 15 deletions examples/example_rdf_import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,33 @@
# p = Parser()
# p.parse("city")

import uuid
import re
import os
import re
import uuid

from rdflib import URIRef
from osp.wrappers.sqlite import SqliteSession

from osp.core.namespaces import city
from osp.core.utils import import_cuds, export_cuds, branch, pretty_print
from osp.core.utils import branch, export_cuds, import_cuds, pretty_print
from osp.wrappers.sqlite import SqliteSession

uuid_re = re.compile(r".*(http://www\.osp-core\.com/cuds#"
r"([a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}"
r"-[a-z0-9]{4}-[a-z0-9]{12})).*")
uuid_re = re.compile(
r".*(http://www\.osp-core\.com/cuds#"
r"([a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}"
r"-[a-z0-9]{4}-[a-z0-9]{12})).*"
)

# Create CUDS structure
c = branch(branch(city.City(name="Freiburg"),
city.City(name="Pablo"),
city.City(name="Yoav"),
rel=city.hasInhabitant),
city.Neighborhood(name="Stühlinger"),
city.Neighborhood(name="Herdern"))
c = branch(
branch(
city.City(name="Freiburg"),
city.City(name="Pablo"),
city.City(name="Yoav"),
rel=city.hasInhabitant,
),
city.Neighborhood(name="Stühlinger"),
city.Neighborhood(name="Herdern"),
)

# Export from Core Session
export_cuds(path="test.rdf", format="ttl")
Expand Down Expand Up @@ -64,8 +72,10 @@
match = uuid_re.match(line)
if match:
uid = uuid.UUID(match[2])
line = line.replace(match[1], "http://city.com/"
+ session._registry.get(uid).name)
line = line.replace(
match[1],
"http://city.com/" + session._registry.get(uid).name,
)
print("\t", line, end="")
print(line, end="", file=f2)

Expand Down
6 changes: 3 additions & 3 deletions examples/example_sqlite_wrapper_city.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Please install the city ontology: $pico install city

import os

from osp.core.namespaces import city
from osp.core.utils import pretty_print
from osp.wrappers.sqlite_wrapper_session import \
SqliteWrapperSession
from osp.wrappers.sqlite_wrapper_session import SqliteWrapperSession

try:
# Construct the Datastructure.
Expand All @@ -17,7 +17,7 @@
n = city.Neighborhood(name="Zähringen")
s = city.Street(name="Le street")
b = city.Building(name="Theater")
a = city.Address(postalCode=79123, name='Le street', number=12)
a = city.Address(postalCode=79123, name="Le street", number=12)
c.add(p1, p2, p3, rel=city.hasInhabitant)
c.add(n).add(s).add(b).add(a)

Expand Down
18 changes: 11 additions & 7 deletions examples/file_upload.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"""An example explaining how to upload files using the transport layer."""

import sys
import logging
from osp.wrappers.sqlite import SqliteSession
from osp.core.session import TransportSessionServer
import sys

from osp.core.namespaces import cuba
from osp.core.session import TransportSessionServer
from osp.wrappers.dataspace import DataspaceSession
from osp.wrappers.sqlite import SqliteSession

logging.getLogger("osp.core.session.transport").setLevel(logging.DEBUG)

if sys.argv[-1] == "client":
print("Please specify where you want to cache the files on the client:")
with DataspaceSession("ws://127.0.0.1:4587",
input("file destination: > ")) as session:
with DataspaceSession(
"ws://127.0.0.1:4587", input("file destination: > ")
) as session:
wrapper = cuba.Wrapper(session=session)
file = cuba.File(path=input("file to upload: > "))
wrapper.add(file, rel=cuba.activeRelationship)
Expand All @@ -24,7 +26,9 @@
print("Starting server now.")
print("Please call 'python %s client' to connect" % __file__)
TransportSessionServer(
SqliteSession, "localhost", 4587,
SqliteSession,
"localhost",
4587,
session_kwargs={"path": "test.db"},
file_destination=file_destination
file_destination=file_destination,
).startListening()
39 changes: 22 additions & 17 deletions examples/multiple_wrappers_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

# Please install the city ontology: $pico install city

from getpass import getpass

from osp.core.namespaces import city
from osp.core.utils import pretty_print
from getpass import getpass
from osp.wrappers.simdummy import SimDummySession

try:
from osp.wrappers.sqlalchemy_wrapper_session import \
SqlAlchemyWrapperSession
from osp.wrappers.sqlalchemy_wrapper_session import (
SqlAlchemyWrapperSession,
)
except ImportError as e:
raise ImportError("For this example, the SQLAlchemy "
"wrapper for SimPhoNy is required!") from e
raise ImportError(
"For this example, the SQLAlchemy " "wrapper for SimPhoNy is required!"
) from e

# import logging
# logger = logging.getLogger("osp.core")
Expand All @@ -23,18 +27,20 @@
db_name = input("Database name: ")
host = input("Host: ")
port = int(input("Port [5432]: ") or 5432)
postgres_url = 'postgresql://%s:%s@%s:%s/%s' % (user, pwd, host, port, db_name)
postgres_url = "postgresql://%s:%s@%s:%s/%s" % (user, pwd, host, port, db_name)

# Let's build an EMMO compatible city!
emmo_town = city.City(name='EMMO town')
emmo_town = city.City(name="EMMO town")

emmo_town.add(city.Citizen(name='Emanuele Ghedini'), rel=city.hasInhabitant)
emmo_town.add(city.Citizen(name='Adham Hashibon'), rel=city.hasInhabitant)
emmo_town.add(city.Citizen(name='Jesper Friis'),
city.Citizen(name='Gerhard Goldbeck'),
city.Citizen(name='Georg Schmitz'),
city.Citizen(name='Anne de Baas'),
rel=city.hasInhabitant)
emmo_town.add(city.Citizen(name="Emanuele Ghedini"), rel=city.hasInhabitant)
emmo_town.add(city.Citizen(name="Adham Hashibon"), rel=city.hasInhabitant)
emmo_town.add(
city.Citizen(name="Jesper Friis"),
city.Citizen(name="Gerhard Goldbeck"),
city.Citizen(name="Georg Schmitz"),
city.Citizen(name="Anne de Baas"),
rel=city.hasInhabitant,
)

emmo_town.add(city.Neighborhood(name="Ontology"))
emmo_town.add(city.Neighborhood(name="User cases"))
Expand All @@ -49,7 +55,7 @@
onto = emmo_town.get(ontology_uid)

# We can go through inverse relationships
print(onto.get(rel=city.isPartOf)[0].name + ' is my city!')
print(onto.get(rel=city.isPartOf)[0].name + " is my city!")

# Working with a DB-wrapper: Store in the DB.
with SqlAlchemyWrapperSession(postgres_url) as session:
Expand All @@ -66,8 +72,7 @@

# Working with a Simulation wrapper
with SimDummySession() as sim_session:
sim_wrapper = city.CitySimWrapper(numSteps=1,
session=sim_session)
sim_wrapper = city.CitySimWrapper(numSteps=1, session=sim_session)
new_inhabitant = city.Person(age=31, name="Peter")
sim_emmo_town, _ = sim_wrapper.add(db_emmo_town, new_inhabitant)
sim_session.run()
Expand Down
Loading

0 comments on commit f2d15e4

Please sign in to comment.