Skip to content

Commit

Permalink
Do not reload the Jupytext config file unless a notebook is opened/sa…
Browse files Browse the repository at this point in the history
…ved (#860)
  • Loading branch information
mwouts authored Sep 25, 2021
1 parent 3798409 commit f7c69be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Jupytext ChangeLog
**Fixed**
- We have upgraded the jupyterlab extension dependencies and especially `ansi-regex` to fix a security vulnerability ([#857](https://github.com/mwouts/jupytext/issues/857))

**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 @@ -531,15 +529,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 @@ -551,7 +544,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 f7c69be

Please sign in to comment.