-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3a0e32
commit 044aa42
Showing
11 changed files
with
154 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: eo-datascience | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- python=3.10 | ||
- pip | ||
- mamba | ||
- jupyter | ||
- nbformat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["setuptools"] | ||
build-backend = "setuptools.build_meta" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[metadata] | ||
name = eo_datascience | ||
version = attr: eo_datascience.__version__ | ||
description = Examples of TUWien Jupyter notebooks for education | ||
author = TU Wien GEO MRS group | ||
author_email = [email protected] | ||
long_description = file: README.md | ||
url = https://github.com/TUW-GEO/eo-datascience | ||
platforms = any | ||
classifiers = | ||
Intended Audience :: Science/Research | ||
Topic :: Scientific/Engineering | ||
Topic :: Scientific/Engineering :: GIS | ||
Topic :: Software Development :: Libraries | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3.8 | ||
Programming Language :: Python :: 3.9 | ||
Operating System :: POSIX | ||
Natural Language :: English | ||
|
||
[options] | ||
package_dir = | ||
= src | ||
packages = find: | ||
install_requires = | ||
nbformat | ||
|
||
[options.packages.find] | ||
where = src | ||
|
||
[options.extras_require] | ||
test = | ||
pytest | ||
pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from setuptools import setup | ||
|
||
setup() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from eo_datascience._version import __commit__ | ||
from eo_datascience._version import __version__ | ||
|
||
name = "eo_datascience" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__version__ = "v0.0.0" | ||
__commit__ = "0000000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import os | ||
import nbformat | ||
from pathlib import Path | ||
|
||
def clean_up_frontmatter(dir = './notebooks', save=False): | ||
# Define the path to the notebooks | ||
nb_paths = find_ipynb(dir) | ||
|
||
# Iterate over the notebooks | ||
for nb_path in nb_paths: | ||
# Load the notebook | ||
nb = nbformat.read(nb_path, as_version=4) | ||
if nb.cells[0].source.startswith('---'): | ||
#Load frontmatter | ||
fm = nb.cells[0].source.split('\n') | ||
|
||
# Extract the title and the subtitle | ||
title, subtitle = '', '' | ||
for line in fm: | ||
if line.startswith('title'): | ||
title = line.split(': ')[1] | ||
if line.startswith('subtitle'): | ||
subtitle = line.split(': ')[1] | ||
|
||
# Update the cell | ||
nb.cells[0].source = f'# {title}\n{subtitle}\n' | ||
|
||
# Save the notebook | ||
if save: | ||
nbformat.write(nb, nb_path) | ||
else: | ||
return nb | ||
|
||
def convert_refs(dir="./notebooks", save=True): | ||
nb_paths = find_ipynb(dir) | ||
|
||
# Iterate over the notebooks | ||
for nb_path in nb_paths: | ||
# Load the notebook | ||
nb = nbformat.read(nb_path, as_version=4) | ||
for i in range(len(nb.cells)): | ||
if i != 0: | ||
nb.cells[i].source = nb.cells[i].source.replace(r"[@", r"{cite}`").replace(r"]", r"`") | ||
|
||
# Save the notebook | ||
if save: | ||
nbformat.write(nb, nb_path) | ||
else: | ||
return nb | ||
|
||
def find_ipynb(dir): | ||
root = Path(dir).resolve() | ||
nb_paths = [root / file for file in os.listdir(root) if file.endswith('.ipynb')] | ||
return nb_paths | ||
|
||
def main(): | ||
clean_up_frontmatter() | ||
|
||
if __name__ == '__main__': | ||
main() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"---\n", | ||
"title: This a mock Jupyter file\n", | ||
"subtitle: We use it for testing\n", | ||
"author: anonymous\n", | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"[@ref1] " | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import nbformat | ||
from pathlib import Path | ||
import pytest | ||
from eo_datascience.clean_nb import clean_up_frontmatter, convert_refs | ||
|
||
def test_remove_front_matter(): | ||
assert clean_up_frontmatter("./tests", False)["cells"][0]["source"] == "# This a mock Jupyter file\nWe use it for testing\n" | ||
|
||
def test_conversion_of_refs(): | ||
assert convert_refs("./tests", False)["cells"][1]["source"] == r'{cite}`ref1` ' |