Skip to content

Commit

Permalink
MSD-4058 - Replace native ID spaces with underscores.
Browse files Browse the repository at this point in the history
  • Loading branch information
owenlittlejohns authored Oct 30, 2024
1 parent bee6cb2 commit d5d66cd
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.9', '3.10', '3.11' ]
python-version: [ '3.9', '3.10', '3.11', '3.12' ]
fail-fast: false

steps:
Expand All @@ -30,7 +30,7 @@ jobs:
uses: actions/upload-artifact@v3
with:
name: Test results for Python ${{ matrix.python-version }}
path: tests/reports/
path: tests/reports/earthdata-varinfo_junit.xml

- name: Archive coverage report
uses: actions/upload-artifact@v3
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## v3.0.1
### 2024-10-18

### Changed:

* CMR native IDs generated from variable names with spaces in them will replace
those space characters with underscores to avoid errors when trying to ingest
such variables.
* The `python-cmr` requirement is updated to v0.12.0, which adds type hints for
that package. A couple of type hints in `earthdata-varinfo` have been updated
accordingly.
* The `numpy` requirement has been relaxed to allow broader compatibility with
client software. Note: This enables Python 3.12 compatibility.
* To ensure compatibility with Python 3.12, the tests are now run using
`pytest`. This allows JUnit style output to be produced, as the previously
used `unittets-xml-runner` package was not compatible with Python 3.12. The
tests themselves are still written using classes and syntax from `unittest`.
The CI/CD for running the tests has been updated to also run the tests under
Python 3.12.

## v3.0.0
### 2024-09-11

Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ prepare-test:
mkdir -p tests/reports tests/coverage

test: prepare-test
coverage run -m xmlrunner discover tests -o tests/reports
coverage html --omit="*tests/*" -d tests/coverage
pytest --junitxml=tests/reports/earthdata-varinfo_junit.xml --cov varinfo --cov-report html:tests/coverage --cov-report term
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ for a PR review):
$ make lint
```

Run `unittest` suite:
Run `unittest` suite (run via `pytest`, but written using `unittest` classes):

```bash
$ make test
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0
3.0.1
4 changes: 2 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
coverage ~= 5.5
ipython ~= 8.0.1
jsonschema ~= 4.17.3
pre-commit ~= 3.7.0
pycodestyle ~= 2.11.0
pylint >= 2.5.0
unittest-xml-reporting ~= 3.0.4
pytest ~= 8.3.3
pytest-cov ~= 5.0.0
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
netCDF4 ~= 1.6.3
numpy ~= 1.24.2
python-cmr ~= 0.9.0
numpy >= 1.24.2,< 2.0
python-cmr ~= 0.12.0
requests ~= 2.31.0
7 changes: 7 additions & 0 deletions tests/unit/test_umm_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,13 @@ def test_generate_variable_native_id(self):
'C1234567890-PROV-Grid_time',
)

with self.subTest('Space in variable name is replaced with underscore'):
umm_var_json = {'Name': '/Grid/variable with space'}
self.assertEqual(
generate_variable_native_id('C1234567890-PROV', umm_var_json),
'C1234567890-PROV-Grid_variable_with_space',
)

def test_get_variable_type(self):
"""Test that 'VariableType' in a UMM-Var record is set to
'SCIENCE_VARIABLE', when a variable is a science variable.
Expand Down
11 changes: 6 additions & 5 deletions varinfo/cmr_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from __future__ import annotations

from collections.abc import Sequence
from typing import Literal
import os.path

Expand Down Expand Up @@ -36,7 +37,7 @@ def get_granules(
provider: str | None = None,
cmr_env: CmrEnvType = CMR_OPS,
auth_header: str | None = None,
) -> list:
) -> Sequence:
"""Search CMR to retrieve granules for a specific collection given:
* concept_id: a CMR collection or granule concept ID. For most
Expand Down Expand Up @@ -79,7 +80,7 @@ def get_granules(
# If neither condition is met, there aren't enough CMR query parameters
# to identify the collection.
raise MissingPositionalArguments(
'concept_id or collection_shortname, ' 'collection_version, and provider'
'concept_id or collection_shortname, collection_version, and provider'
)

# Assign parameters to GranuleQuery
Expand All @@ -98,13 +99,13 @@ def get_granules(
if len(granule_response) == 0:
# No granules were identified, so no files can be downloaded and parsed
raise IndexError(
'No granules were found with selected ' 'parameters and user permissions'
'No granules were found with selected parameters and user permissions'
)

return granule_response


def get_granule_link(granule_response: list) -> str:
def get_granule_link(granule_response: Sequence) -> str:
"""Get the granule download link from CMR."""
granule_link = next(
(
Expand Down Expand Up @@ -164,7 +165,7 @@ def get_edl_token_from_launchpad(
<Launchpad token>
* cmr_env/mode: CMR environments (OPS, UAT, and SIT)
"""
url_urs_endpoint = urs_token_endpoints.get(cmr_env)
url_urs_endpoint = urs_token_endpoints[cmr_env]
try:
response = requests.post(
url=url_urs_endpoint, data=f'token={launchpad_token}', timeout=10
Expand Down
5 changes: 4 additions & 1 deletion varinfo/umm_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,10 @@ def generate_variable_native_id(
"""
return '-'.join(
[collection_concept_id, umm_var_record['Name'].replace('/', '_').lstrip('_')]
[
collection_concept_id,
umm_var_record['Name'].replace('/', '_').replace(' ', '_').lstrip('_'),
]
)


Expand Down

0 comments on commit d5d66cd

Please sign in to comment.