Skip to content
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

Rename API function Session.open_virtual_file to Session.open_virtualfile (remove in v0.15.0) #2996

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,6 @@ Low level access (these are mostly used by the :mod:`pygmt.clib` package):
clib.Session.put_strings
clib.Session.put_vector
clib.Session.write_data
clib.Session.open_virtual_file
clib.Session.open_virtualfile
clib.Session.extract_region
clib.Session.get_libgmt_func
33 changes: 25 additions & 8 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@
raise GMTCLibError(f"Failed to write dataset to '{output}'")

@contextlib.contextmanager
def open_virtual_file(self, family, geometry, direction, data):
def open_virtualfile(self, family, geometry, direction, data):
"""
Open a GMT virtual file to pass data to and from a module.

Expand Down Expand Up @@ -1142,7 +1142,7 @@
... lib.put_vector(dataset, column=1, vector=y)
... # Add the dataset to a virtual file
... vfargs = (family, geometry, "GMT_IN|GMT_IS_REFERENCE", dataset)
... with lib.open_virtual_file(*vfargs) as vfile:
... with lib.open_virtualfile(*vfargs) as vfile:
... # Send the output to a temp file so that we can read it
... with GMTTempFile() as ofile:
... args = f"{vfile} ->{ofile.name}"
Expand Down Expand Up @@ -1190,6 +1190,23 @@
if status != 0:
raise GMTCLibError(f"Failed to close virtual file '{vfname}'.")

def open_virtual_file(self, family, geometry, direction, data):
"""
Open a GMT virtual file to pass data to and from a module.

.. deprecated: 0.11.0

Will be removed in v0.15.0. Use :meth:`pygmt.clib.Session.open_virtualfile`
instead.
"""
msg = (

Check warning on line 1202 in pygmt/clib/session.py

View check run for this annotation

Codecov / codecov/patch

pygmt/clib/session.py#L1202

Added line #L1202 was not covered by tests
"API function `Session.open_virtual_file()' has been deprecated "
"since v0.11.0 and will be removed in v0.15.0. "
"Use `Session.open_virtualfile()' instead."
)
warnings.warn(msg, category=FutureWarning, stacklevel=2)
return self.open_virtualfile(family, geometry, direction, data)

Check warning on line 1208 in pygmt/clib/session.py

View check run for this annotation

Codecov / codecov/patch

pygmt/clib/session.py#L1207-L1208

Added lines #L1207 - L1208 were not covered by tests

@contextlib.contextmanager
def virtualfile_from_vectors(self, *vectors):
"""
Expand All @@ -1205,7 +1222,7 @@
Use this instead of creating the data container and virtual file by
hand with :meth:`pygmt.clib.Session.create_data`,
:meth:`pygmt.clib.Session.put_vector`, and
:meth:`pygmt.clib.Session.open_virtual_file`.
:meth:`pygmt.clib.Session.open_virtualfile`.

If the arrays are C contiguous blocks of memory, they will be passed
without copying to GMT. If they are not (e.g., they are columns of a
Expand Down Expand Up @@ -1286,7 +1303,7 @@
dataset, family="GMT_IS_VECTOR|GMT_IS_DUPLICATE", strings=strings
)

with self.open_virtual_file(
with self.open_virtualfile(
family, geometry, "GMT_IN|GMT_IS_REFERENCE", dataset
) as vfile:
yield vfile
Expand All @@ -1313,7 +1330,7 @@
Use this instead of creating the data container and virtual file by
hand with :meth:`pygmt.clib.Session.create_data`,
:meth:`pygmt.clib.Session.put_matrix`, and
:meth:`pygmt.clib.Session.open_virtual_file`
:meth:`pygmt.clib.Session.open_virtualfile`

The matrix must be C contiguous in memory. If it is not (e.g., it is a
slice of a larger array), the array will be copied to make sure it is.
Expand Down Expand Up @@ -1366,7 +1383,7 @@

self.put_matrix(dataset, matrix)

with self.open_virtual_file(
with self.open_virtualfile(
family, geometry, "GMT_IN|GMT_IS_REFERENCE", dataset
) as vfile:
yield vfile
Expand All @@ -1389,7 +1406,7 @@
Use this instead of creating a data container and virtual file by hand
with :meth:`pygmt.clib.Session.create_data`,
:meth:`pygmt.clib.Session.put_matrix`, and
:meth:`pygmt.clib.Session.open_virtual_file`
:meth:`pygmt.clib.Session.open_virtualfile`.

The grid data matrix must be C contiguous in memory. If it is not
(e.g., it is a slice of a larger array), the array will be copied to
Expand Down Expand Up @@ -1453,7 +1470,7 @@
)
self.put_matrix(gmt_grid, matrix)
args = (family, geometry, "GMT_IN|GMT_IS_REFERENCE", gmt_grid)
with self.open_virtual_file(*args) as vfile:
with self.open_virtualfile(*args) as vfile:
yield vfile

@fmt_docstring
Expand Down
8 changes: 4 additions & 4 deletions pygmt/tests/test_clib_virtualfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_virtual_file(dtypes):
lib.put_matrix(dataset, matrix=data)
# Add the dataset to a virtual file and pass it along to gmt info
vfargs = (family, geometry, "GMT_IN|GMT_IS_REFERENCE", dataset)
with lib.open_virtual_file(*vfargs) as vfile:
with lib.open_virtualfile(*vfargs) as vfile:
with GMTTempFile() as outfile:
lib.call_module("info", f"{vfile} ->{outfile.name}")
output = outfile.read(keep_tabs=True)
Expand All @@ -93,7 +93,7 @@ def test_virtual_file_fails():
# virtual file.
with clib.Session() as lib, mock(lib, "GMT_Open_VirtualFile", returns=1):
with pytest.raises(GMTCLibError):
with lib.open_virtual_file(*vfargs):
with lib.open_virtualfile(*vfargs):
pass

# Test the status check when closing the virtual file
Expand All @@ -103,7 +103,7 @@ def test_virtual_file_fails():
lib, "GMT_Close_VirtualFile", returns=1
):
with pytest.raises(GMTCLibError):
with lib.open_virtual_file(*vfargs):
with lib.open_virtualfile(*vfargs):
pass


Expand All @@ -119,7 +119,7 @@ def test_virtual_file_bad_direction():
0,
)
with pytest.raises(GMTInvalidInput):
with lib.open_virtual_file(*vfargs):
with lib.open_virtualfile(*vfargs):
pass


Expand Down
Loading