Skip to content

Commit c11485d

Browse files
authored
Merge pull request #6 from nasa/release/0.6.0
Release/0.6.0
2 parents 3371df0 + a15e021 commit c11485d

File tree

7 files changed

+158
-9
lines changed

7 files changed

+158
-9
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This workflow will upload a Python Package using Twine when a release is created
2+
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Upload Python Package
10+
11+
on:
12+
release:
13+
types: [published]
14+
15+
jobs:
16+
deploy:
17+
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Set up Python
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: '3.x'
26+
- name: Install dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
pip install build
30+
- name: Build package
31+
run: python -m build
32+
- name: Publish package
33+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
34+
with:
35+
user: __token__
36+
password: ${{ secrets.POETRY_PYPI_TOKEN_PYPI }}

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.6.0]
10+
### Added
11+
- New support for querying variables (UMM-V)
12+
### Changed
13+
- Can now import `ToolQuery` `ServiceQuery` `VariableQuery` straight from cmr module. (e.g. `from cmr import ToolQuery`)
14+
915
## [0.5.0]
1016
### Added
1117
- New support for querying tools (UMM-T) and services (UMM-S)
@@ -16,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1622
## [Older]
1723
- Prior releases of this software originated from https://github.com/jddeal/python-cmr/releases
1824

