Skip to content

Commit

Permalink
Merge pull request #87 from MAAP-Project/develop
Browse files Browse the repository at this point in the history
Develop into master
  • Loading branch information
bsatoriu authored Apr 3, 2024
2 parents 095869b + 5f4c43e commit ea8c575
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 184 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include maap/dps/*.xml
include maap/dps/*.xml
6 changes: 3 additions & 3 deletions doc.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
******
maapPy
******
*******
maap-py
*******

# Python MAAP Client Library

Expand Down
1 change: 1 addition & 0 deletions maap/config_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, maap_host=None, config_file_path=''):
self.__config = ConfigParser()
configfile_present = False
config_paths = list(map(self.__get_config_path, [os.path.dirname(config_file_path), os.curdir, os.path.expanduser("~"), os.environ.get("MAAP_CONF") or '.']))

for loc in config_paths:
try:
with open(loc) as source:
Expand Down
20 changes: 8 additions & 12 deletions maap/dps/DpsHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import requests
import xml.etree.ElementTree as ET
import logging
import os
import json
from os.path import exists

import importlib_resources as resources


class DpsHelper:
DPS_INTERNAL_FILE_JOB = "_job.json"
Expand All @@ -16,7 +17,6 @@ class DpsHelper:
"""
def __init__(self, api_header, dps_token_endpoint):
self._api_header = api_header
self._location = os.path.dirname(os.path.abspath(__file__))
self._logger = logging.getLogger(__name__)
self.dps_token_endpoint = dps_token_endpoint
self.running_in_dps = self._running_in_dps_mode()
Expand All @@ -35,9 +35,9 @@ def _skit(self, lines, kwargs):
return res

def submit_job(self, request_url, **kwargs):
xml_file = os.path.join(self._location, 'execute.xml')
input_xml = os.path.join(self._location, 'execute_inputs.xml')
xml_file = resources.files("maap.dps").joinpath("execute.xml")
input_xml = resources.files("maap.dps").joinpath("execute_inputs.xml")

# ==================================
# Part 1: Parse Required Arguments
# ==================================
Expand Down Expand Up @@ -81,23 +81,19 @@ def submit_job(self, request_url, **kwargs):
ins_xml = ''

other = ''
with open(input_xml) as xml:
ins_xml = xml.read()
ins_xml = input_xml.read_text()

# -------------------------------
# Insert XML for algorithm inputs
# -------------------------------
for key in input_names:
other += ins_xml.format(name=key).format(value=input_names[key])
other += ins_xml.format(name=key, value=input_names[key])
other += '\n'

# print(other)
params['other_inputs'] = other

with open(xml_file) as xml:
req_xml = xml.read()

req_xml = req_xml.format(**params)
req_xml = xml_file.read_text().format(**params)

# log request body
logging.debug('request is')
Expand Down
17 changes: 6 additions & 11 deletions maap/dps/dps_job_model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
import os
from datetime import datetime
import xml.etree.ElementTree as ET

import importlib_resources as resources
import requests

from maap.config_reader import ConfigReader
Expand Down Expand Up @@ -37,18 +37,16 @@ def __init__(self, not_self_signed=False):
self.__algorithm_version = None
self.__username = 'anonymous'
self.__inputs = {}
current_location = os.path.dirname(os.path.abspath(__file__))
self.__xml_file = os.path.join(current_location, 'execute.xml')
self.__input_xml = os.path.join(current_location, 'execute_inputs.xml')
self.__xml_file = resources.files("maap.dps").joinpath("execute.xml")
self.__input_xml = resources.files("maap.dps").joinpath("execute_inputs.xml")

def with_param(self, key, val):
self.__inputs[key] = val
return self

def __generate_xml_inputs(self):
with open(self.__input_xml) as xml:
input_xml = xml.read()
input_xmls = [input_xml.format(name=k).format(value=v) for k, v in self.__inputs.items()]
input_xml = self.__input_xml.read_text()
input_xmls = [input_xml.format(name=k, value=v) for k, v in self.__inputs.items()]
return '\n'.join(input_xmls)

def generate_request_xml(self):
Expand All @@ -61,10 +59,7 @@ def generate_request_xml(self):
'inputs': '', # TODO this is needed?
'other_inputs': self.__generate_xml_inputs(),
}
with open(self.__xml_file) as xml:
request_xml = xml.read()
request_xml = request_xml.format(**params)
return request_xml
return self.__xml_file.read_text().format(**params)

def submit_job(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions maap/dps/execute_inputs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<wps:Input id="{name}">
<wps:Data>
<wps:LiteralValue>{{value}}</wps:LiteralValue>
<wps:LiteralValue><![CDATA[{value}]]></wps:LiteralValue>
</wps:Data>
</wps:Input>
</wps:Input>
9 changes: 6 additions & 3 deletions maap/maap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import uuid
import urllib.parse
import os
from mapboxgl.utils import *
from mapboxgl.viz import *
import sys

import importlib_resources as resources
import requests
from .Result import Collection, Granule, Result
from maap.config_reader import ConfigReader
from maap.dps.dps_job import DPSJob
Expand Down Expand Up @@ -386,6 +388,8 @@ def _get_capabilities(self, granule_ur):
return response

def show(self, granule, display_config={}):
from mapboxgl.viz import RasterTilesViz

granule_ur = granule['Granule']['GranuleUR']
browse_file = json.loads(self._get_browse(granule_ur).text)['browse']
capabilities = json.loads(self._get_capabilities(granule_ur).text)['body']
Expand All @@ -409,4 +413,3 @@ def show(self, granule, display_config={}):

if __name__ == "__main__":
print("initialized")

56 changes: 0 additions & 56 deletions maap/utils/HTTPServerHandler.py

This file was deleted.

39 changes: 0 additions & 39 deletions maap/utils/TokenHandler.py

This file was deleted.

17 changes: 0 additions & 17 deletions requirements.txt

This file was deleted.

92 changes: 58 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,59 @@

# Package data
# ------------
_author = 'Jet Propulsion Laboratory'
_author_email = '[email protected]'
_author = "Jet Propulsion Laboratory"
_author_email = "[email protected]"
_classifiers = [
'Environment :: Console',
'Framework :: Pytest',
'Intended Audience :: Developers',
'Intended Audience :: Information Technology',
'Intended Audience :: Science/Research',
'Topic :: Scientific/Engineering',
'Development Status :: 3 - Alpha',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries :: Python Modules',
"Environment :: Console",
"Framework :: Pytest",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering",
"Development Status :: 3 - Alpha",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.5",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",
]
_description = 'maapPy Python API'
_download_url = ''
_requirements = ["backoff", "boto3==1.33.13", "ConfigParser", "ipython==8.12.0", "mapboxgl", "moto", "mypy_boto3_s3", "pytest",
"PyYAML", "requests", "responses", "setuptools"]
_keywords = ['dataset', 'granule', 'nasa', 'MAAP', 'CMR']
_license = 'Apache License, Version 2.0'
_long_description = 'Python client API for interacting with the NASA MAAP API'
_name = 'maapPy'
_namespaces = []
_test_suite = ''
_url = 'https://github.com/MAAP-Project/maap-py'
_version = '3.1.4'
_description = "maapPy Python API"
_download_url = ""
_boto3_version = "1.34.41"
_requirements = [
"backoff~=2.2",
f"boto3~={_boto3_version}",
"ConfigParser~=6.0",
"importlib_resources~=6.0",
# We must explicitly specify ipython because mapboxgl requires it, but
# does not specify it in its own requirements. This is a bug in mapboxgl
# that has been fixed, but the fix has not been released even though it was
# fixed in 2019. See https://github.com/mapbox/mapboxgl-jupyter/pull/172.
"ipython==8.11.0",
"mapboxgl~=0.10",
"PyYAML~=6.0",
"requests~=2.31",
"setuptools~=69.0",
]
_extra_requirements = {
"dev": [
f"boto3-stubs[s3]~={_boto3_version}",
"moto~=4.2",
"mypy~=1.8",
"pytest~=7.4",
"responses~=0.24",
"types-requests~=2.31",
"types-PyYAML~=6.0",
]
}
_keywords = ["dataset", "granule", "nasa", "MAAP", "CMR"]
_license = "Apache License, Version 2.0"
_long_description = "Python client API for interacting with the NASA MAAP API"
_name = "maap-py"
_namespaces: list[str] = []
_test_suite = ""
_url = "https://github.com/MAAP-Project/maap-py"
_version = "3.1.5"
_zip_safe = False

# Setup Metadata
Expand All @@ -42,12 +67,11 @@ def _read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()


_header = '*' * len(_name) + '\n' + _name + '\n' + '*' * len(_name)
_longDescription = '\n\n'.join([
_header,
_read('README.md')
])
open('doc.txt', 'w').write(_longDescription)
_header = "*" * len(_name) + "\n" + _name + "\n" + "*" * len(_name)
_longDescription = "\n\n".join([_header, _read("README.md")])

with open("doc.txt", "w") as doc:
doc.write(_longDescription)

setup(
author=_author,
Expand All @@ -56,9 +80,9 @@ def _read(*rnames):
description=_description,
download_url=_download_url,
include_package_data=True,
setup_requires=["pytest-runner"],
install_requires=_requirements,
setup_requires=['pytest-runner'],
tests_require=['pytest', 'responses', 'moto'],
extras_require=_extra_requirements,
keywords=_keywords,
license=_license,
long_description=_long_description,
Expand Down
Loading

0 comments on commit ea8c575

Please sign in to comment.