Skip to content

Commit

Permalink
Merge branch 'main' into reaxpro
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirankumaraswamy committed Jul 19, 2023
2 parents 549e309 + 409a003 commit d81ef7b
Show file tree
Hide file tree
Showing 32 changed files with 1,445 additions and 534 deletions.
16 changes: 16 additions & 0 deletions .env_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Marketplace URL
MP_HOST="https://dataspace.reaxpro.eu"
# Access token for markeplace connection. Need to change time to time when expired
MP_ACCESS_TOKEN=....

# Env variables needed for data-sink connection otherwise optional
# Client-ID of the datasink application
CLIENT_ID="2c791805-ea52-4446-af97-80c0355a73b4"

# optional: if incase if we want to get access_token directly from key_cloak
KEYCLOAK_SERVER_URL="https://dataspace.reaxpro.eu/auth/"
KEYCLOAK_CLIENT_ID=....
KEYCLOAK_REALM_NAME=....
KEYCLOAK_CLIENT_SECRET_KEY=....
MARKETPLACE_USERNAME=....
MARKETPLACE_PASSWORD=....
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.2
rev: 0.2.3
hooks:
- id: yamlfmt

Expand All @@ -20,7 +20,7 @@ repos:
- id: check-manifest

- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black

Expand All @@ -31,7 +31,7 @@ repos:
args: [--count, --show-source, --statistics]

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.2.0
rev: v2.3.0
hooks:
- id: setup-cfg-fmt

Expand All @@ -42,7 +42,7 @@ repos:
args: [--profile, black, --filter-files]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.6.0
hooks:
- id: pyupgrade
args: [--py38-plus]
4 changes: 3 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ exclude examples
recursive-exclude examples *

exclude .pre-commit-config.yaml
exclude .gitlab-ci.yml
exclude .flake8

include LICENSE
include README.md
include .env_template
recursive-include marketplace *.md
recursive-include logos *.png
5 changes: 5 additions & 0 deletions examples/data_sink_client/collection_dcat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.get_collection_dcat(collection_name="c1")
print(objects)
5 changes: 5 additions & 0 deletions examples/data_sink_client/dataset_dcat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.get_dataset_dcat(collection_name="c1", dataset_name="d1")
print(objects)
5 changes: 5 additions & 0 deletions examples/data_sink_client/delete_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.delete_collection(collection_name="c1")
print(objects)
5 changes: 5 additions & 0 deletions examples/data_sink_client/delete_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.delete_dataset(collection_name="c1", dataset_name="d1")
print(objects)
10 changes: 10 additions & 0 deletions examples/data_sink_client/download_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.download_dataset(
collection_name="upload_file_example",
dataset_name="file3.txt",
targetdir="/root/symphony/reaxpro",
raise_if_directory_not_empty=False,
)
print(objects)
9 changes: 9 additions & 0 deletions examples/data_sink_client/download_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.download_datasets_from_collection(
collection_name="Simulation_folder9",
targetdir="/root/symphony/reaxpro",
raise_if_directory_not_empty=False,
)
print(objects)
5 changes: 5 additions & 0 deletions examples/data_sink_client/list_collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.list_collections()
print(objects)
5 changes: 5 additions & 0 deletions examples/data_sink_client/list_datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.list_datasets(collection_name="c1")
print(objects)
6 changes: 6 additions & 0 deletions examples/data_sink_client/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from marketplace.data_sink_client.session import MPSession

query = """SELECT ?subject ?predicate ?object WHERE {{ ?subject ?predicate ?object . }} LIMIT 5"""
with MPSession() as test:
objects = test.query(query=query)
print(objects)
6 changes: 6 additions & 0 deletions examples/data_sink_client/query_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from marketplace.data_sink_client.session import MPSession

