adds exercises from last year for reference

This commit is contained in:
Pamela Hathway 2024-07-17 23:32:38 +02:00
parent c622d3ba31
commit 6204803ef9
5 changed files with 148 additions and 0 deletions

View file

@ -0,0 +1,41 @@
## Exercise 1: Virtual Environments
#### Goal
Create a virtual environment + install a package + see that that package was installed only in environment
#### Tasks
We will use `venv` as our environment manager - while commands might differ, the principles apply to all other package managers as well.
1. Check which Python you are currently using, and which packages are installed. Also check which folders are in the folder you are installing the environment into.
3. Create and activate a new environment.
4. Check again which Python you are using and which packages are installed - are they different?
5. Install a specific version of a package using pip e.g. pandas=1.5.3
6. See that dependencies are also installed (more packages than only pandas appear)
7. Deactivate and delete the environment
#### Commands in case you get stuck (not in correct order):
```bash
% investigate Python and packages
> which python
> pip freeze
> pip install <package-name>
> pip install <package-name>==0.0.1
% create an environment option 1 (create folder called venv_folder for files related to virtual environment, feel free to change the name)
> cd <path-to-project_folder>
> mkdir venv_folder
> python3 -m venv venv_folder
> source venv_folder/bin/activate
% create an environment option 2
> python3 -m venv <path-to-folder-for-venv>
> source <path-to-folder-for-venv>/bin/activate
% deactivate and delete a venv environment
> deactivate
> rm -rf venv_folder
```

View file

@ -0,0 +1,35 @@
## Exercise 2: Importing
#### Goal
Get comfortable with different ways of importing objects from a package.
#### Preparation
0. [if not done already] fork the repository
https://github.com/ASPP/2023-heraklion-ODD
and clone it to the laptop in a new directory
1. You will be editing files within this directory
2. Open a terminal and change to this directory, so that you can run the scripts that you are editing
#### Tasks
1. Work on the file `brewing/example_usage_within_package.py`:
1. import and call the `make_example_potion` function from the module `brew_potions.py` function ➔ open a terminal, change to the `brewing` directory and run the script `example_usage_within_package.py`: what happens?
2. change the import statement so that you can call the `make_example_potion` function like this: `br.make_example_potion` ➔ run the script again: what happens?
2. Work on the file `example_usage_outside_package.py`, which is in the directory where you cloned the repo:
1. import the brewing package inside the `example_usage_outside_package.py` that lives at the top level directory of the repo ➔ in the terminal, change to the top level directory of the repo, add the import statement and run the script `example_usage_outside_package.py`: what happens?
2. import and call only the `make_example_potion` function from the module `brew_potions.py`, which is in the `brewing` directory ➔ run the script again: what happens?
3. does it work? if yes, why? If no, why not?
4. change the import statements so that it works, then check whether `brewing/example_usage_inside_package.py` from 1.2 still works.
3. Work on the file `scripts_and_notebooks/example_usage_different_folder.py`:
1. try to import and call only the `make_example_potion` function from the module `brew_potions.py` ➔ in the terminal, change to the `scripts_and_notebooks` directory and run the script `example_usage_different_folder.py`: what happens?
2. does it work? if yes, why? If no, why not?

View file

@ -0,0 +1,27 @@
## Exercise 3: Editable Installation
#### Goal
See advantages of using brewing package as an editable installation.
#### Tasks
1. Check which packages are installed currently
`> pip freeze`
2. install the brewing package as an editable installation
`> pip install -e <path-to-repository>`
or go into the folder which contains `brewing` and call
`> pip install -e .`
3. check which packages are installed now
`> pip freeze`
What changed?
4. Try running the `example_usage_X.py` files that you created in Exercise 1. Do they run without errors and if not, can you make them all work simultaneously?
1. `example_usage_outside_package.py`
2. `scripts/example_usage_different_folder.py`
3. `brewing/example_usage_within_package.py`

View file

@ -0,0 +1,30 @@
## Exercise 4: Workflow
#### Goal
Mimic the *write feature**test feature* workflow.
#### Tasks
In the `brew_potions.py` file complete the `make_python_expert_potion` function that makes the *Python expert* potion (instructions below).
Get Professor Snape to inspect your potion as shown for the example potion. Calling `inspection_by_snape` should never give you an error, so you will have to read what Snape does and says to find out what went wrong.
This is supposed to be easy and fun, so run the inspection often and make mistakes with the potion.
Use your git skills to commit the changes you made to a new branch, and create a pull request on Github.
##### Brewing instructions
Make a new potion called `python_expert` according to these instructions:
```
1. Set up a pewter cauldron and light a fire underneath it
2. Add fish eyes, unicorn hair and tea leaves
3. Let simmer for 2 hours
4. Have Snape inspect the potion (use target_potion='python_expert').
```
Use the `if __name__ =="__main__"` block in `brew_potions.py` to create the `python_expert` potion and call Snape to inspect the potion by calling `inspection_by_snape` . Make sure you actaully call the function you are editing and change the **target** potion for Snape to `"python_expert"`.
Note that if you copy from the `example_potion()` function, it is missing a crucial step. You can look at the `Potion()` class in `brewing/potion_class.by` for inspiration.

View file

@ -0,0 +1,15 @@
## Exercise 5: Documentation
#### Goal
Practice writing doctrings
#### Tasks
As an exercise, write the docstring for the `make_python_expert` function you just wrote.
For a more detailed description, see: https://numpydoc.readthedocs.io/en/latest/format.html
Commit your documenatation and update your pull request.
If you are done, think about which parts of the brewing package should be documented and in what way.