Skip to content

Commit

Permalink
Temporary text notebooks are created in notebook directory
Browse files Browse the repository at this point in the history
when using the --pipe or --check commands
  • Loading branch information
mwouts committed Mar 24, 2024
1 parent 1ef1dea commit f33e519
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Jupytext ChangeLog
==================

1.16.2-dev (2024-03-??)
-------------------

**Changed**
- Temporary text notebooks for the `--pipe` or `--check` commands are now created in the notebook directory ([#1206](https://github.com/mwouts/jupytext/issues/1206))


1.16.1 (2024-01-13)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- defaults
- conda-forge
dependencies:
- python>=3.8
- python>=3.8,<3.12
- jupyterlab>=4.0.0
- nbformat>=5.1.2
- pre-commit
Expand Down
24 changes: 21 additions & 3 deletions src/jupytext/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,10 +659,20 @@ def jupytext_single_file(nb_file, args, log):

# II. ### Apply commands onto the notebook ###
# Pipe the notebook into the desired commands
prefix = None if nb_file == "-" else os.path.splitext(os.path.basename(nb_file))[0]
if nb_file == "-":
prefix = None
directory = None
else:
prefix = os.path.splitext(os.path.basename(nb_file))[0]
directory = os.path.dirname(nb_file)
for cmd in args.pipe or []:
notebook = pipe_notebook(
notebook, cmd, args.pipe_fmt, prefix=prefix, warn_only=args.warn_only
notebook,
cmd,
args.pipe_fmt,
prefix=prefix,
directory=directory,
warn_only=args.warn_only,
)

# and/or test the desired commands onto the notebook
Expand All @@ -673,6 +683,7 @@ def jupytext_single_file(nb_file, args, log):
args.pipe_fmt,
update=False,
prefix=prefix,
directory=directory,
warn_only=args.warn_only,
)

Expand Down Expand Up @@ -1143,7 +1154,13 @@ def exec_command(command, input=None, capture=False, warn_only=False):


def pipe_notebook(
notebook, command, fmt="py:percent", update=True, prefix=None, warn_only=False
notebook,
command,
fmt="py:percent",
update=True,
prefix=None,
directory=None,
warn_only=False,
):
"""Pipe the notebook, in the desired representation, to the given command. Update the notebook
with the returned content if desired."""
Expand All @@ -1167,6 +1184,7 @@ def pipe_notebook(
encoding="utf8",
prefix=prefix,
suffix=fmt["extension"],
dir=directory,
delete=False,
)
try:
Expand Down
2 changes: 1 addition & 1 deletion src/jupytext/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Jupytext's version number"""

__version__ = "1.16.1"
__version__ = "1.16.2-dev"

0 comments on commit f33e519

Please sign in to comment.