fsfe / reuse-tool

reuse is a tool for compliance with the REUSE recommendations.
https://reuse.software
413 stars 150 forks source link

Add license to Jupyter notebooks as Markdown cell #1053

Open SJaffa opened 4 months ago

SJaffa commented 4 months ago

Jupyter notebooks are currently treated as "Uncommentable". Could the license information be added as a new Markdown cell at the top of the notebook rather than a comment or a separate .license file?

carmenbianca commented 4 months ago

Hi @SJaffa. Can you give an example?

SJaffa commented 4 months ago

A Jupyter notebook's underlying structure is a JSON file containing a list of cells. Example:

{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9b216162",
   "metadata": {},
   "source": [
    "First markdown cell text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "505c6c8f",
   "metadata": {},
   "source": [
    "Second markdown cell text"
   ]
  },
...
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

If you can identify the start of the "cells": [ list you can add a new cell at the top containing the license text in the source:

  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "License text here"
   ]
  },

All the cells have an id but I experimented with adding a new cell to the JSON without an id and it seems to work fine and just adds that field when it renders it.