Skip to content

Commit

Permalink
Merge pull request #260 from ASFHyP3/develop
Browse files Browse the repository at this point in the history
Release v6.0.0
  • Loading branch information
jtherrmann authored Feb 2, 2024
2 parents 066cd49 + 8e75f75 commit c69abf8
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ on:

jobs:
call-changelog-check-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-changelog-check.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-changelog-check.yml@v0.9.0
secrets:
USER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/create-jira-issue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
call-create-jira-issue-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-create-jira-issue.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-create-jira-issue.yml@v0.9.0
secrets:
JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
call-version-info-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-version-info.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-version-info.yml@v0.9.0

distribute:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/labeled-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ on:

jobs:
call-labeled-pr-check-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-labeled-pr-check.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-labeled-pr-check.yml@v0.9.0
2 changes: 1 addition & 1 deletion .github/workflows/release-template-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
call-release-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-release-checklist-comment.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-release-checklist-comment.yml@v0.9.0
permissions:
pull-requests: write
secrets:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
call-release-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-release.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-release.yml@v0.9.0
with:
release_prefix: HyP3 SDK
secrets:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on: push

jobs:
call-flake8-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-flake8.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-flake8.yml@v0.9.0
with:
local_package_names: hyp3_sdk

call-secrets-analysis-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-secrets-analysis.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-secrets-analysis.yml@v0.9.0
2 changes: 1 addition & 1 deletion .github/workflows/tag-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ on:

jobs:
call-bump-version-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-bump-version.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-bump-version.yml@v0.9.0
secrets:
USER_TOKEN: ${{ secrets.TOOLS_BOT_PAK }}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ on:

jobs:
call-pytest-workflow:
uses: ASFHyP3/actions/.github/workflows/reusable-pytest.yml@v0.8.3
uses: ASFHyP3/actions/.github/workflows/reusable-pytest.yml@v0.9.0
with:
local_package_name: hyp3_sdk
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [6.0.0]
This release accommodates changes to the HyP3 API schema introduced in HyP3 v6.0.0

### Added
* `credit_cost` attribute to the `Job` class
* `HyP3.check_credits` method to determine your remaining processing credits

### Changed
* `HyP3.my_info()`: A new `remaining_credits` field replaces the `quota` field in the return value
* `HyP3.check_quota` may return a float or an integer if the user has processing credits

### Deprecated
* `HyP3.check_quota` has been deprecated in favor of `HyP3.check_credits`

## [5.0.0]
### Removed
* `legacy` option for the `dem_name` argument of `HyP3.prepare_rtc_job()` and `HyP3.submit_rtc_job()`.
Expand Down
17 changes: 14 additions & 3 deletions src/hyp3_sdk/hyp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from getpass import getpass
from typing import List, Literal, Optional, Union
from urllib.parse import urljoin
from warnings import warn

import hyp3_sdk
import hyp3_sdk.util
Expand Down Expand Up @@ -487,10 +488,20 @@ def my_info(self) -> dict:
_raise_for_hyp3_status(response)
return response.json()

def check_quota(self) -> Optional[int]:
def check_credits(self) -> Union[float, int, None]:
"""
Returns:
The number of jobs left in your quota, or None if you have no quota
Your remaining processing credits, or None if you have no processing limit
"""
info = self.my_info()
return info['quota']['remaining']
return info['remaining_credits']

def check_quota(self) -> Union[float, int, None]:
"""Deprecated method for checking your remaining processing credits; replaced by `HyP3.check_credits`
Returns:
Your remaining processing credits, or None if you have no processing limit
"""
warn('This method is deprecated and will be removed in a future release.\n'
'Please use `HyP3.check_credits` instead.', DeprecationWarning, stacklevel=2)
return self.check_credits()
3 changes: 3 additions & 0 deletions src/hyp3_sdk/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
thumbnail_images: Optional[List] = None,
expiration_time: Optional[datetime] = None,
processing_times: Optional[List[float]] = None,
credit_cost: Optional[float] = None,
):
self.job_id = job_id
self.job_type = job_type
Expand All @@ -45,6 +46,7 @@ def __init__(
self.thumbnail_images = thumbnail_images
self.expiration_time = expiration_time
self.processing_times = processing_times
self.credit_cost = credit_cost

def __repr__(self):
return f'Job.from_dict({self.to_dict()})'
Expand Down Expand Up @@ -72,6 +74,7 @@ def from_dict(input_dict: dict):
thumbnail_images=input_dict.get('thumbnail_images'),
expiration_time=expiration_time,
processing_times=input_dict.get('processing_times'),
credit_cost=input_dict.get('credit_cost'),
)

def to_dict(self, for_resubmit: bool = False):
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def default_job(
files=None,
browse_images=None,
thumbnail_images=None,
expiration_time=None
expiration_time=None,
credit_cost=None,
):
if job_parameters is None:
job_parameters = {'param1': 'value1'}
Expand Down
17 changes: 6 additions & 11 deletions tests/test_hyp3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
import warnings
from datetime import datetime, timedelta, timezone
from unittest.mock import patch
Expand Down Expand Up @@ -411,10 +412,7 @@ def test_my_info():
'name1',
'name2'
],
'quota': {
'max_job_per_month': 50,
'remaining': 25
},
'remaining_credits': 25.,
'user_id': 'someUser'
}
with patch('hyp3_sdk.util.get_authenticated_session', mock_get_authenticated_session):
Expand All @@ -425,20 +423,17 @@ def test_my_info():


@responses.activate
def test_check_quota():
def test_check_credits():
api_response = {
'job_names': [
'name1',
'name2'
],
'quota': {
'max_job_per_month': 50,
'remaining': 25
},
'remaining_credits': 25.,
'user_id': 'someUser'
}
with patch('hyp3_sdk.util.get_authenticated_session', mock_get_authenticated_session):
api = HyP3()
responses.add(responses.GET, urljoin(api.url, '/user'), json=api_response)
response = api.check_quota()
assert response == api_response['quota']['remaining']

assert math.isclose(api.check_credits(), 25.)
6 changes: 4 additions & 2 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"request_time": "2020-09-22T23:55:10+00:00",
"status_code": "SUCCEEDED",
"thumbnail_images": ["https://PAIR_PROCESS_thumb.png"],
"user_id": "asf_hyp3"
"user_id": "asf_hyp3",
"credit_cost": 1,
}

FAILED_JOB = {
Expand All @@ -39,7 +40,8 @@
"name": "test_failure",
"request_time": "2020-09-22T23:55:10+00:00",
"status_code": "FAILED",
"user_id": "asf_hyp3"
"user_id": "asf_hyp3",
"credit_cost": 1,
}


Expand Down

0 comments on commit c69abf8

Please sign in to comment.