query = "SELECT ?subject ?predicate ?object WHERE {{ ?subject ?predicate ?object . }} LIMIT 5"
with MPSession() as test:
objects = test.query_dataset(collection_name="c1", dataset_name="d1", query=query)
print(objects)
8 changes: 8 additions & 0 deletions examples/data_sink_client/upload_files_from_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.create_dataset_from_path(
path="/root/symphony/reaxpro/Simulation_folder9/file3.txt",
collection_name="ams_wrapper9",
)
print(objects)
8 changes: 8 additions & 0 deletions examples/data_sink_client/upload_folder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from marketplace.data_sink_client.session import MPSession

with MPSession() as test:
objects = test.create_datasets_from_sourcedir(
sourcedir="/root/symphony/reaxpro/Simulation_folder9",
collection_name="Simulation_folder1",
)
print(objects)
12 changes: 0 additions & 12 deletions examples/mp_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from marketplace.app import get_app
from marketplace.app.v0 import MarketPlaceApp
from marketplace.app.v0_0_1 import MarketPlaceApp as MarketPlaceApp_v_0_0_1
from marketplace.client import MarketPlaceClient

# General MarketPlaceClient for simple requests like user info
Expand All @@ -30,14 +29,3 @@ def heartbeat(self) -> HTMLResponse:

my_mp_app = MyMarketPlaceApp(app_id="<application_client_id>")
print(my_mp_app.heartbeat())


# To extend the MarketPlaceApp with custom implementations for deprecated api version 0.0.1
class MyMarketPlaceApp_v_0_0_1(MarketPlaceApp_v_0_0_1):
def heartbeat(self) -> str:
res = super().heartbeat()
return f"heartbeat response: {res}"


my_mp_app_v_0_0_1 = MyMarketPlaceApp_v_0_0_1(client_id="<application_client_id>")
print(my_mp_app_v_0_0_1.heartbeat())
27 changes: 2 additions & 25 deletions marketplace/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@
.. currentmodule:: marketplace.app
.. moduleauthor:: Pablo de Andres, Pranjali Singh (Fraunhofer IWM)
"""
import warnings
from typing import Optional

from packaging.version import parse

from ..client import MarketPlaceClient
from .utils import camel_to_snake
from .v0 import MarketPlaceApp as _MarketPlaceApp_v0
from .v0_0_1 import MarketPlaceApp as _MarketPlaceApp_v0_0_1


class MarketPlaceApp(_MarketPlaceApp_v0_0_1):
def __init__(self, *args, **kwargs):
warnings.warn(
"The MarketPlaceApp class is deprecated as of v0.2.0 and will be "
"removed in v1. Please use the get_app() function instead."
)
super().__init__(*args, **kwargs)


def get_app(app_id, client: Optional[MarketPlaceClient] = None, **kwargs):
Expand All @@ -36,25 +25,13 @@ def get_app(app_id, client: Optional[MarketPlaceClient] = None, **kwargs):
# Getting api version and list of capabilities for the application
app_service_path = f"api/applications/{app_id}"
app_info: dict = client.get(path=app_service_path).json()
app_api_version = parse(app_info.get("api_version", "0.0.1"))
app_api_version = parse(app_info.get("api_version", "1.0.0"))

capabilities = []
for capability in app_info["capabilities"]:
capabilities.append(camel_to_snake(capability["name"]))

if app_api_version == parse("0.0.1"):
if client is not None:
raise RuntimeError(
"Cannot use existing client for apps with API version 0.0.1."
)
return _MarketPlaceApp_v0_0_1(
app_id,
marketplace_host_url=kwargs.get("marketplace_host_url"),
access_token=kwargs.get("access_token"),
capabilities=capabilities,
**kwargs,
)
elif parse("0.0.1") < app_api_version <= parse("0.3.0"):
if app_api_version < parse("1.0.0"):
return _MarketPlaceApp_v0(app_id, app_info, client, **kwargs)
else:
raise RuntimeError(f"App API version ({app_api_version}) not supported.")
Expand Down
Loading

0 comments on commit d81ef7b

Please sign in to comment.