Skip to content

Commit 954b387

Browse files
committed
Rename notebook.py to notebook_utils.py to avoid Jupyter package collision (#1294)
The repo shipped notebook.py at its root, which shadowed the Jupyter 'notebook' PyPI package (sys.path[0] is the cwd). Launching Jupyter from the repo root, or PyCharm's 'from notebook.app import main' launcher, then failed with ModuleNotFoundError: 'notebook' is not a package. Rename the module to notebook_utils.py (a visualization/helper module, not edition-specific, so it keeps the unsuffixed-3e convention intact for the algorithm modules) and update the 'from notebook import ...' line in the 25 notebooks that use it, plus the CONTRIBUTING.md references. No .py module or test imports it, so the test suite is unaffected. notebook4e.py is left as-is (its name does not collide).
1 parent 0f5569a commit 954b387

27 files changed

Lines changed: 35 additions & 35 deletions

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ We hope to have an `algorithm-name.md` file for each algorithm, eventually; it w
3737
In this project we use Jupyter/IPython Notebooks to showcase the algorithms in the book. They serve as short tutorials on what the algorithms do, how they are implemented and how one can use them. To install Jupyter, you can follow the instructions [here](https://jupyter.org/install.html). These are some ways you can contribute to the notebooks:
3838

3939
- Proofread the notebooks for grammar mistakes, typos, or general errors.
40-
- Move visualization and unrelated to the algorithm code from notebooks to `notebook.py` (a file used to store code for the notebooks, like visualization and other miscellaneous stuff). Make sure the notebooks still work and have their outputs showing!
41-
- Replace the `%psource` magic notebook command with the function `psource` from `notebook.py` where needed. Examples where this is useful are a) when we want to show code for algorithm implementation and b) when we have consecutive cells with the magic keyword (in this case, if the code is large, it's best to leave the output hidden).
40+
- Move visualization and unrelated to the algorithm code from notebooks to `notebook_utils.py` (a file used to store code for the notebooks, like visualization and other miscellaneous stuff). Make sure the notebooks still work and have their outputs showing!
41+
- Replace the `%psource` magic notebook command with the function `psource` from `notebook_utils.py` where needed. Examples where this is useful are a) when we want to show code for algorithm implementation and b) when we have consecutive cells with the magic keyword (in this case, if the code is large, it's best to leave the output hidden).
4242
- Add the function `pseudocode(algorithm_name)` in algorithm sections. The function prints the pseudocode of the algorithm. You can see some example usage in [`knowledge.ipynb`](https://github.com/aimacode/aima-python/blob/master/knowledge.ipynb).
4343
- Edit existing sections for algorithms to add more information and/or examples.
44-
- Add visualizations for algorithms. The visualization code should go in `notebook.py` to keep things clean.
44+
- Add visualizations for algorithms. The visualization code should go in `notebook_utils.py` to keep things clean.
4545
- Add new sections for algorithms not yet covered. The general format we use in the notebooks is the following: First start with an overview of the algorithm, printing the pseudocode and explaining how it works. Then, add some implementation details, including showing the code (using `psource`). Finally, add examples for the implementations, showing how the algorithms work. Don't fret with adding complex, real-world examples; the project is meant for educational purposes. You can of course choose another format if something better suits an algorithm.
4646

4747
Apart from the notebooks explaining how the algorithms work, we also have notebooks showcasing some indicative applications of the algorithms. These notebooks are in the `*_apps.ipynb` format. We aim to have an `apps` notebook for each module, so if you don't see one for the module you would like to contribute to, feel free to create it from scratch! In these notebooks we are looking for applications showing what the algorithms can do. The general format of these sections is this: Add a description of the problem you are trying to solve, then explain how you are going to solve it and finally provide your solution with examples. Note that any code you write should not require any external libraries apart from the ones already provided (like `matplotlib`).

agents.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"outputs": [],
1717
"source": [
1818
"from agents import *\n",
19-
"from notebook import psource"
19+
"from notebook_utils import psource"
2020
]
2121
},
2222
{

csp.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"outputs": [],
1717
"source": [
1818
"from csp import *\n",
19-
"from notebook import psource, plot_NQueens\n",
19+
"from notebook_utils import psource, plot_NQueens\n",
2020
"%matplotlib inline\n",
2121
"\n",
2222
"# Hide warnings in the matplotlib sections\n",

games.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"outputs": [],
3535
"source": [
3636
"from games import *\n",
37-
"from notebook import psource, pseudocode"
37+
"from notebook_utils import psource, pseudocode"
3838
]
3939
},
4040
{
@@ -631,7 +631,7 @@
631631
},
632632
"outputs": [],
633633
"source": [
634-
"from notebook import Canvas_minimax\n",
634+
"from notebook_utils import Canvas_minimax\n",
635635
"from random import randint"
636636
]
637637
},
@@ -826,7 +826,7 @@
826826
},
827827
"outputs": [],
828828
"source": [
829-
"from notebook import Canvas_alphabeta\n",
829+
"from notebook_utils import Canvas_alphabeta\n",
830830
"from random import randint"
831831
]
832832
},
@@ -1477,7 +1477,7 @@
14771477
},
14781478
"outputs": [],
14791479
"source": [
1480-
"from notebook import Canvas_TicTacToe"
1480+
"from notebook_utils import Canvas_TicTacToe"
14811481
]
14821482
},
14831483
{

intro.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"metadata": {},
8383
"outputs": [],
8484
"source": [
85-
"from notebook import psource, pseudocode\n",
85+
"from notebook_utils import psource, pseudocode\n",
8686
"\n",
8787
"psource(WalkSAT)\n",
8888
"pseudocode(\"WalkSAT\")"

knowledge_current_best.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"source": [
2020
"from knowledge import *\n",
2121
"\n",
22-
"from notebook import pseudocode, psource"
22+
"from notebook_utils import pseudocode, psource"
2323
]
2424
},
2525
{

knowledge_foil.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"outputs": [],
1919
"source": [
2020
"from knowledge import *\n",
21-
"from notebook import psource"
21+
"from notebook_utils import psource"
2222
]
2323
},
2424
{

knowledge_version_space.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"source": [
2020
"from knowledge import *\n",
2121
"\n",
22-
"from notebook import pseudocode, psource"
22+
"from notebook_utils import pseudocode, psource"
2323
]
2424
},
2525
{

learning.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"source": [
1818
"from learning import *\n",
1919
"from probabilistic_learning import *\n",
20-
"from notebook import *"
20+
"from notebook_utils import *"
2121
]
2222
},
2323
{

learning_apps.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"source": [
1818
"from learning import *\n",
1919
"from probabilistic_learning import *\n",
20-
"from notebook import *"
20+
"from notebook_utils import *"
2121
]
2222
},
2323
{

0 commit comments

Comments
 (0)