Skip to content
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
6 changes: 3 additions & 3 deletions pygmt/clib/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
import ctypes as ctp
import sys
from contextlib import contextmanager
from contextlib import contextmanager, nullcontext

import numpy as np
import pandas as pd
Expand All @@ -25,7 +25,7 @@
GMTInvalidInput,
GMTVersionError,
)
from pygmt.helpers import data_kind, dummy_context, fmt_docstring, tempfile_from_geojson
from pygmt.helpers import data_kind, fmt_docstring, tempfile_from_geojson

FAMILIES = [
"GMT_IS_DATASET", # Entity is a data table
Expand Down Expand Up @@ -1451,7 +1451,7 @@ def virtualfile_from_data(

# Decide which virtualfile_from_ function to use
_virtualfile_from = {
"file": dummy_context,
"file": nullcontext,
"geojson": tempfile_from_geojson,
"grid": self.virtualfile_from_grid,
# Note: virtualfile_from_matrix is not used because a matrix can be
Expand Down
1 change: 0 additions & 1 deletion pygmt/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
args_in_kwargs,
build_arg_string,
data_kind,
dummy_context,
is_nonstr_iter,
launch_external_viewer,
)
28 changes: 0 additions & 28 deletions pygmt/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import time
import webbrowser
from collections.abc import Iterable
from contextlib import contextmanager

import xarray as xr
from pygmt.exceptions import GMTInvalidInput
Expand Down Expand Up @@ -92,33 +91,6 @@ def data_kind(data, x=None, y=None, z=None, required_z=False):
return kind


@contextmanager
def dummy_context(arg):
"""
Dummy context manager.

Does nothing when entering or exiting a ``with`` block and yields the
argument passed to it.

Useful when you have a choice of context managers but need one that does
nothing.

Parameters
----------
arg : anything
The argument that will be returned by the context manager.

Examples
--------

>>> with dummy_context("some argument") as temp:
... print(temp)
...
some argument
"""
yield arg


def build_arg_string(kwdict, confdict=None, infile=None, outfile=None):
r"""
Convert keyword dictionaries and input/output files into a GMT argument
Expand Down
3 changes: 1 addition & 2 deletions pygmt/src/x2sys_cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
GMTTempFile,
build_arg_string,
data_kind,
dummy_context,
fmt_docstring,
kwargs_to_strings,
unique_name,
Expand Down Expand Up @@ -196,7 +195,7 @@ def x2sys_cross(tracks=None, outfile=None, **kwargs):
for track in tracks:
kind = data_kind(track)
if kind == "file":
file_contexts.append(dummy_context(track))
file_contexts.append(contextlib.nullcontext(track))
elif kind == "matrix":
# find suffix (-E) of trackfiles used (e.g. xyz, csv, etc) from
# $X2SYS_HOME/TAGNAME/TAGNAME.tag file
Expand Down