Skip to content

Commit

Permalink
Do not reload the Jupytext config file unless a notebook is opened/saved
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Sep 25, 2021
1 parent 149d0f0 commit f68c31d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
5 changes: 4 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 6 additions & 14 deletions jupytext/contentsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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",
Expand Down

0 comments on commit f68c31d

Please sign in to comment.