|
36 | 36 |
|
37 | 37 | """ |
38 | 38 |
|
39 | | -__version__ = "1.4.0" |
| 39 | +__version__ = "1.5.0" |
40 | 40 |
|
41 | 41 | # We don't import Matplotlib here as this brings in NumPy. In turn, NumPy |
42 | 42 | # caches a reference to the io.open() method as part of its data loading |
@@ -410,6 +410,7 @@ def _config_reset(): |
410 | 410 | 'figure_background': '', |
411 | 411 | 'axes_background': 'white', |
412 | 412 | 'extra_tracking': '', |
| 413 | + 'environment': '', |
413 | 414 | }, |
414 | 415 |
|
415 | 416 | 'paths': { |
@@ -705,24 +706,39 @@ def setup_figure(width=1.0, height=1.0, columns=None, margin=False, |
705 | 706 | """ |
706 | 707 | global _config, _interactive |
707 | 708 |
|
708 | | - # Need to install our file trackers (if desired) |
709 | | - # before we import Matplotlib. |
710 | | - if 'PGFUTILS_TRACK_FILES' in os.environ: |
711 | | - _install_standard_file_trackers() |
712 | | - |
713 | 709 | # Reset the configuration. |
714 | 710 | _config_reset() |
715 | 711 |
|
716 | 712 | # Load configuration from a local file if one exists. |
717 | 713 | if os.path.exists('pgfutils.cfg'): |
718 | 714 | _config.read('pgfutils.cfg') |
| 715 | + _file_tracker.filenames.add(("r", "pgfutils.cfg")) |
719 | 716 |
|
720 | 717 | # And anything given in the function call. |
721 | 718 | if kwargs: |
722 | 719 | _config.read_kwargs(**kwargs) |
723 | 720 |
|
724 | | - # Now we can add any extra trackers specified in the config. |
| 721 | + # Set environment variables specified in the configuration. |
| 722 | + for line in _config['pgfutils']['environment'].splitlines(): |
| 723 | + line = line.strip() |
| 724 | + if not line: |
| 725 | + continue |
| 726 | + |
| 727 | + # Check the variables are formatted correctly. |
| 728 | + if '=' not in line: |
| 729 | + raise ValueError( |
| 730 | + "Environment variables should be in the form NAME=VALUE. " |
| 731 | + "The line '{}' does not match this.".format(line) |
| 732 | + ) |
| 733 | + |
| 734 | + # And set them. |
| 735 | + key, value = line.split("=", 1) |
| 736 | + os.environ[key.strip()] = value.strip() |
| 737 | + |
| 738 | + # Install file trackers if desired. This must be done before anything which |
| 739 | + # imports Matplotlib. |
725 | 740 | if 'PGFUTILS_TRACK_FILES' in os.environ: |
| 741 | + _install_standard_file_trackers() |
726 | 742 | extra = _config['pgfutils']['extra_tracking'].strip() |
727 | 743 | if extra: |
728 | 744 | _install_extra_file_trackers(extra.split(",")) |
|
0 commit comments