Skip to content

Commit 94a3433

Browse files
committed
Don't open the file to be renamed
unless it is a notebook
1 parent 518ab60 commit 94a3433

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Jupytext ChangeLog
22
==================
33

4+
1.17.1 (2025-04-26)
5+
-------------------
6+
7+
**Fixed**
8+
- Renaming files other than notebooks will not load their content ([#1376](https://github.com/mwouts/jupytext/issues/1376))
9+
10+
411
1.17.0 (2025-04-05)
512
-------------------
613

src/jupytext/async_contentsmanager.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,25 @@ async def trust_notebook(self, path):
530530
await self.super.trust_notebook(alt_path)
531531

532532
async def rename_file(self, old_path, new_path):
533-
"""Rename the current notebook, as well as its alternative representations"""
533+
"""
534+
Rename the current file. If the file is a notebook,
535+
we rename the paired files as well
536+
"""
537+
538+
# If the file is not a notebook, we call the parent rename_file method
539+
ext = os.path.splitext(old_path)[1]
540+
config = await self.get_config(old_path, use_cache=True)
541+
if ext not in self.all_nb_extensions(config):
542+
await self.super.rename_file(old_path, new_path)
543+
return
544+
534545
if old_path not in self.paired_notebooks:
535546
try:
536547
# we do not know yet if this is a paired notebook (#190)
537548
# -> to get this information we open the notebook
549+
self.log.info(
550+
"Opening %s to check if it is a paired notebook", old_path
551+
)
538552
await self.get(old_path, content=True)
539553
except Exception:
540554
pass

src/jupytext/sync_contentsmanager.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,25 @@ def trust_notebook(self, path):
536536
self.super.trust_notebook(alt_path)
537537

538538
def rename_file(self, old_path, new_path):
539-
"""Rename the current notebook, as well as its alternative representations"""
539+
"""
540+
Rename the current file. If the file is a notebook,
541+
we rename the paired files as well
542+
"""
543+
544+
# If the file is not a notebook, we call the parent rename_file method
545+
ext = os.path.splitext(old_path)[1]
546+
config = self.get_config(old_path, use_cache=True)
547+
if ext not in self.all_nb_extensions(config):
548+
self.super.rename_file(old_path, new_path)
549+
return
550+
540551
if old_path not in self.paired_notebooks:
541552
try:
542553
# we do not know yet if this is a paired notebook (#190)
543554
# -> to get this information we open the notebook
555+
self.log.info(
556+
"Opening %s to check if it is a paired notebook", old_path
557+
)
544558
self.get(old_path, content=True)
545559
except Exception:
546560
pass

src/jupytext/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Jupytext's version number"""
22

3-
__version__ = "1.17.0"
3+
__version__ = "1.17.1"

0 commit comments

Comments
 (0)