Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace #18

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"""
"""
# ==============================================================================
from setuptools import setup, find_packages, Extension, Command
from setuptools import setup, find_namespace_packages

# ==============================================================================

pkg_root_dir = 'src'
packages = find_packages(pkg_root_dir)
packages = find_namespace_packages(where='src', include=['openalea', 'openalea.*'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace

find_namespace_packages(where='src', include=['openalea', 'openalea.*'])

by

find_namespace_packages(where='src', include=['openalea.*'])

This is my fault.

top_pkgs = [pkg for pkg in packages if len(pkg.split('.')) <= 2]
package_dir = dict([('', pkg_root_dir)] +
[(pkg, pkg_root_dir + "/" + pkg.replace('.', '/'))
Expand Down
48 changes: 0 additions & 48 deletions src/agroservices/__init__.py

This file was deleted.

49 changes: 32 additions & 17 deletions src/agroservices/ipm/ipm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,32 @@
################## Interface Python IPM using Bioservice ########################################################

import json
from jsf import JSF
from typing import Union
from pathlib import Path
from agroservices.services import REST
from agroservices.ipm.datadir import datadir
from typing import Union

import agroservices.ipm.fakers as fakers
import agroservices.ipm.fixes as fixes
from agroservices.ipm.datadir import datadir
from agroservices.services import REST

__all__ = ["IPM"]


def load_model(dssid, model):
model = fixes.fix_prior_load_model(dssid, model)
if 'input_schema' in model['execution']:
model['execution']['input_schema'] = json.loads(model['execution']['input_schema'])
model['execution']['input_schema'] = json.loads(
model['execution']['input_schema'])
model = fixes.fix_load_model(dssid, model)
return model


def read_dss(dss):
dss['models'] = {model["id"]: load_model(dss['id'], model) for model in dss["models"]}
dss['models'] = {model["id"]: load_model(dss['id'], model) for model in
dss["models"]}
return dss


class IPM(REST):
"""
Interface to the IPM https://ipmdecisions.nibio.no/
Expand Down Expand Up @@ -79,7 +84,8 @@ class IPM(REST):
>>> ipm.post_schema_dss_yaml_validate()
"""

def __init__(self, name='IPM', url="https://platform.ipmdecisions.net", callback=None, *args, **kwargs):
def __init__(self, name='IPM', url="https://platform.ipmdecisions.net",
callback=None, *args, **kwargs):
"""Constructor

Parameters
Expand All @@ -90,7 +96,7 @@ def __init__(self, name='IPM', url="https://platform.ipmdecisions.net", callback
Use cache, by default False
"""
# hack ipmdecisions.net is down
#url = 'https://ipmdecisions.nibio.no'
# url = 'https://ipmdecisions.nibio.no'
super().__init__(
name=name,
url=url,
Expand Down Expand Up @@ -154,7 +160,8 @@ def get_schema_weatherdata(self) -> dict:

# schema weather data validate

def post_schema_weatherdata_validate(self, jsonfile: Union[str, Path] = 'weather_data.json') -> dict:
def post_schema_weatherdata_validate(self, jsonfile: Union[
str, Path] = 'weather_data.json') -> dict:
"""Validates the posted weather data against the Json schema

Parameters
Expand All @@ -180,7 +187,8 @@ def post_schema_weatherdata_validate(self, jsonfile: Union[str, Path] = 'weather

###################### WeatherAdaptaterService #############################

def get_weatheradapter(self, source: dict, params: dict = None, credentials: dict = None) -> dict:
def get_weatheradapter(self, source: dict, params: dict = None,
credentials: dict = None) -> dict:
"""Call weatheradapter service for a given weatherdata source

Parameters
Expand Down Expand Up @@ -208,7 +216,8 @@ def get_weatheradapter(self, source: dict, params: dict = None, credentials: dic
if params is None:
params = fakers.weather_adapter_params(source)

endpoint = source['endpoint'].format(WEATHER_API_URL=self._url + '/api/wx')
endpoint = source['endpoint'].format(
WEATHER_API_URL=self._url + '/api/wx')

if not source['authentication_type'] == 'CREDENTIALS':
res = self.http_get(endpoint, params=params, frmt='json')
Expand All @@ -222,7 +231,8 @@ def get_weatheradapter(self, source: dict, params: dict = None, credentials: dic

# weatherdatasource

def get_weatherdatasource(self, source_id=None, access_type=None, authentication_type=None) -> list:
def get_weatherdatasource(self, source_id=None, access_type=None,
authentication_type=None) -> list:
"""Access a dict of available wetherdata sources, of a source referenced by its id

Parameters
Expand Down Expand Up @@ -250,23 +260,27 @@ def get_weatherdatasource(self, source_id=None, access_type=None, authentication
for r in res:
if 'geoJSON' in r['spatial']:
if r['spatial']['geoJSON'] is not None:
r['spatial']['geoJSON'] = json.loads(r['spatial']['geoJSON'])
r['spatial']['geoJSON'] = json.loads(
r['spatial']['geoJSON'])

sources = {item['id']: item for item in res}
sources = fixes.fix_get_weatherdatasource(sources)

if source_id is None:
res = sources
if access_type is not None:
res = {k: v for k, v in res.items() if v['access_type'] == access_type}
res = {k: v for k, v in res.items() if
v['access_type'] == access_type}
if authentication_type is not None:
res = {k: v for k, v in res.items() if v['authentication_type'] == authentication_type}
res = {k: v for k, v in res.items() if
v['authentication_type'] == authentication_type}
return res
elif source_id in sources:
return sources[source_id]
else:
raise ValueError(
"datasource error: source_id is not referencing a valid datasource: %s" % (','.join(sources.keys())))
"datasource error: source_id is not referencing a valid datasource: %s" % (
','.join(sources.keys())))

def post_weatherdatasource_location(
self,
Expand Down Expand Up @@ -402,7 +416,8 @@ def get_dss(self, execution_type=None) -> dict:
if execution_type is not None:
filtered = {}
for id, dss in all_dss.items():
models = {k:v for k,v in dss['models'].items() if v['execution']['type'] == execution_type}
models = {k: v for k, v in dss['models'].items() if
v['execution']['type'] == execution_type}
if len(models) > 0:
dss['models'] = models
filtered[id] = dss
Expand Down
Loading
Loading