@@ -115,33 +115,28 @@ class Session:
115
115
"""
116
116
A GMT API session where most operations involving the C API happen.
117
117
118
- Works as a context manager (for use in a ``with`` block) to create a GMT C
119
- API session and destroy it in the end to clean up memory.
118
+ Works as a context manager (for use in a ``with`` block) to create a GMT C API
119
+ session and destroy it in the end to clean up memory.
120
120
121
- Functions of the shared library are exposed as methods of this class. Most
122
- methods MUST be used with an open session (inside a ``with`` block). If
123
- creating GMT data structures to communicate data, put that code inside the
124
- same ``with`` block as the API calls that will use the data.
121
+ Functions of the shared library are exposed as methods of this class. Most methods
122
+ MUST be used with an open session (inside a ``with`` block). If creating GMT data
123
+ structures to communicate data, put that code inside the same ``with`` block as the
124
+ API calls that will use the data.
125
125
126
- By default, will let :mod:`ctypes` try to find the GMT shared library
127
- (``libgmt``). If the environment variable :term:`GMT_LIBRARY_PATH` is set, will
128
- look for the shared library in the directory specified by it.
126
+ By default, will let :mod:`ctypes` try to find the GMT shared library (``libgmt``).
127
+ If the environment variable :term:`GMT_LIBRARY_PATH` is set, will look for the
128
+ shared library in the directory specified by it.
129
129
130
- A ``GMTVersionError`` exception will be raised if the GMT shared library
131
- reports a version older than the required minimum GMT version.
132
-
133
- The ``session_pointer`` attribute holds a ctypes pointer to the currently
134
- open session.
130
+ The ``session_pointer`` attribute holds a ctypes pointer to the currently open
131
+ session.
135
132
136
133
Raises
137
134
------
138
135
GMTCLibNotFoundError
139
- If there was any problem loading the library (couldn't find it or
140
- couldn't access the functions).
136
+ If there was any problem loading the library (couldn't find it or couldn't
137
+ access the functions).
141
138
GMTCLibNoSessionError
142
- If you try to call a method outside of a 'with' block.
143
- GMTVersionError
144
- If the minimum required version of GMT is not found.
139
+ If you try to call a method outside of a ``with`` block.
145
140
146
141
Examples
147
142
--------
@@ -151,45 +146,44 @@ class Session:
151
146
>>> grid = load_static_earth_relief()
152
147
>>> type(grid)
153
148
<class 'xarray.core.dataarray.DataArray'>
154
- >>> # Create a session and destroy it automatically when exiting the "with"
155
- >>> # block.
156
- >>> with Session() as ses:
149
+ >>> # Create a session and destroy it automatically when exiting the "with" block.
150
+ >>> with Session() as lib:
157
151
... # Create a virtual file and link to the memory block of the grid.
158
- ... with ses .virtualfile_from_grid(grid) as fin:
152
+ ... with lib .virtualfile_from_grid(grid) as fin:
159
153
... # Create a temp file to use as output.
160
154
... with GMTTempFile() as fout:
161
- ... # Call the grdinfo module with the virtual file as input
162
- ... # and the temp file as output.
163
- ... ses .call_module("grdinfo", [fin, "-C", f"->{fout.name}"])
155
+ ... # Call the grdinfo module with the virtual file as input and the
156
+ ... # temp file as output.
157
+ ... lib .call_module("grdinfo", [fin, "-C", f"->{fout.name}"])
164
158
... # Read the contents of the temp file before it's deleted.
165
159
... print(fout.read().strip())
166
160
-55 -47 -24 -10 190 981 1 1 8 14 1 1
167
161
"""
168
162
169
163
@property
170
- def session_pointer (self ):
164
+ def session_pointer (self ) -> ctp . c_void_p :
171
165
"""
172
166
The :class:`ctypes.c_void_p` pointer to the current open GMT session.
173
167
174
168
Raises
175
169
------
176
170
GMTCLibNoSessionError
177
- If trying to access without a currently open GMT session (i.e.,
178
- outside of the context manager).
171
+ If trying to access without a currently open GMT session (i.e., outside of
172
+ the context manager).
179
173
"""
180
174
if not hasattr (self , "_session_pointer" ) or self ._session_pointer is None :
181
175
raise GMTCLibNoSessionError ("No currently open GMT API session." )
182
176
return self ._session_pointer
183
177
184
178
@session_pointer .setter
185
- def session_pointer (self , session ):
179
+ def session_pointer (self , session : ctp . c_void_p ):
186
180
"""
187
181
Set the session void pointer.
188
182
"""
189
183
self ._session_pointer = session
190
184
191
185
@property
192
- def info (self ):
186
+ def info (self ) -> dict [ str , str ] :
193
187
"""
194
188
Dictionary with the GMT version and default paths and parameters.
195
189
"""
0 commit comments