Skip to content

Commit

Permalink
Merge pull request #18 from AurelienBesnier/namespace
Browse files Browse the repository at this point in the history
Namespace
  • Loading branch information
pradal authored Mar 20, 2024
2 parents 930e4a0 + 0f7e1f1 commit e251c8d
Show file tree
Hide file tree
Showing 6 changed files with 488 additions and 482 deletions.
73 changes: 12 additions & 61 deletions .github/workflows/conda-package-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,17 @@ name: build_publish_anaconda

on:
push:
branches: [ master ]
branches:
- '**'
tags:
- 'v*'
pull_request:
branches: [ master ]

jobs:
build-and-publish:
name: ${{ matrix.os }}, Python 3.${{ matrix.python-minor-version }} for conda deployment
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
max-parallel: 3
matrix:
os: [ ubuntu-latest ]
python-minor-version: [9]
isMaster:
- ${{ github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/dev') }}
exclude:
- isMaster: false
os: ubuntu-latest
python-minor-version: 7
- isMaster: false
os: ubuntu-latest
python-minor-version: 8
- isMaster: false
os: macos-latest
python-minor-version: 7
- isMaster: false
os: macos-latest
python-minor-version: 8
- isMaster: false
os: macos-latest
python-minor-version: 9
- isMaster: false
os: windows-latest
python-minor-version: 7
- isMaster: false
os: windows-latest
python-minor-version: 8
- isMaster: false
os: windows-latest
python-minor-version: 9
branches:
- '**'


steps:
- name: Chekout
uses: actions/checkout@v3
- name: Determine publish
uses: haya14busa/action-cond@v1
id: publish
with:
cond: ${{ contains(github.ref, 'master') || startsWith(github.ref, 'refs/heads/v') }}
if_true: 'true'
if_false: 'false'
- name: Build and Publish
uses: openalea/[email protected]
with:
conda: conda
mamba: true
python: ${{ matrix.python-minor-version }}
numpy: '20.0'
channels: openalea3, conda-forge
token: ${{ secrets.ANACONDA_TOKEN }}
publish: ${{ steps.publish.outputs.value }}
label: main
jobs:
build:
uses: openalea/github-action-conda-build/.github/workflows/conda-package-build.yml@main
secrets:
anaconda_token: ${{ secrets.ANACONDA_TOKEN }}
20 changes: 8 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +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)
top_pkgs = [pkg for pkg in packages if len(pkg.split('.')) <= 2]
package_dir = dict([('', pkg_root_dir)] +
[(pkg, pkg_root_dir + "/" + pkg.replace('.', '/'))
for pkg in top_pkgs])

packages = find_namespace_packages(where='src', include=['openalea.*'])
name = "agroservices"

_version = {}
Expand All @@ -41,9 +37,9 @@
This package is intended to be close to the webservice.
Therefore the requests will have the same API that each web service.
'''
author= 'Christian Fournier, Marc Labadie, Christophe Pradal'
url='https://github.com/H2020-IPM-openalea/agroservices'
license="GPL-v3"
author = 'Christian Fournier, Marc Labadie, Christophe Pradal'
url = 'https://github.com/H2020-IPM-openalea/agroservices'
license = "CeCILL-C"

setup(
name=name,
Expand All @@ -59,9 +55,9 @@

# package installation
packages=packages,
package_dir=package_dir,
package_dir={'': 'src'},
zip_safe=False,

# See MANIFEST.in
include_package_data=True,
)
)
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

0 comments on commit e251c8d

Please sign in to comment.