Skip to content

Commit

Permalink
Update instructions and tests
Browse files Browse the repository at this point in the history
Given that many have Anaconda and Windows,
best to only use allowed when it's easy to install.
  • Loading branch information
mwermelinger committed May 2, 2023
1 parent 24ac36b commit e49edef
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 39 deletions.
41 changes: 19 additions & 22 deletions docs/m269_guide.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,33 @@
## Quick Guide for M269

First, make sure you have Python 3.10 or 3.11.
If you intend to later install further software in order to check the method calls of your code,
you need 3.10 rather than 3.11.
The following explains how to install and use `allowed`, a tool that checks if
your TMA code only uses the Python constructs mentioned in Chapters 10, 20 and 28.
The tool is merely a convenience compared to visually inspecting your code.

1. Open a terminal and type `python3 -V`.
2. If your Python version is 3.9 or lower,
install 3.10 or 3.11 from [https://python.org](https://www.python.org/downloads/).
(You don't need to uninstall your current Python.)
1. Open a terminal. Enter `python -V` to obtain your Python version.

Next, install the `allowed` tool:
If it is 3.9 or lower, then you can't use `allowed`, sorry.
While you can have multiple Python versions on your system,
it's not worth the hassle and potential problems at this point in M269.

3. Click on one of the download buttons above.
4. Go to your downloads folder and extract the files from the downloaded archive.
Next, if you have Python 3.10 or later, install the `allowed` tool:

2. Click the 'Download .zip' button above.
3. Go to your downloads folder and extract the files from the downloaded archive.
(Your web browser may have done it automatically.)
5. Move the files `allowed.py` and `m269.json` from the `allowed-main` folder
4. Move the files `allowed.py` and `m269.json` from the
`dsa-ou-allowed-main-24ac36b` folder (the last 7 characters may vary)
to the folder with your M269 materials.

To use the tool:

6. Open a terminal and go to the folder where you put both files.
To use the tool, open a terminal and go to the folder where you put both files:

- To check the first TMA, type `python allowed.py -u 10 path/to/TMA01.ipynb`,
5. To check the first TMA, type `python allowed.py -u 10 path/to/TMA01.ipynb`,
e.g. `python allowed.py -u 10 TMA01/22J-TMA01-STUDENT.ipynb` or similar.
(On Windows, use backslashes.)
- To check the second TMA, type `python allowed.py -u 20 path/to/TMA02.ipynb`.
- To check the third TMA, type `python allowed.py path/to/TMA03.ipynb`.
6. To check the second TMA, type `python allowed.py -u 20 path/to/TMA02.ipynb`.
7. To check the third TMA, type `python allowed.py path/to/TMA03.ipynb`.

These checks won't detect if you're calling methods that haven't been taught,
like `count()` on lists.
To check methods calls you need Python 3.10 and do the following:

7. If you're on Windows, install [WSL](https://learn.microsoft.com/en-us/windows/wsl).
8. In a terminal, type `pip install pytype` to install the necessary type checker.
9. Add `-m` when checking a TMA, e.g. `python allowed.py -m -u 10 path/to/TMA01.ipynb`.
It's possible for `allowed` to check method calls,
but it would require installing Linux on Windows. Again, not worth the trouble.
18 changes: 9 additions & 9 deletions tests/sample-nb-m.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ sample.ipynb:cell_2:21: else in for-loop
sample.ipynb:cell_2:26: try:
sample.ipynb:cell_2:27: print(n, "prime" if is_prime(n) else "not prime")
sample.ipynb:cell_2:28: except AssertionError:
sample.ipynb:cell_3:7: break
sample.ipynb:cell_3:8: value += 1
sample.ipynb:cell_3:12: continue
sample.ipynb:cell_3:14: else in while-loop
sample.ipynb:cell_4:6: print(f"first {FIRST} odd numbers: {odd}")
sample.ipynb:cell_4:7: method count called on list odd
sample.ipynb:cell_4:11: <<
sample.ipynb:cell_4:12: math.e
sample.ipynb:cell_4:13: built-in function type()
sample.ipynb:cell_5:7: break
sample.ipynb:cell_5:8: value += 1
sample.ipynb:cell_5:12: continue
sample.ipynb:cell_5:14: else in while-loop
sample.ipynb:cell_6:4: print(f"first {FIRST} odd numbers: {odd}")
sample.ipynb:cell_6:5: method count called on list odd
sample.ipynb:cell_6:9: <<
sample.ipynb:cell_6:10: math.e
sample.ipynb:cell_6:11: built-in function type()
16 changes: 8 additions & 8 deletions tests/sample-nb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ sample.ipynb:cell_2:21: else in for-loop
sample.ipynb:cell_2:26: try:
sample.ipynb:cell_2:27: print(n, "prime" if is_prime(n) else "not prime")
sample.ipynb:cell_2:28: except AssertionError:
sample.ipynb:cell_3:7: break
sample.ipynb:cell_3:8: value += 1
sample.ipynb:cell_3:12: continue
sample.ipynb:cell_3:14: else in while-loop
sample.ipynb:cell_4:6: print(f"first {FIRST} odd numbers: {odd}")
sample.ipynb:cell_4:11: <<
sample.ipynb:cell_4:12: math.e
sample.ipynb:cell_4:13: built-in function type()
sample.ipynb:cell_5:7: break
sample.ipynb:cell_5:8: value += 1
sample.ipynb:cell_5:12: continue
sample.ipynb:cell_5:14: else in while-loop
sample.ipynb:cell_6:4: print(f"first {FIRST} odd numbers: {odd}")
sample.ipynb:cell_6:9: <<
sample.ipynb:cell_6:10: math.e
sample.ipynb:cell_6:11: built-in function type()
warning: didn't check method calls (use option -m)

0 comments on commit e49edef

Please sign in to comment.