Skip to content

Quarto deletes the original index.ipynb file when rendering a different notebook (index.render.ipynb) with output-file: index, despite the original file being explicitly ignored in the project configuration. #10841

Open

Description

@mckabue

Bug description

Quarto unexpectedly deletes the original index.ipynb file when rendering a different notebook (index.render.ipynb) with output-file: index, despite the original file being explicitly ignored in the project configuration.

_quarto.yml

project:
  type: website
  render:
   - '*.ipynb'
   - '!index.ipynb'
website:
  title: "Test"
format:
  html: default
  pdf: default
  # When the following line is uncommented, the "index.ipynb" file is deleted upon render
  # ipynb: default

index.ipynb

{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "---\n",
        "title: \"Test - index.ipynb\"\n",
        "---\n",
        "\n",
        "## Test - index.ipynb\n",
        "\n",
        "This is a Quarto website.\n",
        "\n",
        "To learn more about Quarto websites visit <https://quarto.org/docs/websites>."
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}

index.render.ipynb

{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "---\n",
        "title: \"Test - index.render.ipynb\"\n",
        "output-file: index\n",
        "---\n",
        "\n",
        "## Test - index.render.ipynb\n",
        "\n",
        "This is a Quarto website.\n",
        "\n",
        "To learn more about Quarto websites visit <https://quarto.org/docs/websites>."
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}

Note: The bug appears to be triggered when the ipynb: default format is uncommented in _quarto.yml. When this line is commented out, the original index.ipynb is not deleted.

Steps to reproduce

  1. Create a Quarto project with the following files:

    • index.ipynb: A standard Quarto notebook
    • index.render.ipynb: A notebook with output-file: index in its YAML front matter
    • _quarto.yml: A project configuration file with !index.ipynb in the render options
  2. Ensure _quarto.yml contains:

    project:
      type: website
      render:
       - '*.ipynb'
       - '!index.ipynb'
    website:
      title: "Test"
    format:
      html: default
      pdf: default
      ipynb: default
  3. Run quarto render to build the project.

Note: The bug appears to be triggered when the ipynb: default format is uncommented in _quarto.yml. When this line is commented out, the original index.ipynb is not deleted.

Expected behavior

  • index.render.ipynb should be rendered as index.html, index.pdf and index.ipynb in the output directory.
  • The original index.ipynb should remain untouched, as it's specified to be ignored in _quarto.yml.

Actual behavior

  • index.render.ipynb is correctly rendered as index.html, index.pdf and index.ipynb in the output directory.
  • The original index.ipynb is unexpectedly deleted, despite being specified as ignored in the project configuration.

Your environment

Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.5 LTS
Release:	22.04
Codename:	jammy

Quarto check output

Quarto 1.5.57
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.57
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: (external install)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/anon-b/.TinyTeX/bin/aarch64-linux
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.10.12
      Path: /usr/bin/python3
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/

Activity

  1. added
    bug
    on Sep 19, 2024
  2. mckabue commented on Sep 19, 2024

    @mckabue
    Author

    Some context:

    Why do I have such a setup? index.ipynb is my main source file. It has logic that cant be be naturally processed by quarto. the logic is a bit complex so notebook filters cant handle it (it too late). so the logic is handled by a pre-render. the prerender script generates a new file (index.render.ipynb) that quarto is able to process, and index.ipynb is added to ignored files. however, i want quarto to output as if nothing changed, the final files should be index.html, index.pdf and index.ipynb from index.render.ipynb

  3. cderv commented on Sep 20, 2024

    @cderv
    Member

    Note: The bug appears to be triggered when the ipynb: default format is uncommented in _quarto.yml. When this line is commented out, the original index.ipynb is not deleted.

    When setting format: ipynb, you are asking Quarto explicitly to render to a .ipynb file. Our current logic is to use <stem>.<ext> and use the base name of the input. Unless there is clash between input and output, and we add .out

    So quarto render test.ipynb --to ipynb leads to test.out.ipynb.

    Though when output-file is specified, it overwrites as it is user specified. So doing output-file: index, means that quarto will wirte output to <stem>.<ext> and <stem> will be the specific output-file.

    This means quarto render index.render.ipynb --to ipynb will output to index.ipynb

    Hope this clarify the behavior on this. Let's see now the related problem

    Expected behavior

    • index.render.ipynb should be rendered as index.html, index.pdf and index.ipynb in the output directory.
    • The original index.ipynb should remain untouched, as it's specified to be ignored in _quarto.yml.

    I think the expectation is not correct considering how Quarto works in related to output-dir and why the output-file configuration is creating the conflict.

    Quarto will move rendered file outputs to output directory after rendering.

    So when quarto render index.render.ipynb --to ipynb runs, it will overwrites the index.ipynb and then move this output file to the output directory.

    This is definitely a problem, among others related to paths computation, and we have high hope in this to solve it

    You can find a list of issues there too, some of them related to this one.

    So until this is done, you need to adapt your workflow to avoid having your index.ipynb that Quarto is supposed to ignore in the same place that your Quarto ipynb input.

    Ideas to help

    • Rename your index.ipynb to _index.ipynb so that Quarto knows to ignore, and it won't be overwritten by output ?
    • Don't set outfile to index
      • Rename you index.render.out.ipynb in a post render project step to your final index.ipynb once moved in output dir

    And maybe other.

    Sorry for the inconvenience on this, #6518 is necessary to solve all those types of problem the right way.

  4. added this to the Future milestone on Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions