From cb1b47becf2a0d3b2570ca9929f42f7d7e472b6f Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Sat, 7 Jan 2023 17:30:56 -0500 Subject: [PATCH] Do not generate json file at runtime This only works with local user installations, it does not work with proper package managers. --- versionwarning/signals.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/versionwarning/signals.py b/versionwarning/signals.py index d80da4c..6fd8122 100644 --- a/versionwarning/signals.py +++ b/versionwarning/signals.py @@ -65,8 +65,13 @@ def generate_versionwarning_data_json(app, config=None, **kwargs): if not os.path.exists(data_path): os.mkdir(data_path) - with open(os.path.join(data_path, JSON_DATA_FILENAME), 'w') as f: - f.write(data) + # Generate json file during build, not at runtime. I am not sure about + # proper way to distinguish these cases, but if build went ok, at runtime + # this file would already exist, probably read-only. + out = os.path.join(data_path, JSON_DATA_FILENAME) + if not os.path.exists(out): + with open(os.path.join(data_path, JSON_DATA_FILENAME), 'w') as f: + f.write(data) # Add the path where ``versionwarning-data.json`` file and # ``versionwarning.js`` are saved