Skip to content

Commit c1f4efa

Browse files
author
Tania Allard
committed
Complete the run all section
1 parent 48bccba commit c1f4efa

1 file changed

Lines changed: 57 additions & 2 deletions

File tree

03_ProcessData.ipynb

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,69 @@
167167
"source": [
168168
"# Packaging\n",
169169
"\n",
170-
"Since are using a modular approach we need to ensure we can call our functions from a **run all script**.\n",
170+
"We used a modular approach here, so we can use and reuse the functions more efficiently. \n",
171+
"The next step it to make a `runall` script to minimize the user interaction. \n",
172+
"\n",
173+
"First, we need to make sure that Python recognizes our scripts as a package so we can call functions from the multiple modules.\n",
171174
"\n",
172175
"From the shell: \n",
173176
"```\n",
174-
"$ touch src/__init__/py\n",
177+
"$ touch src/data/__init__.py # Create empty file\n",
178+
"$ touch src/visualization/__init__.py # Create empty file\n",
179+
"$ touch src/__init__.py\n",
180+
"```"
181+
]
182+
},
183+
{
184+
"cell_type": "markdown",
185+
"metadata": {
186+
"slideshow": {
187+
"slide_type": "subslide"
188+
}
189+
},
190+
"source": [
191+
"# Creating the `run all` script\n",
192+
"\n",
193+
"<div class='info'> \n",
194+
" We will run everything from the root directory.<br>\n",
195+
" As such all the paths will be relative to the top level of your project\n",
196+
"</div>\n",
197+
"\n",
198+
"Since our modules start with digits (i.e. `01`, `02`) we cannot do the import as we'd normally do\n",
199+
"```python \n",
200+
"from mypackage import myawesomemodule\n",
201+
"```\n",
202+
"Instead we need to do it like so:\n",
203+
"```python\n",
204+
"subset = importlib.import_module('.data.01_subset-data-GBP', 'scripts')\n",
205+
"plotwines = importlib.import_module('.visualization.02_visualize-wines', 'scripts')\n",
206+
"country_sub = importlib.import_module('.data.03_country-subset', 'scripts')\n",
207+
"```\n",
208+
"\n",
209+
"Also we need to make sure the imports are declared in `src/__init__.py`\n",
210+
"```python\n",
211+
"from . import data\n",
212+
"from . import visualization\n",
175213
"```"
176214
]
177215
},
216+
{
217+
"cell_type": "markdown",
218+
"metadata": {},
219+
"source": [
220+
"### TO DO:\n",
221+
"\n",
222+
"How would you do to run the analysis from step 01 (process the data) to 03 subset for a country and plot the results?\n",
223+
"\n",
224+
"\n",
225+
"Once you have done this and make sure you can run it from your shell and commit the changes to git.\n",
226+
"\n",
227+
"Note you might need to run this from the shell like so \n",
228+
"```\n",
229+
"python -m scripts.runall-wine-analysis\n",
230+
"``` \n"
231+
]
232+
},
178233
{
179234
"cell_type": "code",
180235
"execution_count": 1,

0 commit comments

Comments
 (0)