Skip to content

Commit

Permalink
Merge pull request #34 from ICESAT-2HackWeek/nb2pkg_notes
Browse files Browse the repository at this point in the history
Nb2pkg notes
  • Loading branch information
scottyhq authored Aug 23, 2024
2 parents 1133e4f + 3d6051f commit 3b27f7e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
Binary file added book/tutorials/nb-to-package/OOP_annotated.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion book/tutorials/nb-to-package/OOP_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
In this tutorial, we'll be learning how to structure object-oriented code
to take full advantage of this programming paradigm.

Follow along with the slides [`here`](./OOP.pdf)!
Follow along with the slides [`here`](./OOP.pdf)! Here are the [`annotated slides`](./OOP_annotated.pdf) from the tutorial.

We'll be using UCAR's ['Very Simple Climate Model'](https://scied.ucar.edu/interactive/simple-climate-model) as an example.

Expand Down
12 changes: 12 additions & 0 deletions book/tutorials/nb-to-package/simple_eggsample/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "eggsample"
version = "0.1.0"
description = "The eggsample from an eggsellent cook"
requires-python = ">= 3.10"

[project.scripts]
eggsample = "eggsample.cli:main"
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from eggsample.eggsellent_cook import EggsellentCook

def main():
cook = EggsellentCook()
cook.add_ingredients()
cook.prepare_the_food()
cook.serve_the_food()
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import random

condiments_tray = ["pickled walnuts", "steak sauce", "mushy peas"]

class EggsellentCook:
FAVORITE_INGREDIENTS = ("egg", "egg", "egg")

def __init__(self):
self.ingredients = None

def _add_ingredients(self, ingredients):
spices = ["salt", "pepper"]
you_can_never_have_enough_eggs = ["egg", "egg"]
spam = ["lovely spam", "wonderous spam"]
more_spam = ["splendiferous spam", "magnificent spam"]
ingredients = spices + you_can_never_have_enough_eggs + spam + more_spam
return ingredients

def _prep_condiments(self, condiments):
condiments.append("mint sauce")
return ("Now this is what I call a condiments tray!",)

def add_ingredients(self):
results = self._add_ingredients(
ingredients=self.FAVORITE_INGREDIENTS
)
my_ingredients = list(self.FAVORITE_INGREDIENTS)
self.ingredients = my_ingredients + results

def prepare_the_food(self):
random.shuffle(self.ingredients)

def serve_the_food(self):
condiment_comments = self._prep_condiments(
condiments=condiments_tray
)
print(f"Your food. Enjoy some {', '.join(self.ingredients)}")
print(f"Some condiments? We have {', '.join(condiments_tray)}")
if any(condiment_comments):
print("\n".join(condiment_comments))

0 comments on commit 3b27f7e

Please sign in to comment.