Skip to content

Commit ce926a0

Browse files
committed
Move session-unrelated code block outside the session block
1 parent 95fab98 commit ce926a0

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

pygmt/src/x2sys_cross.py

+23-23
Original file line numberDiff line numberDiff line change
@@ -195,30 +195,30 @@ def x2sys_cross(
195195
"""
196196
output_type = validate_output_table_type(output_type, outfile=outfile)
197197

198-
with Session() as lib:
199-
file_contexts = []
200-
for track in tracks:
201-
kind = data_kind(track)
202-
if kind == "file":
203-
file_contexts.append(contextlib.nullcontext(track))
204-
elif kind == "matrix":
205-
# find suffix (-E) of trackfiles used (e.g. xyz, csv, etc) from
206-
# $X2SYS_HOME/TAGNAME/TAGNAME.tag file
207-
lastline = (
208-
Path(os.environ["X2SYS_HOME"], kwargs["T"], f"{kwargs['T']}.tag")
209-
.read_text(encoding="utf8")
210-
.strip()
211-
.split("\n")[-1]
212-
) # e.g. "-Dxyz -Etsv -I1/1"
213-
for item in sorted(lastline.split()): # sort list alphabetically
214-
if item.startswith(("-E", "-D")): # prefer -Etsv over -Dxyz
215-
suffix = item[2:] # e.g. tsv (1st choice) or xyz (2nd choice)
216-
217-
# Save pandas.DataFrame track data to temporary file
218-
file_contexts.append(tempfile_from_dftrack(track=track, suffix=suffix))
219-
else:
220-
raise GMTInvalidInput(f"Unrecognized data type: {type(track)}")
198+
file_contexts = []
199+
for track in tracks:
200+
kind = data_kind(track)
201+
if kind == "file":
202+
file_contexts.append(contextlib.nullcontext(track))
203+
elif kind == "matrix":
204+
# find suffix (-E) of trackfiles used (e.g. xyz, csv, etc) from
205+
# $X2SYS_HOME/TAGNAME/TAGNAME.tag file
206+
lastline = (
207+
Path(os.environ["X2SYS_HOME"], kwargs["T"], f"{kwargs['T']}.tag")
208+
.read_text(encoding="utf8")
209+
.strip()
210+
.split("\n")[-1]
211+
) # e.g. "-Dxyz -Etsv -I1/1"
212+
for item in sorted(lastline.split()): # sort list alphabetically
213+
if item.startswith(("-E", "-D")): # prefer -Etsv over -Dxyz
214+
suffix = item[2:] # e.g. tsv (1st choice) or xyz (2nd choice)
215+
216+
# Save pandas.DataFrame track data to temporary file
217+
file_contexts.append(tempfile_from_dftrack(track=track, suffix=suffix))
218+
else:
219+
raise GMTInvalidInput(f"Unrecognized data type: {type(track)}")
221220

221+
with Session() as lib:
222222
with lib.virtualfile_out(kind="dataset", fname=outfile) as vouttbl:
223223
with contextlib.ExitStack() as stack:
224224
fnames = [stack.enter_context(c) for c in file_contexts]

0 commit comments

Comments
 (0)