Skip to content
This repository was archived by the owner on Aug 28, 2025. It is now read-only.
12 changes: 5 additions & 7 deletions .actions/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@
"""
TEMPLATE_FOOTER = """
# %% [markdown]
# <code style="color:#792ee5;">
# <h1> <strong> Congratulations - Time to Join the Community! </strong> </h1>
# </code>
# ## Congratulations - Time to Join the Community!
#
# Congratulations on completing this notebook tutorial! If you enjoyed this and would like to join the Lightning
# movement, you can do so in the following ways!
Expand Down Expand Up @@ -165,12 +163,10 @@ def augment_script(fpath: str):

py_file = HelperCLI._replace_images(py_file, os.path.dirname(fpath))

first_empty = min([i for i, ln in enumerate(py_file) if not ln.startswith("#")])
header = TEMPLATE_HEADER % meta
requires = set(default_requirements() + meta["requirements"])
setup = TEMPLATE_SETUP % dict(requirements=" ".join(requires))
py_file[first_empty] = header + setup
py_file.append(TEMPLATE_FOOTER)
py_file = [header + setup] + py_file + [TEMPLATE_FOOTER]

with open(fpath, "w") as fp:
fp.writelines(py_file)
Expand All @@ -191,7 +187,9 @@ def _replace_images(lines: list, local_dir: str) -> list:
# update all images
for img in set(imgs):
url_path = '/'.join([URL_DOWNLOAD, local_dir, img])
md = md.replace(img, url_path)
# todo: add a rule to replace this paths only i md sections
md = md.replace(f'src="{img}"', f'src="{url_path}"')
md = md.replace(f']({img})', f']({url_path})')

return [ln + os.linesep for ln in md.split(os.linesep)]

Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Lightning-Sandbox documentation
:caption: Start here
:glob:

notebooks/*
notebooks/**/*


Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ addopts =
--strict
--doctest-modules
--color=yes
--nbval-cell-timeout=300

[coverage:report]
exclude_lines =
Expand Down
13 changes: 13 additions & 0 deletions template/.meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title: How to write a PyTorch Lightning tutorial
author: PL team
created: 2021-06-16
updated: 2021-06-16
license: CC
description: |
This is a template to show how to contribute a tutorial.
requirements:
- pytorch-lightning
- matplotlib
accelerator:
- CPU
- GPU
47 changes: 47 additions & 0 deletions template/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
# %% [markdown]
# ## Create a Markdown cell
#
# NOTE: Please start each file with declaring UTF8 encoding as `# -*- coding: utf-8 -*-`
#
# `# %% [markdown]`
#
# the content of single cell shall be connected with `# ` at each line, so for example:
# `# Add some text that will be rendered as markdown text.`

# %% [markdown]
# ## Create a code cell
#
# `# %%`

# %%
import torch

print(torch.__version__)

# %% [markdown]
# ## Add any Python codes
# Easy integration with Python ecosystem libraries component.
#
# For example create a simple plot with `matplotlib` with an image:
#
# ![test image](test.png)
#
# From: https://matplotlib.org/stable/gallery/lines_bars_and_markers/simple_plot.html

# %%
import matplotlib.pyplot as plt # noqa: E402
import numpy as np # noqa: E402

# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)

fig, ax = plt.subplots()
ax.plot(t, s)

ax.set(xlabel='time (s)', ylabel='voltage (mV)', title='About as simple as it gets, folks')
ax.grid()

fig.savefig("test.png")
plt.show()
Binary file added template/test.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.