-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/pymetkit #56
Merged
Merged
Feature/pymetkit #56
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c73ded1
Create README.md
jinmannwong d5dd9c0
Initial Python interface implementation
jinmannwong 7fecdbc
Modify api to accept string or file-like object
jinmannwong 681cdc7
Add README and comments
jinmannwong 1a713d9
Add required python version to pyproject.toml
jinmannwong 396c50f
Refactor and add functionality to create request from scratch
jinmannwong 5486cd8
Add method to validate request
jinmannwong cdb8728
Add method to merge requests and related tests
jinmannwong 92bb89c
Review comments
jinmannwong 1ef7c05
Add check for equality and tests
jinmannwong 2968806
Add 'pymetkit/' from commit '1ef7c05d9b7f94a17918cbc29eba84e3731f209a'
ChrisspyB 47681bb
Merge from bitbucket branch 'feature/metkit-python' into feature/pyme…
ChrisspyB 43b41d3
Merge branch 'feature/c-api' into feature/pymetkit
ChrisspyB 20100c4
Update pymetkit to reflect C API changes
ChrisspyB 95da9f5
Merge branch 'feature/c-api' into feature/pymetkit
ChrisspyB e62548f
Restructure python project
ChrisspyB 56d2d4e
Small change
ChrisspyB 8ae0b12
Merge branch 'feature/c-api' into feature/pymetkit
ChrisspyB 5f4c960
Rename Request to MarsRequest
ChrisspyB 24800af
Merge branch 'feature/c-api' into feature/pymetkit
ChrisspyB ddf611d
Temporarily disable some strict expansion tests
ChrisspyB ea8ba6d
Merge branch 'develop' into feature/pymetkit
ChrisspyB 232fd48
Merge branch 'develop' into feature/pymetkit
ChrisspyB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# pymetkit | ||
|
||
This repository contains an Python interface to the MetKit library for parsing MARS requests. | ||
|
||
## Example | ||
|
||
The function for parsing a MARS request is `metkit.parse_mars_request` which accepts a string or file-like object | ||
as inputs. A list of `metkit.mars.Request` instances are returned, which is a dictionary containing the keys and | ||
values in the MARS request and the attribute `verb` for the verb in the MARS request. | ||
|
||
### From String | ||
``` | ||
from metkit import parse_mars_request | ||
|
||
request_str = "retrieve,class=od,date=20240124,time=12,param=129,step=12,target=test.grib" | ||
requests = parse_mars_request(requests) | ||
|
||
print(requests[0]) | ||
# verb: retrieve, request: {'class': ['od'], 'date': ['20240124'], 'time': ['1200'], 'param': ['129'], 'step': ['12'], 'target': ['test.grib'], 'domain': ['g'], 'expver': ['0001'], 'levelist': ['1000', '850', '700', '500', '400', '300'], 'levtype': ['pl'], 'stream': ['oper'], 'type': ['an']} | ||
``` | ||
|
||
### From File | ||
If the MARS request is contained inside a file, e.g. test_requests.txt: | ||
``` | ||
from metkit import parse_mars_request | ||
|
||
requests = parse_mars_request(open("test_requests.txt", "r")) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .pymetkit import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pathlib import Path | ||
from .pymetkit import * | ||
import importlib.metadata | ||
|
||
__version__ = importlib.metadata.version("pymetkit") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
struct metkit_marsrequest_t; | ||
typedef struct metkit_marsrequest_t metkit_marsrequest_t; | ||
struct metkit_requestiterator_t; | ||
typedef struct metkit_requestiterator_t metkit_requestiterator_t; | ||
struct metkit_paramiterator_t; | ||
typedef struct metkit_paramiterator_t metkit_paramiterator_t; | ||
|
||
typedef enum metkit_error_values_t | ||
{ | ||
METKIT_SUCCESS = 0, /* Operation succeded. */ | ||
METKIT_ERROR = 1, /* Operation failed. */ | ||
METKIT_ERROR_UNKNOWN = 2, /* Failed with an unknown error. */ | ||
METKIT_ERROR_USER = 3, /* Failed with an user error. */ | ||
METKIT_ERROR_ASSERT = 4 /* Failed with an assert() */ | ||
} metkit_error_t; | ||
|
||
typedef enum metkit_iterator_status_t | ||
{ | ||
METKIT_ITERATOR_SUCCESS = 0, /* Operation succeded. */ | ||
METKIT_ITERATOR_COMPLETE = 1, /* All elements have been returned */ | ||
METKIT_ITERATOR_ERROR = 2 /* Operation failed. */ | ||
} metkit_iterator_status_t; | ||
|
||
|
||
const char* metkit_get_error_string(enum metkit_error_values_t err); | ||
const char* metkit_version(); | ||
const char* metkit_git_sha1(); | ||
metkit_error_t metkit_initialise(); | ||
|
||
metkit_error_t metkit_parse_marsrequests(const char* str, metkit_requestiterator_t** requests, bool strict); | ||
metkit_error_t metkit_marsrequest_new(metkit_marsrequest_t** request); | ||
metkit_error_t metkit_marsrequest_delete(const metkit_marsrequest_t* request); | ||
metkit_error_t metkit_marsrequest_set(metkit_marsrequest_t* request, const char* param, const char* values[], int numValues); | ||
metkit_error_t metkit_marsrequest_set_one(metkit_marsrequest_t* request, const char* param, const char* value); | ||
metkit_error_t metkit_marsrequest_set_verb(metkit_marsrequest_t* request, const char* verb); | ||
metkit_error_t metkit_marsrequest_verb(const metkit_marsrequest_t* request, const char** verb); | ||
metkit_error_t metkit_marsrequest_has_param(const metkit_marsrequest_t* request, const char* param, bool* has); | ||
metkit_error_t metkit_marsrequest_params(const metkit_marsrequest_t* request, metkit_paramiterator_t** params); | ||
metkit_error_t metkit_marsrequest_count_values(const metkit_marsrequest_t* request, const char* param, size_t* count); | ||
metkit_error_t metkit_marsrequest_value(const metkit_marsrequest_t* request, const char* param, int index, const char** value); | ||
metkit_error_t metkit_marsrequest_expand(const metkit_marsrequest_t* request, bool inherit, bool strict, metkit_marsrequest_t* expandedRequest); | ||
metkit_error_t metkit_marsrequest_merge(metkit_marsrequest_t* request, const metkit_marsrequest_t* otherRequest); | ||
|
||
metkit_error_t metkit_requestiterator_delete(const metkit_requestiterator_t* it); | ||
metkit_iterator_status_t metkit_requestiterator_next(metkit_requestiterator_t* it); | ||
metkit_iterator_status_t metkit_requestiterator_current(metkit_requestiterator_t* it, metkit_marsrequest_t* request); | ||
|
||
metkit_error_t metkit_paramiterator_delete(const metkit_paramiterator_t* it); | ||
metkit_iterator_status_t metkit_paramiterator_next(metkit_paramiterator_t* it); | ||
metkit_iterator_status_t metkit_paramiterator_current(const metkit_paramiterator_t* it, const char** param); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're going to have a parameter iterator, at least make it able to return the number of values and the values as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See other comment |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced you need a params iterator, as opposed to just returning them by count/index in the same way as you do for the values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the existing C++ implementation, it is not possible to return the params without making a copy (they internally stored in a linked list), unlike the values, so they are less suitable for accessing by index and count