From 88065f90f6b815a0e0eb7efe3d4c9432cff408c5 Mon Sep 17 00:00:00 2001 From: Wei Ji Date: Sun, 17 May 2020 21:35:59 +1200 Subject: [PATCH 1/4] Set GMT_COMPATIBILITY to 6 when pygmt session starts To prevent users getting "pygmt-session [ERROR]: GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6". --- pygmt/session_management.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/session_management.py b/pygmt/session_management.py index cafd306e120..57fcb4c110b 100644 --- a/pygmt/session_management.py +++ b/pygmt/session_management.py @@ -15,6 +15,7 @@ def begin(): prefix = "pygmt-session" with Session() as lib: lib.call_module("begin", prefix) + lib.call_module("set", "GMT_COMPATIBILITY 6") def end(): From 56c0fddbd6021ff921320178af9ea0bee6682e11 Mon Sep 17 00:00:00 2001 From: Wei Ji Date: Mon, 18 May 2020 00:43:51 +1200 Subject: [PATCH 2/4] Add test to ensure GMT_COMPATIBILITY = 6 is set Prevents regression of pygmt-session [ERROR]: GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6. Contains setup, test and teardown of a mock session where the user has a gmt.conf file with GMT_COMPATIBILITY = 5. --- pygmt/tests/test_session_management.py | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/pygmt/tests/test_session_management.py b/pygmt/tests/test_session_management.py index e69f24ec49b..ea39300cd52 100644 --- a/pygmt/tests/test_session_management.py +++ b/pygmt/tests/test_session_management.py @@ -20,3 +20,35 @@ def test_begin_end(): begin() # Restart the global session assert os.path.exists("pygmt-session.pdf") os.remove("pygmt-session.pdf") + + +def test_gmt_compat_6_is_applied(capsys): + """ + Ensure that users with old gmt.conf files won't get pygmt-session [ERROR]: + GMT_COMPATIBILITY: Expects values from 6 to 6; reset to 6. + """ + end() # Kill the global session + try: + with Session() as lib: + # pretend that gmt.conf has GMT_COMPATIBILITY = 5 + lib.call_module("gmtset", "GMT_COMPATIBILITY 5") + begin() + with Session() as lib: + lib.call_module("basemap", "-R10/70/-3/8 -JX4i/3i -Ba") + out, err = capsys.readouterr() # capture stdout and stderr + assert out == "" + assert err != ( + "pygmt-session [ERROR]: GMT_COMPATIBILITY:" + " Expects values from 6 to 6; reset to 6.\n" + ) + assert err == "" # double check that there are no other errors + finally: + with Session() as lib: + # revert gmt.conf back to GMT_COMPATIBILITY = 6 + lib.call_module("set", "GMT_COMPATIBILITY 6") + end() + begin() # Restart the global session + assert os.path.exists("gmt.conf") + os.remove("gmt.conf") + assert os.path.exists("pygmt-session.pdf") + os.remove("pygmt-session.pdf") From fdde97c39fd0b36d5e35748bea080b55f87f8a10 Mon Sep 17 00:00:00 2001 From: Wei Ji <23487320+weiji14@users.noreply.github.com> Date: Mon, 18 May 2020 09:15:17 +1200 Subject: [PATCH 3/4] Add note on why GMT_COMPATIBILITY is set to 6 Co-authored-by: Dongdong Tian --- pygmt/session_management.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pygmt/session_management.py b/pygmt/session_management.py index 57fcb4c110b..e814daf4fb8 100644 --- a/pygmt/session_management.py +++ b/pygmt/session_management.py @@ -15,6 +15,7 @@ def begin(): prefix = "pygmt-session" with Session() as lib: lib.call_module("begin", prefix) + # pygmt relies on GMT modern mode with GMT_COMPATIBILITY at version 6 lib.call_module("set", "GMT_COMPATIBILITY 6") From 2c5580c24d0b11448f254aeadb2acf9858397c52 Mon Sep 17 00:00:00 2001 From: Wei Ji Date: Thu, 21 May 2020 15:16:30 +1200 Subject: [PATCH 4/4] Remove the need to remove gmt.conf file Because it's in a temporary pygmt session folder anyway. --- pygmt/tests/test_session_management.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pygmt/tests/test_session_management.py b/pygmt/tests/test_session_management.py index ea39300cd52..6ca9afa75b5 100644 --- a/pygmt/tests/test_session_management.py +++ b/pygmt/tests/test_session_management.py @@ -48,7 +48,5 @@ def test_gmt_compat_6_is_applied(capsys): lib.call_module("set", "GMT_COMPATIBILITY 6") end() begin() # Restart the global session - assert os.path.exists("gmt.conf") - os.remove("gmt.conf") assert os.path.exists("pygmt-session.pdf") os.remove("pygmt-session.pdf")