Skip to content

Commit 2454aa6

Browse files
Document the environment variables that can affect the behavior of PyGMT (#3432)
Co-authored-by: Yvonne Fröhlich <[email protected]>
1 parent 5196ae6 commit 2454aa6

File tree

10 files changed

+74
-23
lines changed

10 files changed

+74
-23
lines changed

doc/_static/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,7 @@ th.text-center, td.text-center {
219219
th.text-right, td.text-right {
220220
text-align: right !important;
221221
}
222+
223+
.std-term {
224+
font-weight: 600;
225+
}

doc/install.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,17 +269,17 @@ problems and solutions.
269269
Sometimes, PyGMT will be unable to find the correct version of the GMT shared library
270270
(`libgmt`). This can happen if you have multiple versions of GMT installed.
271271

272-
You can tell PyGMT exactly where to look for `libgmt` by setting the `GMT_LIBRARY_PATH`
273-
environment variable to the directory where `libgmt.so`, `libgmt.dylib` or `gmt.dll` can
274-
be found on Linux, macOS or Windows, respectively.
272+
You can tell PyGMT exactly where to look for `libgmt` by setting the environment
273+
variable {term}`GMT_LIBRARY_PATH` to the directory where `libgmt.so`, `libgmt.dylib` or
274+
`gmt.dll` can be found on Linux, macOS or Windows, respectively.
275275

276276
For Linux/macOS, add the following line to your shell configuration file (usually
277277
`~/.bashrc` for Bash on Linux and `~/.zshrc` for Zsh on macOS):
278278
```
279279
export GMT_LIBRARY_PATH=$HOME/miniforge3/envs/pygmt/lib
280280
```
281281

282-
For Windows, add the `GMT_LIBRARY_PATH` environment variable following these
282+
For Windows, add the environment variable {term}`GMT_LIBRARY_PATH` following these
283283
[instructions](https://www.wikihow.com/Create-an-Environment-Variable-in-Windows-10)
284284
and set its value to a path like:
285285
```

doc/techref/environment_variables.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Environment Variables
2+
3+
PyGMT's behavior can be controlled through various environment variables. These variables
4+
can be set either in your shell environment or within your Python script using the
5+
{py:data}`os.environ` dictionary.
6+
7+
Here we list the environment variables used by PyGMT which are categorized into three groups:
8+
9+
1. System environment variables
10+
2. GMT/PyGMT environment variables
11+
3. Module-specific environment variables
12+
13+
## System Environment Variables
14+
15+
```{glossary}
16+
TZ
17+
Specify the time zone for the current calendar time. It can be set to a string that
18+
defines the timezone, such as `"UTC"`, `"America/New_York"`, or `"Europe/London"`.
19+
Refer to [Specifying the Time Zone with TZ](https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html)
20+
for the valid format. If not set, the system's default timezone is used.
21+
```
22+
23+
## GMT/PyGMT Environment Variables
24+
25+
```{glossary}
26+
GMT_LIBRARY_PATH
27+
Specify the directory where the GMT shared library is located. This is useful when
28+
GMT is installed in a non-standard location or when you want to use a specific
29+
version of GMT. If not set, PyGMT will attempt to find the GMT library in standard
30+
system locations.
31+
32+
PYGMT_USE_EXTERNAL_DISPLAY
33+
Whether to use external viewers for displaying images. If set to `"false"`, PyGMT
34+
will not attempt to open images in external viewers. This can be useful when running
35+
tests or building the documentation to avoid popping up windows.
36+
```
37+
38+
## Module-Specific Environment Variables
39+
40+
```{glossary}
41+
X2SYS_HOME
42+
Specify the directory where x2sys databases and related settings will be stored.
43+
This environment variable is used by x2sys-related functions (e.g.,
44+
{func}`pygmt.x2sys_init`) to manage and access x2sys data. If not set, these
45+
functions will use a default directory or prompt for a location.
46+
```

doc/techref/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ visit the {gmt-docs}`GMT Technical Reference <reference.html>`.
1111
projections.md
1212
fonts.md
1313
encodings.md
14+
environment_variables
1415
```

pygmt/clib/loading.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Utility functions to load libgmt as ctypes.CDLL.
33
44
The path to the shared library can be found automatically by ctypes or set through the
5-
GMT_LIBRARY_PATH environment variable.
5+
environment variable :term:`GMT_LIBRARY_PATH`.
66
"""
77

88
import ctypes
@@ -128,9 +128,9 @@ def clib_full_names(env: Mapping | None = None) -> Iterator[str]:
128128
129129
The GMT shared library is searched for in following ways, sorted by priority:
130130
131-
1. Path defined by environmental variable GMT_LIBRARY_PATH
132-
2. Path returned by command "gmt --show-library"
133-
3. Path defined by environmental variable PATH (Windows only)
131+
1. Path defined by the environment variable :term:`GMT_LIBRARY_PATH`
132+
2. Path returned by the command "gmt --show-library"
133+
3. Path defined by the environment variable PATH (Windows only)
134134
4. System default search path
135135
136136
Parameters

pygmt/clib/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class Session:
116116
same ``with`` block as the API calls that will use the data.
117117
118118
By default, will let :mod:`ctypes` try to find the GMT shared library
119-
(``libgmt``). If the environment variable ``GMT_LIBRARY_PATH`` is set, will
119+
(``libgmt``). If the environment variable :term:`GMT_LIBRARY_PATH` is set, will
120120
look for the shared library in the directory specified by it.
121121
122122
A ``GMTVersionError`` exception will be raised if the GMT shared library

pygmt/figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def _get_default_display_method() -> Literal["external", "notebook", "none"]:
4343
The default display method is ``"notebook"`` in the Jupyter notebook environment,
4444
and ``"external"`` in other cases.
4545
46-
Setting environment variable **PYGMT_USE_EXTERNAL_DISPLAY** to ``"false"`` can
46+
Setting environment variable :term:`PYGMT_USE_EXTERNAL_DISPLAY` to ``"false"`` can
4747
disable image preview in external viewers. It's useful when running the tests and
4848
building the documentation to avoid popping up windows.
4949
@@ -421,8 +421,8 @@ def show(
421421
resolution and dimension of the figure in the notebook.
422422
423423
The external viewer can be disabled by setting the environment variable
424-
**PYGMT_USE_EXTERNAL_DISPLAY** to ``"false"``. This is useful when running tests
425-
and building the documentation to avoid popping up windows.
424+
:term:`PYGMT_USE_EXTERNAL_DISPLAY` to ``"false"``. This is useful when running
425+
tests and building the documentation to avoid popping up windows.
426426
427427
The external viewer does not block the current process, thus it's necessary to
428428
suspend the execution of the current process for a short while after launching

pygmt/src/timestamp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def timestamp(
2727
2828
Add the GMT timestamp logo with an optional label at the bottom-left corner of a
2929
plot with an offset of ``("-54p", "-54p")``. The timestamp will be in the locale set
30-
by the environment variable **TZ** (generally local time but can be changed via
30+
by the environment variable :term:`TZ` (generally local time but can be changed via
3131
``os.environ["TZ"]``) and its format is controlled by the ``timefmt`` parameter. It
3232
can also be replaced with any custom text string using the ``text`` parameter.
3333

pygmt/src/x2sys_cross.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ def x2sys_cross(
9696
or file names. Supported file formats are ASCII, native binary, or
9797
COARDS netCDF 1-D data. More columns may also be present.
9898
99-
If the file names are missing their file extension, we will append the
100-
suffix specified for this TAG. Track files will be searched for first
101-
in the current directory and second in all directories listed in
102-
$X2SYS_HOME/TAG/TAG_paths.txt (if it exists). [If $X2SYS_HOME is not
103-
set it will default to $GMT_SHAREDIR/x2sys]. (**Note**: MGD77 files
104-
will also be looked for via $MGD77_HOME/mgd77_paths.txt and .gmt
105-
files will be searched for via $GMT_SHAREDIR/mgg/gmtfile_paths).
99+
If the file names are missing their file extension, we will append the suffix
100+
specified for this TAG. Track files will be searched for first in the current
101+
directory and second in all directories listed in $X2SYS_HOME/TAG/TAG_paths.txt
102+
(if it exists). [If environment variable :term:`X2SYS_HOME` is not set it will
103+
default to $GMT_SHAREDIR/x2sys]. (**Note**: MGD77 files will also be looked for
104+
via $MGD77_HOME/mgd77_paths.txt and .gmt files will be searched for via
105+
$GMT_SHAREDIR/mgg/gmtfile_paths).
106106
107107
outfile
108108
The file name for the output ASCII txt file to store the table in.

pygmt/src/x2sys_init.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def x2sys_init(tag, **kwargs):
3030
x2sys TAG. The TAG keeps track of settings such as file format, whether the
3131
data are geographic or not, and the binning resolution for track indices.
3232
33-
Before you can run :func:`pygmt.x2sys_init` you must set the environmental
34-
parameter X2SYS_HOME to a directory where you have write permission, which
35-
is where x2sys can keep track of your settings.
33+
Before you can run :func:`pygmt.x2sys_init` you must set the environment variable
34+
:term:`X2SYS_HOME` to a directory where you have write permission, which is where
35+
x2sys can keep track of your settings.
3636
3737
Full option list at :gmt-docs:`supplements/x2sys/x2sys_init.html`
3838

0 commit comments

Comments
 (0)