Skip to content

Commit a2e85cd

Browse files
authored
Merge branch 'main' into pytest/xdist
2 parents e4e2ab9 + 5787a34 commit a2e85cd

File tree

8 files changed

+49
-49
lines changed

8 files changed

+49
-49
lines changed

examples/tutorials/basics/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
# Plot text labels at the x and y positions of the markers while varying the anchor
8383
# point via the justify parameter
8484
fig.text(x=-0.5, y=0.5, text="TL", justify="TL") # TopLeft
85-
fig.text(x=0, y=0.5, text="TM", justify="TC") # TopCenter
85+
fig.text(x=0, y=0.5, text="TC", justify="TC") # TopCenter
8686
fig.text(x=0.5, y=0.5, text="TR", justify="TR") # TopRight
8787
fig.text(x=-0.5, y=0, text="ML", justify="ML") # MiddleLeft
8888
fig.text(x=0, y=0, text="MC", justify="MC") # MiddleCenter

pygmt/clib/session.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
)
3535
from pygmt.helpers import (
3636
data_kind,
37-
fmt_docstring,
3837
tempfile_from_geojson,
3938
tempfile_from_image,
4039
)
@@ -146,7 +145,7 @@ class Session:
146145
... with GMTTempFile() as fout:
147146
... # Call the grdinfo module with the virtual file as input
148147
... # and the temp file as output.
149-
... ses.call_module("grdinfo", f"{fin} -C ->{fout.name}")
148+
... ses.call_module("grdinfo", [fin, "-C", f"->{fout.name}"])
150149
... # Read the contents of the temp file before it's deleted.
151150
... print(fout.read().strip())
152151
-55 -47 -24 -10 190 981 1 1 8 14 1 1
@@ -543,18 +542,20 @@ def get_common(self, option):
543542
Examples
544543
--------
545544
>>> with Session() as lib:
546-
... lib.call_module("basemap", "-R0/10/10/15 -JX5i/2.5i -Baf -Ve")
545+
... lib.call_module(
546+
... "basemap", ["-R0/10/10/15", "-JX5i/2.5i", "-Baf", "-Ve"]
547+
... )
547548
... region = lib.get_common("R")
548549
... projection = lib.get_common("J")
549550
... timestamp = lib.get_common("U")
550551
... verbose = lib.get_common("V")
551-
... lib.call_module("plot", "-T -Xw+1i -Yh-1i")
552+
... lib.call_module("plot", ["-T", "-Xw+1i", "-Yh-1i"])
552553
... xshift = lib.get_common("X") # xshift/yshift are in inches
553554
... yshift = lib.get_common("Y")
554555
>>> print(region, projection, timestamp, verbose, xshift, yshift)
555556
[ 0. 10. 10. 15.] True False 3 6.0 1.5
556557
>>> with Session() as lib:
557-
... lib.call_module("basemap", "-R0/10/10/15 -JX5i/2.5i -Baf")
558+
... lib.call_module("basemap", ["-R0/10/10/15", "-JX5i/2.5i", "-Baf"])
558559
... lib.get_common("A")
559560
Traceback (most recent call last):
560561
...
@@ -1180,8 +1181,7 @@ def open_virtualfile(self, family, geometry, direction, data):
11801181
... with lib.open_virtualfile(*vfargs) as vfile:
11811182
... # Send the output to a temp file so that we can read it
11821183
... with GMTTempFile() as ofile:
1183-
... args = f"{vfile} ->{ofile.name}"
1184-
... lib.call_module("info", args)
1184+
... lib.call_module("info", [vfile, f"->{ofile.name}"])
11851185
... print(ofile.read().strip())
11861186
<vector memory>: N = 5 <0/4> <5/9>
11871187
"""
@@ -1288,7 +1288,7 @@ def virtualfile_from_vectors(self, *vectors):
12881288
... with ses.virtualfile_from_vectors(x, y, z) as fin:
12891289
... # Send the output to a file so that we can read it
12901290
... with GMTTempFile() as fout:
1291-
... ses.call_module("info", f"{fin} ->{fout.name}")
1291+
... ses.call_module("info", [fin, f"->{fout.name}"])
12921292
... print(fout.read().strip())
12931293
<vector memory>: N = 3 <1/3> <4/6> <7/9>
12941294
"""
@@ -1398,7 +1398,7 @@ def virtualfile_from_matrix(self, matrix):
13981398
... with ses.virtualfile_from_matrix(data) as fin:
13991399
... # Send the output to a file so that we can read it
14001400
... with GMTTempFile() as fout:
1401-
... ses.call_module("info", f"{fin} ->{fout.name}")
1401+
... ses.call_module("info", [fin, f"->{fout.name}"])
14021402
... print(fout.read().strip())
14031403
<matrix memory>: N = 4 <0/9> <1/10> <2/11>
14041404
"""
@@ -1478,8 +1478,9 @@ def virtualfile_from_grid(self, grid):
14781478
... with ses.virtualfile_from_grid(data) as fin:
14791479
... # Send the output to a file so that we can read it
14801480
... with GMTTempFile() as fout:
1481-
... args = f"{fin} -L0 -Cn ->{fout.name}"
1482-
... ses.call_module("grdinfo", args)
1481+
... ses.call_module(
1482+
... "grdinfo", [fin, "-L0", "-Cn", f"->{fout.name}"]
1483+
... )
14831484
... print(fout.read().strip())
14841485
-55 -47 -24 -10 190 981 1 1 8 14 1 1
14851486
>>> # The output is: w e s n z0 z1 dx dy n_columns n_rows reg gtype
@@ -1510,7 +1511,6 @@ def virtualfile_from_grid(self, grid):
15101511
with self.open_virtualfile(*args) as vfile:
15111512
yield vfile
15121513

1513-
@fmt_docstring
15141514
def virtualfile_in( # noqa: PLR0912
15151515
self,
15161516
check_kind=None,
@@ -1571,7 +1571,7 @@ def virtualfile_in( # noqa: PLR0912
15711571
... with ses.virtualfile_in(check_kind="vector", data=data) as fin:
15721572
... # Send the output to a file so that we can read it
15731573
... with GMTTempFile() as fout:
1574-
... ses.call_module("info", fin + " ->" + fout.name)
1574+
... ses.call_module("info", [fin, f"->{fout.name}"])
15751575
... print(fout.read().strip())
15761576
<vector memory>: N = 3 <7/9> <4/6> <1/3>
15771577
"""
@@ -1718,15 +1718,15 @@ def virtualfile_out(
17181718
... # Create a virtual file for storing the output table.
17191719
... with Session() as lib:
17201720
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1721-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1721+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
17221722
... ds = lib.read_virtualfile(vouttbl, kind="dataset")
17231723
... assert isinstance(ds.contents, _GMT_DATASET)
17241724
...
17251725
... # Write data to an actual file without creating a virtual file.
17261726
... with Session() as lib:
17271727
... with lib.virtualfile_out(fname=tmpfile.name) as vouttbl:
17281728
... assert vouttbl == tmpfile.name
1729-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1729+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
17301730
... line = Path(vouttbl).read_text()
17311731
... assert line == "1\t2\t3\tTEXT\n"
17321732
"""
@@ -1798,7 +1798,7 @@ def read_virtualfile(
17981798
... with Path(tmpfile.name).open(mode="w") as fp:
17991799
... print("1.0 2.0 3.0 TEXT", file=fp)
18001800
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1801-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1801+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
18021802
... # Read the virtual file as a void pointer
18031803
... void_pointer = lib.read_virtualfile(vouttbl)
18041804
... assert isinstance(void_pointer, int) # void pointer is an int
@@ -1809,7 +1809,7 @@ def read_virtualfile(
18091809
>>> # Read grid from a virtual file
18101810
>>> with Session() as lib:
18111811
... with lib.virtualfile_out(kind="grid") as voutgrd:
1812-
... lib.call_module("read", f"@earth_relief_01d_g {voutgrd} -Tg")
1812+
... lib.call_module("read", ["@earth_relief_01d_g", voutgrd, "-Tg"])
18131813
... # Read the virtual file as a void pointer
18141814
... void_pointer = lib.read_virtualfile(voutgrd)
18151815
... assert isinstance(void_pointer, int) # void pointer is an int
@@ -1905,7 +1905,7 @@ def virtualfile_to_dataset(
19051905
... with lib.virtualfile_out(
19061906
... kind="dataset", fname=outtmp.name
19071907
... ) as vouttbl:
1908-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1908+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
19091909
... result = lib.virtualfile_to_dataset(
19101910
... vfname=vouttbl, output_type="file"
19111911
... )
@@ -1915,7 +1915,7 @@ def virtualfile_to_dataset(
19151915
... # strings output
19161916
... with Session() as lib:
19171917
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1918-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1918+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
19191919
... outstr = lib.virtualfile_to_dataset(
19201920
... vfname=vouttbl, output_type="strings"
19211921
... )
@@ -1925,7 +1925,7 @@ def virtualfile_to_dataset(
19251925
... # numpy output
19261926
... with Session() as lib:
19271927
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1928-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1928+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
19291929
... outnp = lib.virtualfile_to_dataset(
19301930
... vfname=vouttbl, output_type="numpy"
19311931
... )
@@ -1934,7 +1934,7 @@ def virtualfile_to_dataset(
19341934
... # pandas output
19351935
... with Session() as lib:
19361936
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1937-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1937+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
19381938
... outpd = lib.virtualfile_to_dataset(
19391939
... vfname=vouttbl, output_type="pandas"
19401940
... )
@@ -1943,7 +1943,7 @@ def virtualfile_to_dataset(
19431943
... # pandas output with specified column names
19441944
... with Session() as lib:
19451945
... with lib.virtualfile_out(kind="dataset") as vouttbl:
1946-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
1946+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
19471947
... outpd2 = lib.virtualfile_to_dataset(
19481948
... vfname=vouttbl,
19491949
... output_type="pandas",
@@ -2026,7 +2026,7 @@ def virtualfile_to_raster(
20262026
... with GMTTempFile(suffix=".nc") as tmpfile:
20272027
... outgrid = tmpfile.name
20282028
... with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd:
2029-
... lib.call_module("read", f"@earth_relief_01d_g {voutgrd} -Tg")
2029+
... lib.call_module("read", ["@earth_relief_01d_g", voutgrd, "-Tg"])
20302030
... result = lib.virtualfile_to_raster(
20312031
... vfname=voutgrd, outgrid=outgrid
20322032
... )
@@ -2036,7 +2036,7 @@ def virtualfile_to_raster(
20362036
... # xarray.DataArray output
20372037
... outgrid = None
20382038
... with lib.virtualfile_out(kind="grid", fname=outgrid) as voutgrd:
2039-
... lib.call_module("read", f"@earth_relief_01d_g {voutgrd} -Tg")
2039+
... lib.call_module("read", ["@earth_relief_01d_g", voutgrd, "-Tg"])
20402040
... result = lib.virtualfile_to_raster(vfname=voutgrd, outgrid=outgrid)
20412041
... assert isinstance(result, xr.DataArray)
20422042
"""

pygmt/datatypes/dataset.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class _GMT_DATASET(ctp.Structure): # noqa: N801
3737
... # Read the data file
3838
... with Session() as lib:
3939
... with lib.virtualfile_out(kind="dataset") as vouttbl:
40-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
40+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
4141
... # The dataset
4242
... ds = lib.read_virtualfile(vouttbl, kind="dataset").contents
4343
... print(ds.n_tables, ds.n_columns, ds.n_segments)
@@ -224,7 +224,7 @@ def to_dataframe(
224224
... print("10.0 11.0 12.0 TEXT123 TEXT456789", file=fp)
225225
... with Session() as lib:
226226
... with lib.virtualfile_out(kind="dataset") as vouttbl:
227-
... lib.call_module("read", f"{tmpfile.name} {vouttbl} -Td")
227+
... lib.call_module("read", [tmpfile.name, vouttbl, "-Td"])
228228
... ds = lib.read_virtualfile(vouttbl, kind="dataset")
229229
... text = ds.contents.to_strings()
230230
... df = ds.contents.to_dataframe(header=0)

pygmt/datatypes/grid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class _GMT_GRID(ctp.Structure): # noqa: N801
2222
>>> from pygmt.clib import Session
2323
>>> with Session() as lib:
2424
... with lib.virtualfile_out(kind="grid") as voutgrd:
25-
... lib.call_module("read", f"@static_earth_relief.nc {voutgrd} -Tg")
25+
... lib.call_module("read", ["@static_earth_relief.nc", voutgrd, "-Tg"])
2626
... # Read the grid from the virtual file
2727
... grid = lib.read_virtualfile(voutgrd, kind="grid").contents
2828
... # The grid header
@@ -106,7 +106,7 @@ def to_dataarray(self) -> xr.DataArray:
106106
>>> from pygmt.clib import Session
107107
>>> with Session() as lib:
108108
... with lib.virtualfile_out(kind="grid") as voutgrd:
109-
... lib.call_module("read", f"@static_earth_relief.nc {voutgrd} -Tg")
109+
... lib.call_module("read", ["@static_earth_relief.nc", voutgrd, "-Tg"])
110110
... # Read the grid from the virtual file
111111
... grid = lib.read_virtualfile(voutgrd, kind="grid")
112112
... # Convert to xarray.DataArray and use it later

pygmt/tests/test_clib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def test_call_module_invalid_arguments():
181181
"""
182182
with clib.Session() as lib:
183183
with pytest.raises(GMTCLibError):
184-
lib.call_module("info", "bogus-data.bla")
184+
lib.call_module("info", ["bogus-data.bla"])
185185

186186

187187
def test_call_module_invalid_name():
@@ -190,7 +190,7 @@ def test_call_module_invalid_name():
190190
"""
191191
with clib.Session() as lib:
192192
with pytest.raises(GMTCLibError):
193-
lib.call_module("meh", "")
193+
lib.call_module("meh", [])
194194

195195

196196
def test_call_module_error_message():
@@ -199,7 +199,7 @@ def test_call_module_error_message():
199199
"""
200200
with clib.Session() as lib:
201201
with pytest.raises(GMTCLibError) as exc_info:
202-
lib.call_module("info", "bogus-data.bla")
202+
lib.call_module("info", ["bogus-data.bla"])
203203
assert "Module 'info' failed with status code" in exc_info.value.args[0]
204204
assert (
205205
"gmtinfo [ERROR]: Cannot find file bogus-data.bla" in exc_info.value.args[0]
@@ -213,7 +213,7 @@ def test_method_no_session():
213213
# Create an instance of Session without "with" so no session is created.
214214
lib = clib.Session()
215215
with pytest.raises(GMTCLibNoSessionError):
216-
lib.call_module("gmtdefaults", "")
216+
lib.call_module("gmtdefaults", [])
217217
with pytest.raises(GMTCLibNoSessionError):
218218
_ = lib.session_pointer
219219

@@ -385,14 +385,14 @@ def test_extract_region_two_figures():
385385
# Activate the first figure and extract the region from it
386386
# Use in a different session to avoid any memory problems.
387387
with clib.Session() as lib:
388-
lib.call_module("figure", f"{fig1._name} -")
388+
lib.call_module("figure", [fig1._name, "-"])
389389
with clib.Session() as lib:
390390
wesn1 = lib.extract_region()
391391
npt.assert_allclose(wesn1, region1)
392392

393393
# Now try it with the second one
394394
with clib.Session() as lib:
395-
lib.call_module("figure", f"{fig2._name} -")
395+
lib.call_module("figure", [fig2._name, "-"])
396396
with clib.Session() as lib:
397397
wesn2 = lib.extract_region()
398398
npt.assert_allclose(wesn2, np.array([-165.0, -150.0, 15.0, 25.0]))

0 commit comments

Comments
 (0)