Skip to content

Commit

Permalink
Merge pull request #6 from nasa/release/0.6.0
Browse files Browse the repository at this point in the history
Release/0.6.0
  • Loading branch information
frankinspace authored Oct 28, 2021
2 parents 3371df0 + a15e021 commit c11485d
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 9 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.POETRY_PYPI_TOKEN_PYPI }}
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.6.0]
### Added
- New support for querying variables (UMM-V)
### Changed
- Can now import `ToolQuery` `ServiceQuery` `VariableQuery` straight from cmr module. (e.g. `from cmr import ToolQuery`)

## [0.5.0]
### Added
- New support for querying tools (UMM-T) and services (UMM-S)
Expand All @@ -16,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Older]
- Prior releases of this software originated from https://github.com/jddeal/python-cmr/releases

[Unreleased]: https://github.com/nasa/python_cmr/compare/v0.5.0...HEAD
[Unreleased]: https://github.com/nasa/python_cmr/compare/v0.6.0...HEAD
[0.6.0]: https://github.com/nasa/python_cmr/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/nasa/python_cmr/compare/ef0f9e7d67ce99d342a568bd6a098c3462df16d2...v0.5.0
[Older]: https://github.com/jddeal/python-cmr/releases
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Python CMR is an easy to use wrapper to the NASA EOSDIS [Common Metadata Reposit

Getting access to NASA's earth science metadata is as simple as this:

>>> from cmr import CollectionQuery, GranuleQuery
>>> from cmr import CollectionQuery, GranuleQuery, ToolQuery, ServiceQuery, VariableQuery

>>> api = CollectionQuery()
>>> collections = api.archive_center("LP DAAC").keyword("AST_L1*").get(5)
Expand Down Expand Up @@ -40,7 +40,7 @@ To install from pypi:

To install from github, perhaps to try out the dev branch:

$ git clone https://github.com/jddeal/python-cmr
$ git clone https://github.com/nasa/python_cmr
$ cd python-cmr
$ pip install .

Expand Down Expand Up @@ -138,6 +138,9 @@ Service searches support the following methods
# Search via name
>>> api.name('PODAAC L2 Cloud Subsetter')

# Search via concept_id
>>> api.concept_id('S1962070864-POCLOUD')

Tool searches support the following methods

# Search via provider
Expand All @@ -150,6 +153,24 @@ Tool searches support the following methods
# Search via name
>>> api.name('hitide')

# Search via concept_id
>>> api.concept_id('TL2092786348-POCLOUD')

Variable searches support the following methods

# Search via provider
>>> api = VariableQuery()
>>> api.provider('POCLOUD')

# Search via native_id
>>> api.native_id('JASON_CS_S6A_L2_AMR_RAD_STATIC_CALIBRATION-AMR_Side_1-acc_lat')

# Search via name
>>> api.name('/AMR_Side_1/acc_lat')

# Search via concept_id
>>> api.concept_id('V2112019824-POCLOUD')

As an alternative to chaining methods together to set the parameters of your query, a method exists to allow you to pass your parameters as keyword arguments:

# search for AST_L1T version 003 granules at latitude 42, longitude -100
Expand Down
4 changes: 2 additions & 2 deletions cmr/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .queries import GranuleQuery, CollectionQuery
from .queries import GranuleQuery, CollectionQuery, ToolQuery, ServiceQuery, VariableQuery

__all__ = ["GranuleQuery", "CollectionQuery"]
__all__ = ["GranuleQuery", "CollectionQuery", "ToolQuery", "ServiceQuery", "VariableQuery"]
20 changes: 17 additions & 3 deletions cmr/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def concept_id(self, IDs):

self.params["concept_id"] = IDs

return self

def provider(self, provider):
"""
Filter by provider.
Expand Down Expand Up @@ -755,7 +757,7 @@ def service_concept_id(self, IDs):
def _valid_state(self):
return True

class ToolServiceBaseQuery(Query):
class ToolServiceVariableBaseQuery(Query):
"""
Base class for Tool and Service CMR queries.
"""
Expand Down Expand Up @@ -824,7 +826,7 @@ def name(self, name):
self.params['name'] = name
return self

class ToolQuery(ToolServiceBaseQuery):
class ToolQuery(ToolServiceVariableBaseQuery):
"""
Class for querying tools from the CMR.
"""
Expand All @@ -840,7 +842,7 @@ def _valid_state(self):
return True


class ServiceQuery(ToolServiceBaseQuery):
class ServiceQuery(ToolServiceVariableBaseQuery):
"""
Class for querying services from the CMR.
"""
Expand All @@ -852,5 +854,17 @@ def __init__(self, mode=CMR_OPS):
"dif", "dif10", "opendata", "umm_json", "umm_json_v[0-9]_[0-9]"
])

def _valid_state(self):
return True


class VariableQuery(ToolServiceVariableBaseQuery):
def __init__(self, mode=CMR_OPS):
Query.__init__(self, "variables", mode)
self.concept_id_chars = ['V']
self._valid_formats_regex.extend([
"dif", "dif10", "opendata", "umm_json", "umm_json_v[0-9]_[0-9]"
])

def _valid_state(self):
return True
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="python-cmr",
version="0.5.0",
version="0.6.0",
license="MIT",
url="https://github.com/nasa/python_cmr",
description="Python wrapper to the NASA Common Metadata Repository (CMR) API.",
Expand Down
71 changes: 71 additions & 0 deletions tests/test_variable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import unittest

from cmr.queries import VariableQuery

class TestVariableClass(unittest.TestCase):

def test_name(self):
query = VariableQuery()
query.name("name")

self.assertIn("name", query.params)
self.assertEqual(query.params["name"], "name")

def test_provider(self):
query = VariableQuery()
query.provider("provider")

self.assertIn("provider", query.params)
self.assertEqual(query.params["provider"], "provider")

def test_native_id(self):
query = VariableQuery()
query.native_id("native_id")

self.assertIn("native_id", query.params)
self.assertEqual(query.params["native_id"], ["native_id"])

def test_native_ids(self):
query = VariableQuery()
query.native_id(["native_id1", "native_id2"])

self.assertIn("native_id", query.params)
self.assertEqual(query.params["native_id"], ["native_id1", "native_id2"])

def test_valid_formats(self):
query = VariableQuery()
formats = [
"json", "xml", "echo10", "iso", "iso19115",
"csv", "atom", "kml", "native", "dif", "dif10",
"opendata", "umm_json", "umm_json_v1_1" "umm_json_v1_9"]

for _format in formats:
query.format(_format)
self.assertEqual(query._format, _format)

def test_invalid_format(self):
query = VariableQuery()

with self.assertRaises(ValueError):
query.format("invalid")
query.format("jsonn")
query.format("iso19116")

def test_valid_concept_id(self):
query = VariableQuery()

query.concept_id("V1299783579-LPDAAC_ECS")
self.assertEqual(query.params["concept_id"], ["V1299783579-LPDAAC_ECS"])

query.concept_id(["V1299783579-LPDAAC_ECS", "V1441380236-PODAAC"])
self.assertEqual(query.params["concept_id"], ["V1299783579-LPDAAC_ECS", "V1441380236-PODAAC"])

def test_invalid_concept_id(self):
query = VariableQuery()

with self.assertRaises(ValueError):
query.concept_id("G1327299284-LPDAAC_ECS")

with self.assertRaises(ValueError):
query.concept_id(["C1299783579-LPDAAC_ECS", "G1327299284-LPDAAC_ECS"])

0 comments on commit c11485d

Please sign in to comment.