pymetkit 1.13.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pymetkit-1.13.1/AUTHORS +12 -0
- pymetkit-1.13.1/LICENSE +190 -0
- pymetkit-1.13.1/NOTICE +15 -0
- pymetkit-1.13.1/PKG-INFO +16 -0
- pymetkit-1.13.1/README.md +43 -0
- pymetkit-1.13.1/VERSION +1 -0
- pymetkit-1.13.1/pymetkit.egg-info/PKG-INFO +16 -0
- pymetkit-1.13.1/pymetkit.egg-info/SOURCES.txt +16 -0
- pymetkit-1.13.1/pymetkit.egg-info/dependency_links.txt +1 -0
- pymetkit-1.13.1/pymetkit.egg-info/not-zip-safe +1 -0
- pymetkit-1.13.1/pymetkit.egg-info/requires.txt +6 -0
- pymetkit-1.13.1/pymetkit.egg-info/top_level.txt +1 -0
- pymetkit-1.13.1/pyproject.toml +47 -0
- pymetkit-1.13.1/python/pymetkit/src/pymetkit/__init__.py +1 -0
- pymetkit-1.13.1/python/pymetkit/src/pymetkit/_version.py +5 -0
- pymetkit-1.13.1/python/pymetkit/src/pymetkit/metkit_c.h +52 -0
- pymetkit-1.13.1/python/pymetkit/src/pymetkit/pymetkit.py +312 -0
- pymetkit-1.13.1/setup.cfg +4 -0
pymetkit-1.13.1/AUTHORS
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
metkit authors
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
The main development of metkit is done at the European Centre for Medium-Range Weather Forecasts (ECMWF - http://www.ecmwf.int )
|
|
5
|
+
|
|
6
|
+
Current developers
|
|
7
|
+
==================
|
|
8
|
+
|
|
9
|
+
Baudouin Raoult
|
|
10
|
+
Tiago Quintino
|
|
11
|
+
Simon Smart
|
|
12
|
+
Matthias Zink
|
pymetkit-1.13.1/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 1996- ECMWF
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
pymetkit-1.13.1/NOTICE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
metkit
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
Copyright 1996- ECMWF
|
|
5
|
+
|
|
6
|
+
This product is developed by the
|
|
7
|
+
|
|
8
|
+
Development Section, European Centre for Medium-Range Weather Forecasts (ECMWF) - http://www.ecmwf.int
|
|
9
|
+
|
|
10
|
+
Below is a list of software packages which are used inside:
|
|
11
|
+
|
|
12
|
+
- No external package in currently included
|
|
13
|
+
|
|
14
|
+
Please also read the cmake/NOTICE file bundled in the distribution packages, which lists the included third-party CMake macros.
|
|
15
|
+
|
pymetkit-1.13.1/PKG-INFO
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pymetkit
|
|
3
|
+
Version: 1.13.1
|
|
4
|
+
Summary: Python interface for metkit
|
|
5
|
+
Author-email: "European Centre for Medium-Range Weather Forecasts (ECMWF)" <software.support@ecmwf.int>
|
|
6
|
+
License: Apache License Version 2.0
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: NOTICE
|
|
10
|
+
License-File: AUTHORS
|
|
11
|
+
Requires-Dist: cffi
|
|
12
|
+
Requires-Dist: metkitlib
|
|
13
|
+
Requires-Dist: findlibs
|
|
14
|
+
Provides-Extra: tests
|
|
15
|
+
Requires-Dist: pytest; extra == "tests"
|
|
16
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
metkit
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
[](https://github.com/ecmwf/metkit/blob/develop/LICENSE)
|
|
5
|
+
|
|
6
|
+
Requirements
|
|
7
|
+
------------
|
|
8
|
+
|
|
9
|
+
Runtime dependencies:
|
|
10
|
+
|
|
11
|
+
- eckit -- http://github.com/ecmwf/eckit
|
|
12
|
+
|
|
13
|
+
Build dependencies:
|
|
14
|
+
|
|
15
|
+
- CMake --- For use and installation see http://www.cmake.org/
|
|
16
|
+
- ecbuild --- ECMWF library of CMake macros ()
|
|
17
|
+
|
|
18
|
+
Installation
|
|
19
|
+
------------
|
|
20
|
+
|
|
21
|
+
metkit employs an out-of-source build/install based on CMake.
|
|
22
|
+
|
|
23
|
+
Make sure ecbuild is installed and the ecbuild executable script is found ( `which ecbuild` ).
|
|
24
|
+
|
|
25
|
+
Now proceed with installation as follows:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Environment --- Edit as needed
|
|
29
|
+
srcdir=$(pwd)
|
|
30
|
+
builddir=build
|
|
31
|
+
installdir=$HOME/local
|
|
32
|
+
|
|
33
|
+
# 1. Create the build directory:
|
|
34
|
+
mkdir $builddir
|
|
35
|
+
cd $builddir
|
|
36
|
+
|
|
37
|
+
# 2. Run CMake
|
|
38
|
+
ecbuild --prefix=$installdir -- -DECKIT_PATH=<path/to/eckit/install> $srcdir
|
|
39
|
+
|
|
40
|
+
# 3. Compile / Install
|
|
41
|
+
make -j10
|
|
42
|
+
make install
|
|
43
|
+
```
|
pymetkit-1.13.1/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.13.1
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pymetkit
|
|
3
|
+
Version: 1.13.1
|
|
4
|
+
Summary: Python interface for metkit
|
|
5
|
+
Author-email: "European Centre for Medium-Range Weather Forecasts (ECMWF)" <software.support@ecmwf.int>
|
|
6
|
+
License: Apache License Version 2.0
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: NOTICE
|
|
10
|
+
License-File: AUTHORS
|
|
11
|
+
Requires-Dist: cffi
|
|
12
|
+
Requires-Dist: metkitlib
|
|
13
|
+
Requires-Dist: findlibs
|
|
14
|
+
Provides-Extra: tests
|
|
15
|
+
Requires-Dist: pytest; extra == "tests"
|
|
16
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
AUTHORS
|
|
2
|
+
LICENSE
|
|
3
|
+
NOTICE
|
|
4
|
+
README.md
|
|
5
|
+
VERSION
|
|
6
|
+
pyproject.toml
|
|
7
|
+
pymetkit.egg-info/PKG-INFO
|
|
8
|
+
pymetkit.egg-info/SOURCES.txt
|
|
9
|
+
pymetkit.egg-info/dependency_links.txt
|
|
10
|
+
pymetkit.egg-info/not-zip-safe
|
|
11
|
+
pymetkit.egg-info/requires.txt
|
|
12
|
+
pymetkit.egg-info/top_level.txt
|
|
13
|
+
python/pymetkit/src/pymetkit/__init__.py
|
|
14
|
+
python/pymetkit/src/pymetkit/_version.py
|
|
15
|
+
python/pymetkit/src/pymetkit/metkit_c.h
|
|
16
|
+
python/pymetkit/src/pymetkit/pymetkit.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pymetkit
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# pytest
|
|
2
|
+
[tool.pytest.ini_options]
|
|
3
|
+
minversion = "6.0"
|
|
4
|
+
addopts = "-vv -s"
|
|
5
|
+
testpaths = [
|
|
6
|
+
"pymetkit/tests"
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
# pyproject.toml
|
|
10
|
+
|
|
11
|
+
[build-system]
|
|
12
|
+
requires = ["setuptools", "wheel", "cffi"]
|
|
13
|
+
build-backend = "setuptools.build_meta"
|
|
14
|
+
|
|
15
|
+
[project]
|
|
16
|
+
name = "pymetkit"
|
|
17
|
+
description = "Python interface for metkit"
|
|
18
|
+
dynamic = ["version"]
|
|
19
|
+
authors = [
|
|
20
|
+
{ name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "software.support@ecmwf.int" },
|
|
21
|
+
]
|
|
22
|
+
license = { text = "Apache License Version 2.0" }
|
|
23
|
+
requires-python = ">=3.10"
|
|
24
|
+
dependencies = [
|
|
25
|
+
"cffi",
|
|
26
|
+
"metkitlib",
|
|
27
|
+
"findlibs"
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.dynamic]
|
|
31
|
+
version = { file = ["VERSION"] }
|
|
32
|
+
|
|
33
|
+
[tool.setuptools]
|
|
34
|
+
packages = ["pymetkit"]
|
|
35
|
+
package-dir = { "pymetkit" = "./python/pymetkit/src/pymetkit" }
|
|
36
|
+
include-package-data = true
|
|
37
|
+
zip-safe = false
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.package-data]
|
|
40
|
+
"pymetkit" = [
|
|
41
|
+
"VERSION",
|
|
42
|
+
"metkit_c.h"
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[project.optional-dependencies]
|
|
46
|
+
tests = ["pytest"]
|
|
47
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .pymetkit import *
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
struct metkit_marsrequest_t;
|
|
3
|
+
typedef struct metkit_marsrequest_t metkit_marsrequest_t;
|
|
4
|
+
struct metkit_requestiterator_t;
|
|
5
|
+
typedef struct metkit_requestiterator_t metkit_requestiterator_t;
|
|
6
|
+
struct metkit_paramiterator_t;
|
|
7
|
+
typedef struct metkit_paramiterator_t metkit_paramiterator_t;
|
|
8
|
+
|
|
9
|
+
typedef enum metkit_error_values_t {
|
|
10
|
+
METKIT_SUCCESS = 0, /* Operation succeded. */
|
|
11
|
+
METKIT_ERROR = 1, /* Operation failed. */
|
|
12
|
+
METKIT_ERROR_UNKNOWN = 2, /* Failed with an unknown error. */
|
|
13
|
+
METKIT_ERROR_USER = 3, /* Failed with an user error. */
|
|
14
|
+
METKIT_ERROR_ASSERT = 4 /* Failed with an assert() */
|
|
15
|
+
} metkit_error_t;
|
|
16
|
+
|
|
17
|
+
typedef enum metkit_iterator_status_t {
|
|
18
|
+
METKIT_ITERATOR_SUCCESS = 0, /* Operation succeded. */
|
|
19
|
+
METKIT_ITERATOR_COMPLETE = 1, /* All elements have been returned */
|
|
20
|
+
METKIT_ITERATOR_ERROR = 2 /* Operation failed. */
|
|
21
|
+
} metkit_iterator_status_t;
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const char* metkit_get_error_string(enum metkit_error_values_t err);
|
|
25
|
+
const char* metkit_version();
|
|
26
|
+
const char* metkit_git_sha1();
|
|
27
|
+
metkit_error_t metkit_initialise();
|
|
28
|
+
|
|
29
|
+
metkit_error_t metkit_parse_marsrequests(const char* str, metkit_requestiterator_t** requests, bool strict);
|
|
30
|
+
metkit_error_t metkit_marsrequest_new(metkit_marsrequest_t** request);
|
|
31
|
+
metkit_error_t metkit_marsrequest_delete(const metkit_marsrequest_t* request);
|
|
32
|
+
metkit_error_t metkit_marsrequest_set(metkit_marsrequest_t* request, const char* param, const char* values[],
|
|
33
|
+
int numValues);
|
|
34
|
+
metkit_error_t metkit_marsrequest_set_one(metkit_marsrequest_t* request, const char* param, const char* value);
|
|
35
|
+
metkit_error_t metkit_marsrequest_set_verb(metkit_marsrequest_t* request, const char* verb);
|
|
36
|
+
metkit_error_t metkit_marsrequest_verb(const metkit_marsrequest_t* request, const char** verb);
|
|
37
|
+
metkit_error_t metkit_marsrequest_has_param(const metkit_marsrequest_t* request, const char* param, bool* has);
|
|
38
|
+
metkit_error_t metkit_marsrequest_params(const metkit_marsrequest_t* request, metkit_paramiterator_t** params);
|
|
39
|
+
metkit_error_t metkit_marsrequest_count_values(const metkit_marsrequest_t* request, const char* param, size_t* count);
|
|
40
|
+
metkit_error_t metkit_marsrequest_value(const metkit_marsrequest_t* request, const char* param, int index,
|
|
41
|
+
const char** value);
|
|
42
|
+
metkit_error_t metkit_marsrequest_expand(const metkit_marsrequest_t* request, bool inherit, bool strict,
|
|
43
|
+
metkit_marsrequest_t* expandedRequest);
|
|
44
|
+
metkit_error_t metkit_marsrequest_merge(metkit_marsrequest_t* request, const metkit_marsrequest_t* otherRequest);
|
|
45
|
+
|
|
46
|
+
metkit_error_t metkit_requestiterator_delete(const metkit_requestiterator_t* it);
|
|
47
|
+
metkit_iterator_status_t metkit_requestiterator_next(metkit_requestiterator_t* it);
|
|
48
|
+
metkit_iterator_status_t metkit_requestiterator_current(metkit_requestiterator_t* it, metkit_marsrequest_t* request);
|
|
49
|
+
|
|
50
|
+
metkit_error_t metkit_paramiterator_delete(const metkit_paramiterator_t* it);
|
|
51
|
+
metkit_iterator_status_t metkit_paramiterator_next(metkit_paramiterator_t* it);
|
|
52
|
+
metkit_iterator_status_t metkit_paramiterator_current(const metkit_paramiterator_t* it, const char** param);
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from cffi import FFI
|
|
3
|
+
import findlibs
|
|
4
|
+
from typing import IO, Iterator
|
|
5
|
+
import warnings
|
|
6
|
+
from ._version import __version__
|
|
7
|
+
|
|
8
|
+
ffi = FFI()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def ffi_encode(data) -> bytes:
|
|
12
|
+
if isinstance(data, bytes):
|
|
13
|
+
return data
|
|
14
|
+
|
|
15
|
+
if not isinstance(data, str):
|
|
16
|
+
data = str(data)
|
|
17
|
+
|
|
18
|
+
return data.encode(encoding="utf-8", errors="surrogateescape")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def ffi_decode(data: FFI.CData) -> str:
|
|
22
|
+
buf = ffi.string(data)
|
|
23
|
+
if isinstance(buf, str):
|
|
24
|
+
return buf
|
|
25
|
+
else:
|
|
26
|
+
return buf.decode(encoding="utf-8", errors="surrogateescape")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class MarsRequest:
|
|
30
|
+
def __init__(self, verb: str | None = None, **kwargs):
|
|
31
|
+
"""
|
|
32
|
+
Create MetKit MarsRequest object. Parameters and values in
|
|
33
|
+
the request can be specified through kwargs, noting that
|
|
34
|
+
reserved words in Python must be suffixed with "_" e.g. "class_"
|
|
35
|
+
"""
|
|
36
|
+
crequest = ffi.new("metkit_marsrequest_t **")
|
|
37
|
+
lib.metkit_marsrequest_new(crequest)
|
|
38
|
+
self.__request = ffi.gc(crequest[0], lib.metkit_marsrequest_delete)
|
|
39
|
+
if verb is not None:
|
|
40
|
+
lib.metkit_marsrequest_set_verb(self.__request, ffi_encode(verb))
|
|
41
|
+
for param, values in kwargs.items():
|
|
42
|
+
self[param.rstrip("_")] = values
|
|
43
|
+
|
|
44
|
+
def ctype(self) -> FFI.CData:
|
|
45
|
+
return self.__request
|
|
46
|
+
|
|
47
|
+
def verb(self) -> str:
|
|
48
|
+
cverb = ffi.new("const char **")
|
|
49
|
+
lib.metkit_marsrequest_verb(self.__request, cverb)
|
|
50
|
+
return ffi_decode(cverb[0])
|
|
51
|
+
|
|
52
|
+
def expand(self, inherit: bool = True, strict: bool = False) -> "MarsRequest":
|
|
53
|
+
"""
|
|
54
|
+
Return expanded request
|
|
55
|
+
|
|
56
|
+
Params
|
|
57
|
+
------
|
|
58
|
+
inherit: bool, if True, populates expanded request with default values
|
|
59
|
+
strict: bool, if True, raise error instead of warning for invalid values
|
|
60
|
+
|
|
61
|
+
Returns
|
|
62
|
+
-------
|
|
63
|
+
Request, resulting from expansion
|
|
64
|
+
"""
|
|
65
|
+
expanded_request = MarsRequest()
|
|
66
|
+
lib.metkit_marsrequest_expand(
|
|
67
|
+
self.__request, inherit, strict, expanded_request.ctype()
|
|
68
|
+
)
|
|
69
|
+
return expanded_request
|
|
70
|
+
|
|
71
|
+
def validate(self):
|
|
72
|
+
"""
|
|
73
|
+
Check if request is valid against MARS language definition. Does not
|
|
74
|
+
inherit missing parameters.
|
|
75
|
+
|
|
76
|
+
Raises
|
|
77
|
+
------
|
|
78
|
+
Exception if request is incompatible with MARS language definition
|
|
79
|
+
"""
|
|
80
|
+
self.expand(False, True)
|
|
81
|
+
|
|
82
|
+
def keys(self) -> Iterator[str]:
|
|
83
|
+
"""
|
|
84
|
+
Get iterator over parameters in request
|
|
85
|
+
|
|
86
|
+
Returns
|
|
87
|
+
-------
|
|
88
|
+
Iterator over parameter names
|
|
89
|
+
"""
|
|
90
|
+
it_c = ffi.new("metkit_paramiterator_t **")
|
|
91
|
+
lib.metkit_marsrequest_params(self.__request, it_c)
|
|
92
|
+
it = ffi.gc(it_c[0], lib.metkit_paramiterator_delete)
|
|
93
|
+
|
|
94
|
+
while lib.metkit_paramiterator_next(it) == lib.METKIT_ITERATOR_SUCCESS:
|
|
95
|
+
cparam = ffi.new("const char **")
|
|
96
|
+
lib.metkit_paramiterator_current(it, cparam)
|
|
97
|
+
param = ffi_decode(cparam[0])
|
|
98
|
+
yield param
|
|
99
|
+
|
|
100
|
+
def num_values(self, param: str) -> int:
|
|
101
|
+
"""
|
|
102
|
+
Number of values for parameter
|
|
103
|
+
|
|
104
|
+
Params
|
|
105
|
+
------
|
|
106
|
+
param: parameter name
|
|
107
|
+
|
|
108
|
+
Returns
|
|
109
|
+
-------
|
|
110
|
+
int
|
|
111
|
+
"""
|
|
112
|
+
cparam = ffi_encode(param)
|
|
113
|
+
count = ffi.new("size_t *", 0)
|
|
114
|
+
lib.metkit_marsrequest_count_values(self.__request, cparam, count)
|
|
115
|
+
return count[0]
|
|
116
|
+
|
|
117
|
+
def merge(self, other: "MarsRequest") -> "MarsRequest":
|
|
118
|
+
"""
|
|
119
|
+
Merge the values in another request with existing request and returns result as a
|
|
120
|
+
new Request object. Does not modify inputs to merge. Both input requests must contain
|
|
121
|
+
the same values and the resulting request object must be compatible with MARS language
|
|
122
|
+
definition
|
|
123
|
+
|
|
124
|
+
Params
|
|
125
|
+
------
|
|
126
|
+
other: Request, request to merge with self
|
|
127
|
+
|
|
128
|
+
Returns
|
|
129
|
+
-------
|
|
130
|
+
Request, containing the result of the merge
|
|
131
|
+
|
|
132
|
+
Raises
|
|
133
|
+
------
|
|
134
|
+
ValueError if parameters in the two requests do not match
|
|
135
|
+
MetKitException if resulting request is not compatible with MARS language definition
|
|
136
|
+
"""
|
|
137
|
+
if set(self.keys()) != set(other.keys()):
|
|
138
|
+
raise ValueError("Can not merge requests with different parameters.")
|
|
139
|
+
res = MarsRequest(self.verb(), **{k: v for k, v in self})
|
|
140
|
+
lib.metkit_marsrequest_merge(res.ctype(), other.ctype())
|
|
141
|
+
res.validate()
|
|
142
|
+
return res
|
|
143
|
+
|
|
144
|
+
def __iter__(self) -> Iterator[tuple[str, list[str]]]:
|
|
145
|
+
for param in self.keys():
|
|
146
|
+
yield param, self[param]
|
|
147
|
+
|
|
148
|
+
def __getitem__(self, param: str) -> str | list[str]:
|
|
149
|
+
nvalues = self.num_values(param)
|
|
150
|
+
values = []
|
|
151
|
+
for index in range(nvalues):
|
|
152
|
+
cvalue = ffi.new("const char **")
|
|
153
|
+
lib.metkit_marsrequest_value(self.__request, ffi_encode(param), index, cvalue)
|
|
154
|
+
value = ffi_decode(cvalue[0])
|
|
155
|
+
if nvalues == 1:
|
|
156
|
+
return value
|
|
157
|
+
values.append(value)
|
|
158
|
+
return values
|
|
159
|
+
|
|
160
|
+
def __contains__(self, param: str) -> bool:
|
|
161
|
+
has = ffi.new("bool *", False)
|
|
162
|
+
lib.metkit_marsrequest_has_param(self.__request, ffi_encode(param), has)
|
|
163
|
+
return has[0]
|
|
164
|
+
|
|
165
|
+
def __setitem__(self, param: str, values: int | str | list[str]):
|
|
166
|
+
if isinstance(values, (str, int)):
|
|
167
|
+
values = [values]
|
|
168
|
+
cvals = []
|
|
169
|
+
for value in values:
|
|
170
|
+
if isinstance(value, int):
|
|
171
|
+
value = str(value)
|
|
172
|
+
cvals.append(ffi.new("const char[]", value.encode("ascii")))
|
|
173
|
+
lib.metkit_marsrequest_set(
|
|
174
|
+
self.__request,
|
|
175
|
+
ffi_encode(param),
|
|
176
|
+
ffi.new("const char*[]", cvals),
|
|
177
|
+
len(values),
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
def __eq__(self, other: "MarsRequest") -> bool:
|
|
181
|
+
if self.verb() != other.verb():
|
|
182
|
+
return False
|
|
183
|
+
expanded = self.expand()
|
|
184
|
+
other_expanded = other.expand()
|
|
185
|
+
return dict(expanded) == dict(other_expanded)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def parse_mars_request(file_or_str: IO | str, strict: bool = False) -> list[MarsRequest]:
|
|
189
|
+
"""
|
|
190
|
+
Function for parsing mars request from file object or string.
|
|
191
|
+
|
|
192
|
+
Params
|
|
193
|
+
------
|
|
194
|
+
file_or_str: string or file-like object, containing mars request
|
|
195
|
+
strict: bool, whether to raise error or warning when request is not compatible with
|
|
196
|
+
MARS language definition. In the case of warning, when False, the incompatible
|
|
197
|
+
parameters are unset from the request.
|
|
198
|
+
|
|
199
|
+
Returns
|
|
200
|
+
-------
|
|
201
|
+
list of Request
|
|
202
|
+
"""
|
|
203
|
+
crequest_iter = ffi.new("metkit_requestiterator_t **")
|
|
204
|
+
|
|
205
|
+
if isinstance(file_or_str, str):
|
|
206
|
+
lib.metkit_parse_marsrequests(ffi_encode(file_or_str), crequest_iter, strict)
|
|
207
|
+
else:
|
|
208
|
+
lib.metkit_parse_marsrequests(
|
|
209
|
+
ffi_encode(file_or_str.read()), crequest_iter, strict
|
|
210
|
+
)
|
|
211
|
+
request_iter = ffi.gc(crequest_iter[0], lib.metkit_requestiterator_delete)
|
|
212
|
+
|
|
213
|
+
requests = []
|
|
214
|
+
while lib.metkit_requestiterator_next(request_iter) == lib.METKIT_ITERATOR_SUCCESS:
|
|
215
|
+
new_request = MarsRequest()
|
|
216
|
+
lib.metkit_requestiterator_current(request_iter, new_request.ctype())
|
|
217
|
+
requests.append(new_request)
|
|
218
|
+
|
|
219
|
+
return requests
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
class MetKitException(RuntimeError):
|
|
223
|
+
"""Raised when MetKit library throws exception"""
|
|
224
|
+
|
|
225
|
+
pass
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class CFFIModuleLoadFailed(ImportError):
|
|
229
|
+
"""Raised when the shared library fails to load"""
|
|
230
|
+
|
|
231
|
+
pass
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
class PatchedLib:
|
|
235
|
+
"""
|
|
236
|
+
Patch a CFFI library with error handling
|
|
237
|
+
|
|
238
|
+
Finds the header file associated with the MetKit C API and parses it,
|
|
239
|
+
loads the shared library, and patches the accessors with
|
|
240
|
+
automatic python-C error handling.
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
def __init__(self):
|
|
244
|
+
libName = findlibs.find("metkit")
|
|
245
|
+
|
|
246
|
+
if libName is None:
|
|
247
|
+
raise RuntimeError("MetKit library not found")
|
|
248
|
+
|
|
249
|
+
ffi.cdef(self.__read_header())
|
|
250
|
+
self.__lib = ffi.dlopen(libName)
|
|
251
|
+
|
|
252
|
+
# All of the executable members of the CFFI-loaded library are functions in the MetKit
|
|
253
|
+
# C API. These should be wrapped with the correct error handling. Otherwise forward
|
|
254
|
+
# these on directly.
|
|
255
|
+
|
|
256
|
+
for f in dir(self.__lib):
|
|
257
|
+
try:
|
|
258
|
+
attr = getattr(self.__lib, f)
|
|
259
|
+
setattr(
|
|
260
|
+
self, f, self.__check_error(attr, f) if callable(attr) else attr
|
|
261
|
+
)
|
|
262
|
+
except Exception as e:
|
|
263
|
+
print(e)
|
|
264
|
+
print("Error retrieving attribute", f, "from library")
|
|
265
|
+
|
|
266
|
+
# Initialise the library, and set it up for python-appropriate behaviour
|
|
267
|
+
|
|
268
|
+
self.metkit_initialise()
|
|
269
|
+
|
|
270
|
+
# Check the library version
|
|
271
|
+
|
|
272
|
+
versionstr = ffi.string(self.metkit_version()).decode("utf-8")
|
|
273
|
+
if versionstr != __version__:
|
|
274
|
+
warnings.warn(f"Metkit library version {versionstr} does not match python version {__version__}")
|
|
275
|
+
|
|
276
|
+
def __read_header(self):
|
|
277
|
+
with open(os.path.join(os.path.dirname(__file__), "metkit_c.h"), "r") as f:
|
|
278
|
+
return f.read()
|
|
279
|
+
|
|
280
|
+
def __check_error(self, fn, name: str):
|
|
281
|
+
"""
|
|
282
|
+
If calls into the MetKit library return errors, ensure that they get
|
|
283
|
+
detected and reported by throwing an appropriate python exception.
|
|
284
|
+
"""
|
|
285
|
+
|
|
286
|
+
def wrapped_fn(*args, **kwargs):
|
|
287
|
+
|
|
288
|
+
# debug
|
|
289
|
+
retval = fn(*args, **kwargs)
|
|
290
|
+
|
|
291
|
+
# Some functions dont return error codes. Ignore these.
|
|
292
|
+
if name in ["metkit_version", "metkit_git_sha1"]:
|
|
293
|
+
return retval
|
|
294
|
+
|
|
295
|
+
# error codes:
|
|
296
|
+
if retval not in (
|
|
297
|
+
self.__lib.METKIT_SUCCESS,
|
|
298
|
+
self.__lib.METKIT_ITERATOR_SUCCESS,
|
|
299
|
+
self.__lib.METKIT_ITERATOR_COMPLETE,
|
|
300
|
+
):
|
|
301
|
+
err = ffi_decode(self.__lib.metkit_get_error_string(retval))
|
|
302
|
+
msg = "Error in function '{}': {}".format(name, err)
|
|
303
|
+
raise MetKitException(msg)
|
|
304
|
+
return retval
|
|
305
|
+
|
|
306
|
+
return wrapped_fn
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
try:
|
|
310
|
+
lib = PatchedLib()
|
|
311
|
+
except CFFIModuleLoadFailed as e:
|
|
312
|
+
raise ImportError() from e
|