19-
[Unreleased]: https://github.com/nasa/python_cmr/compare/v0.5.0...HEAD
25+
[Unreleased]: https://github.com/nasa/python_cmr/compare/v0.6.0...HEAD
26+
[0.6.0]: https://github.com/nasa/python_cmr/compare/v0.5.0...v0.6.0
2027
[0.5.0]: https://github.com/nasa/python_cmr/compare/ef0f9e7d67ce99d342a568bd6a098c3462df16d2...v0.5.0
2128
[Older]: https://github.com/jddeal/python-cmr/releases

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Python CMR is an easy to use wrapper to the NASA EOSDIS [Common Metadata Reposit
1111

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

14-
>>> from cmr import CollectionQuery, GranuleQuery
14+
>>> from cmr import CollectionQuery, GranuleQuery, ToolQuery, ServiceQuery, VariableQuery
1515

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

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

43-
$ git clone https://github.com/jddeal/python-cmr
43+
$ git clone https://github.com/nasa/python_cmr
4444
$ cd python-cmr
4545
$ pip install .
4646

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

141+
# Search via concept_id
142+
>>> api.concept_id('S1962070864-POCLOUD')
143+
141144
Tool searches support the following methods
142145

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

156+
# Search via concept_id
157+
>>> api.concept_id('TL2092786348-POCLOUD')
158+
159+
Variable searches support the following methods
160+
161+
# Search via provider
162+
>>> api = VariableQuery()
163+
>>> api.provider('POCLOUD')
164+
165+
# Search via native_id
166+
>>> api.native_id('JASON_CS_S6A_L2_AMR_RAD_STATIC_CALIBRATION-AMR_Side_1-acc_lat')
167+
168+
# Search via name
169+
>>> api.name('/AMR_Side_1/acc_lat')
170+
171+
# Search via concept_id
172+
>>> api.concept_id('V2112019824-POCLOUD')
173+
153174
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:
154175

155176
# search for AST_L1T version 003 granules at latitude 42, longitude -100

cmr/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from .queries import GranuleQuery, CollectionQuery
1+
from .queries import GranuleQuery, CollectionQuery, ToolQuery, ServiceQuery, VariableQuery
22

3-
__all__ = ["GranuleQuery", "CollectionQuery"]
3+
__all__ = ["GranuleQuery", "CollectionQuery", "ToolQuery", "ServiceQuery", "VariableQuery"]

cmr/queries.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def concept_id(self, IDs):
229229

230230
self.params["concept_id"] = IDs
231231

232+
return self
233+
232234
def provider(self, provider):
233235
"""
234236
Filter by provider.
@@ -755,7 +757,7 @@ def service_concept_id(self, IDs):
755757
def _valid_state(self):
756758
return True
757759

758-
class ToolServiceBaseQuery(Query):
760+
class ToolServiceVariableBaseQuery(Query):
759761
"""
760762
Base class for Tool and Service CMR queries.
761763
"""
@@ -824,7 +826,7 @@ def name(self, name):
824826
self.params['name'] = name
825827
return self
826828

827-
class ToolQuery(ToolServiceBaseQuery):
829+
class ToolQuery(ToolServiceVariableBaseQuery):
828830
"""
829831
Class for querying tools from the CMR.
830832
"""
@@ -840,7 +842,7 @@ def _valid_state(self):
840842
return True
841843

842844

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

857+
def _valid_state(self):
858+
return True
859+
860+
861+
class VariableQuery(ToolServiceVariableBaseQuery):
862+
def __init__(self, mode=CMR_OPS):
863+
Query.__init__(self, "variables", mode)
864+
self.concept_id_chars = ['V']
865+
self._valid_formats_regex.extend([
866+
"dif", "dif10", "opendata", "umm_json", "umm_json_v[0-9]_[0-9]"
867+
])
868+
855869
def _valid_state(self):
856870
return True

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="python-cmr",
5-
version="0.5.0",
5+
version="0.6.0",
66
license="MIT",
77
url="https://github.com/nasa/python_cmr",
88
description="Python wrapper to the NASA Common Metadata Repository (CMR) API.",

tests/test_variable.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import unittest
2+
3+
from cmr.queries import VariableQuery
4+
5+
class TestVariableClass(unittest.TestCase):
6+
7+
def test_name(self):
8+
query = VariableQuery()
9+
query.name("name")
10+
11+
self.assertIn("name", query.params)
12+
self.assertEqual(query.params["name"], "name")
13+
14+
def test_provider(self):
15+
query = VariableQuery()
16+
query.provider("provider")
17+
18+
self.assertIn("provider", query.params)
19+
self.assertEqual(query.params["provider"], "provider")
20+
21+
def test_native_id(self):
22+
query = VariableQuery()
23+
query.native_id("native_id")
24+
25+
self.assertIn("native_id", query.params)
26+
self.assertEqual(query.params["native_id"], ["native_id"])
27+
28+
def test_native_ids(self):
29+
query = VariableQuery()
30+
query.native_id(["native_id1", "native_id2"])
31+
32+
self.assertIn("native_id", query.params)
33+
self.assertEqual(query.params["native_id"], ["native_id1", "native_id2"])
34+
35+
def test_valid_formats(self):
36+
query = VariableQuery()
37+
formats = [
38+
"json", "xml", "echo10", "iso", "iso19115",
39+
"csv", "atom", "kml", "native", "dif", "dif10",
40+
"opendata", "umm_json", "umm_json_v1_1" "umm_json_v1_9"]
41+
42+
for _format in formats:
43+
query.format(_format)
44+
self.assertEqual(query._format, _format)
45+
46+
def test_invalid_format(self):
47+
query = VariableQuery()
48+
49+
with self.assertRaises(ValueError):
50+
query.format("invalid")
51+
query.format("jsonn")
52+
query.format("iso19116")
53+
54+
def test_valid_concept_id(self):
55+
query = VariableQuery()
56+
57+
query.concept_id("V1299783579-LPDAAC_ECS")
58+
self.assertEqual(query.params["concept_id"], ["V1299783579-LPDAAC_ECS"])
59+
60+
query.concept_id(["V1299783579-LPDAAC_ECS", "V1441380236-PODAAC"])
61+
self.assertEqual(query.params["concept_id"], ["V1299783579-LPDAAC_ECS", "V1441380236-PODAAC"])
62+
63+
def test_invalid_concept_id(self):
64+
query = VariableQuery()
65+
66+
with self.assertRaises(ValueError):
67+
query.concept_id("G1327299284-LPDAAC_ECS")
68+
69+
with self.assertRaises(ValueError):
70+
query.concept_id(["C1299783579-LPDAAC_ECS", "G1327299284-LPDAAC_ECS"])
71+

0 commit comments

Comments
 (0)