From b3293ca2d2909c50eb3b01716b1eaeac4e988599 Mon Sep 17 00:00:00 2001 From: msschwartz21 Date: Tue, 23 Jul 2024 18:05:31 -0400 Subject: [PATCH] Remove stale files and update readme to be more accurate --- README.md | 8 ++++++-- convert-solution.py | 41 ----------------------------------------- prepare-exercise.sh | 10 ---------- setup.sh | 16 ++++++++++------ 4 files changed, 16 insertions(+), 59 deletions(-) delete mode 100644 convert-solution.py delete mode 100644 prepare-exercise.sh diff --git a/README.md b/README.md index dce552d..47dec24 100644 --- a/README.md +++ b/README.md @@ -17,5 +17,9 @@ jupyter lab ``` ## TA Info -- For development purposes please install `black`, `jupytext` and `nbconvert`. To generate the solution and exercise notebooks from `solution.py`, run `sh prepare-exercise.sh`. -- The `setup.sh` has to install jupyter lab with `mamba install -y -c conda-forge jupyterlab`. +Each exercise should contain at least three files: +- `README.md` contains very short setup instructions. Instruct students to run the setup script and then to run `jupyter lab` from the base environment. +- `solution.py` is a python script formatted for display/conversion to a jupyter notebook. You can use `jupytext` when you are writing your exercise so that this happens almost automatically. Please tag task and solution cells so that they can be removed from solution and exercise notebooks respectively. + - The github action `build-notebooks` included in this repo will automatically generate two notebooks from `solution.py` : `exercise.ipynb` and `solution.ipynb` +- `setup.sh` is a bash script to run all setup tasks needed to use the notebook, e.g. create environment, pip installs, data download, data extraction, etc. Please comment the script so that students can understand what you did. Additionally the first cell of your notebook should recap what happened in the setup script. + - Reactivate base environment at the end of the script so that students are prepared to run `jupyter lab` to start the exercise \ No newline at end of file diff --git a/convert-solution.py b/convert-solution.py deleted file mode 100644 index 279f787..0000000 --- a/convert-solution.py +++ /dev/null @@ -1,41 +0,0 @@ -import argparse -from traitlets.config import Config -import nbformat as nbf -from nbconvert.preprocessors import TagRemovePreprocessor, ClearOutputPreprocessor -from nbconvert.exporters import NotebookExporter - - -def get_arg_parser(): - parser = argparse.ArgumentParser() - - parser.add_argument('input_file') - parser.add_argument('output_file') - - return parser - - -def convert(input_file, output_file): - c = Config() - c.TagRemovePreprocessor.remove_cell_tags = ("solution",) - c.TagRemovePreprocessor.enabled = True - c.ClearOutputPreprocesser.enabled = True - c.NotebookExporter.preprocessors = [ - "nbconvert.preprocessors.TagRemovePreprocessor", - "nbconvert.preprocessors.ClearOutputPreprocessor" - ] - - exporter = NotebookExporter(config=c) - exporter.register_preprocessor(TagRemovePreprocessor(config=c), True) - exporter.register_preprocessor(ClearOutputPreprocessor(), True) - - output = NotebookExporter(config=c).from_filename(input_file) - with open(output_file, 'w') as f: - f.write(output[0]) - - -if __name__ == "__main__": - parser = get_arg_parser() - args = parser.parse_args() - - convert(args.input_file, args.output_file) - print(f'Converted {args.input_file} to {args.output_file}') diff --git a/prepare-exercise.sh b/prepare-exercise.sh deleted file mode 100644 index be605ce..0000000 --- a/prepare-exercise.sh +++ /dev/null @@ -1,10 +0,0 @@ -# Run black on .py files -black solution.py - -# Convert .py to ipynb -# "cell_metadata_filter": "all" preserve cell tags including our solution tags -jupytext --to ipynb --update-metadata '{"jupytext": {"cell_metadata_filter":"all"}}' solution.py - -# Create the exercise notebook by removing cell outputs and deleting cells tagged with "solution" -# There is a bug in the nbconvert cli so we need to use the python API instead -python convert-solution.py solution.ipynb exercise.ipynb diff --git a/setup.sh b/setup.sh index 5da968a..457bf82 100644 --- a/setup.sh +++ b/setup.sh @@ -1,10 +1,14 @@ +envname = 000-example-exercise + # Create environment name based on the exercise name -mamba create -n 000-example-exercise python=3.10 -mamba activate 000-example-exercise -# Install additional requirements -mamba install numpy pandas matplotlib +mamba create -n $envname python=3.10 +if [[ "$CONDA_DEFAULT_ENV" == "$envname" ]]; then + echo "Environment activated successfully for package installs" + mamba install numpy pandas matplotlib +else + echo "Failed to activate environment for package installs. Dependencies not installed!" # Return to base environment -mamba activate base +mamba deactivate; mamba activate base -# Download and extract data, etc. +# Download and extract data, etc. \ No newline at end of file