Skip to content

Commit a1a28ee

Browse files
committed
__init__ back to nothing and global:
those `copy!(x,y)`s never worked (the error was that x and y of different type) Also: add note for pkg users (i.e. for VoltoMapSim) to set `__precompile__(false)`, and why.
1 parent 8bd00d9 commit a1a28ee

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Sciplotlib.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# A note on precompilation and __init__.
2+
#
3+
# If Sciplotlib is used in another module, then that module must be marked as
4+
# `__precompile__(false)`. If not, during precompilation of that top-level module,
5+
# Sciplotlib's `__init__` will be called [*], which is a function that cannot be called
6+
# during a precompilation phase; it errors then.
7+
#
8+
# [*] Strange but true. Strange cause `__init__` is explicitly made to not be called during
9+
# precompilation. It indeed is not called when precompiling Sciplotlib itself. But it
10+
# _does_ get called when precompiling a downstream package.
11+
112
module Sciplotlib
213

314
using Reexport

src/init.jl

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
1-
# On `PyNULL()` and `copy!`:
2-
# https://github.com/JuliaPy/PyCall.jl/issues/699#issuecomment-504616552
3-
41
"""
52
Matplotlib's style settings [1]. Note that directly editing `mpl.rcParams` has no effect
63
[2]. Editing this object however does work.
74
85
- [1] https://matplotlib.org/stable/tutorials/introductory/customizing.html#the-default-matplotlibrc-file
96
- [2] https://github.com/JuliaPy/PyPlot.jl#modifying-matplotlibrcparams
107
"""
11-
const rcParams = PyNULL()
8+
rcParams = nothing
129

1310
"""
1411
A copy of the initial `mpl.rcParams`. Note that we do not use `mpl.rcParamsDefault` or
1512
`mpl.rcParamsOrig`, as these are different to what's actually used by default (e.g. in a
1613
Jupyter notebook).
1714
"""
18-
const rcParams_original = PyNULL()
15+
rcParams_original = nothing
1916

2017
function __init__()
21-
copy!(rcParams_original, mpl.rcParams)
22-
copy!(rcParams, PyPlot.PyDict(mpl."rcParams")) # String quotes prevent conversion from
23-
# # Python to Julia dict.
18+
global rcParams = PyPlot.PyDict(mpl."rcParams") # String quotes prevent conversion from
19+
# # Python to Julia dict.
20+
global rcParams_original = copy(mpl.rcParams)
2421
set_mpl_style!(sciplotlib_style)
2522
end

0 commit comments

Comments
 (0)