Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not reload the Jupytext config file unless a notebook is opened/saved #860

Merged
merged 2 commits into from
Sep 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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