From f68c31de20a748bfe3b65d5e0c8dfd463438df20 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sat, 25 Sep 2021 15:27:37 +0200 Subject: [PATCH] Do not reload the Jupytext config file unless a notebook is opened/saved --- docs/CHANGELOG.md | 5 ++++- jupytext/contentsmanager.py | 20 ++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index a3eb87792..fad271949 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,7 +5,10 @@ Jupytext ChangeLog ----------------------- **Added** -- The `py:percent` format can encode Markdown cells as raw strings (#836) +- The `py:percent` format can encode Markdown cells as raw strings ([#836](https://github.com/mwouts/jupytext/issues/836)) + +**Changed** +- The Jupytext configuration file is reloaded only when a notebook is opened, saved, or when a different folder is explored ([#797](https://github.com/mwouts/jupytext/issues/797)) 1.12.0 (2021-09-09) diff --git a/jupytext/contentsmanager.py b/jupytext/contentsmanager.py index 12ca4d25d..13ed16f88 100644 --- a/jupytext/contentsmanager.py +++ b/jupytext/contentsmanager.py @@ -3,7 +3,7 @@ import itertools import os from collections import namedtuple -from datetime import datetime, timedelta +from datetime import timedelta import nbformat from tornado.web import HTTPError @@ -58,9 +58,7 @@ def __init__(self, *args, **kwargs): self.paired_notebooks = dict() # Configuration cache, useful when notebooks are listed in a given directory - self.cached_config = namedtuple( - "cached_config", "path timestamp config_file config" - ) + self.cached_config = namedtuple("cached_config", "path config_file config") self.super = super(JupytextContentsManager, self) self.super.__init__(*args, **kwargs) @@ -501,15 +499,10 @@ def get_config(self, path, use_cache=False): """Return the Jupytext configuration for the given path""" parent_dir = self.get_parent_dir(path) - # When listing the notebooks for the tree view, we use a one-second - # cache for the configuration file - if ( - not use_cache - or parent_dir != self.cached_config.path - or ( - self.cached_config.timestamp + timedelta(seconds=1) < datetime.now() - ) - ): + # When listing the notebooks for the tree view, we use a cache for the configuration file + # The cache will be refreshed when a notebook is opened or saved, or when we go + # to a different directory. + if not use_cache or parent_dir != self.cached_config.path: try: config_file = self.get_config_file(parent_dir) if config_file: @@ -521,7 +514,6 @@ def get_config(self, path, use_cache=False): ) self.cached_config.config_file = config_file self.cached_config.path = parent_dir - self.cached_config.timestamp = datetime.now() except JupytextConfigurationError as err: self.log.error( u"Error while reading config file: %s %s",