Skip to content

Commit 1c6f119

Browse files
author
Tania Allard
committed
Finish main content
1 parent f8171ee commit 1c6f119

11 files changed

+387
-1
lines changed

.travis.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: python
2+
3+
python:
4+
- 3.6
5+
6+
before_install:
7+
# Here we download miniconda and create our conda environment
8+
- export MINICONDA=$HOME/miniconda
9+
- export PATH="$MINICONDA/bin:$PATH"
10+
- hash -r
11+
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
12+
- bash miniconda.sh -b -f -p $MINICONDA
13+
- conda config --set always_yes yes
14+
- conda update conda
15+
- conda info -a
16+
- conda env create -f testenv.yml -v
17+
- source activate testenv
18+
19+
script:
20+
- pytest
21+
- pytest --nbval notebooks/00_explore-data.ipynb

04_Testing.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
}
157157
},
158158
"source": [
159-
"Your test script should look like this:\n",
159+
"Modifying <code>test_03_country_subset.py</code>\n",
160160
"``` python\n",
161161
"import importlib\n",
162162
"\n",

05_SharingAnalysis.ipynb

+354
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,354 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Sharing your code with the world\n",
8+
"\n",
9+
"We now have a fully automated and tested workflow!!! 🤩🎉😎\n",
10+
"\n",
11+
"And we are ready to share our awesomeness with the world. \n",
12+
"\n",
13+
"Head to [https://github.com/](https://github.com/) and login to your account\n"
14+
]
15+
},
16+
{
17+
"cell_type": "markdown",
18+
"metadata": {},
19+
"source": [
20+
"In your repository section click on the green **new repository** button\n",
21+
"![gh1](assets/github1.PNG)"
22+
]
23+
},
24+
{
25+
"cell_type": "markdown",
26+
"metadata": {},
27+
"source": [
28+
"We need to link your local project to your GitHub repository\n",
29+
"![link](assets/github2.PNG)\n",
30+
"\n",
31+
"type those command on your shell (or copy and paste). **Use your own details**\n",
32+
"\n",
33+
"Refresh your web browser and... ta dah! Your project is online"
34+
]
35+
},
36+
{
37+
"cell_type": "markdown",
38+
"metadata": {},
39+
"source": [
40+
"# Continuous integration \n",
41+
"\n",
42+
"Now, instead of running our tests manually every time we want for this to be tested every time we push something from our local computer to our GitHub account. \n",
43+
"\n",
44+
"Some of the advantages of doing this are:\n",
45+
"- check every version of your code\n",
46+
"- check for errors continuosly\n",
47+
"- report the results of the tests\n",
48+
"- identify when things stop working\n"
49+
]
50+
},
51+
{
52+
"cell_type": "markdown",
53+
"metadata": {},
54+
"source": [
55+
"### Activate Travis CI\n",
56+
"\n",
57+
"Travis CI is a continuous integration server hosting platform. All you need is an account. Now let's go to [https://travis-ci.org/](https://travis-ci.org/) and activate CI for your project\n",
58+
"\n",
59+
"![travis](assets/travisact.PNG)"
60+
]
61+
},
62+
{
63+
"cell_type": "markdown",
64+
"metadata": {},
65+
"source": [
66+
"## .travis.yml\n",
67+
"A **.travis.yml** script tells Travis CI what steps are needed to test your project\n",
68+
"\n",
69+
"```yaml\n",
70+
"language: python\n",
71+
"\n",
72+
"python:\n",
73+
" - 3.6\n",
74+
" \n",
75+
"before_install:\n",
76+
" # Here we download miniconda and create our conda environment\n",
77+
" - export MINICONDA=$HOME/miniconda\n",
78+
" - export PATH=\"$MINICONDA/bin:$PATH\"\n",
79+
" - hash -r\n",
80+
" - wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh\n",
81+
" - bash miniconda.sh -b -f -p $MINICONDA\n",
82+
" - conda config --set always_yes yes\n",
83+
" - conda update conda\n",
84+
" - conda info -a\n",
85+
" # Create the environment from a yml file\n",
86+
" # Is this familiar?\n",
87+
" - conda env create -f testenv.yml -v\n",
88+
" - source activate testenv\n",
89+
" \n",
90+
"script:\n",
91+
" - pytest\n",
92+
" - pytest --nbval notebooks/00_explore-data.ipynb\n",
93+
"```"
94+
]
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"metadata": {},
99+
"source": [
100+
"### Does Your Software Work on Your Colleague’s Computer?\n",
101+
"\n",
102+
"Complex analysis depend on a number of packages and libraries native to your OS, packages the user installes, environmental variables and so on. Manually maintaining these dependencies is a rather tedious task. \n",
103+
"\n",
104+
"That is why we use package managers, such as Conda. \n",
105+
"Do you remember we started this workshop by installing all the packages we needed and one of the steps was to use an **environment.yml** file? This ensures we all have the same packages. \n",
106+
"\n",
107+
"Then at the beginnign of the course we activated our **reproPython** environment and have been using the packages installed in this environment. \n",
108+
"\n",
109+
"<div class='warn'> conda is only one package manager, there are many more alternatives for you </div>"
110+
]
111+
},
112+
{
113+
"cell_type": "markdown",
114+
"metadata": {},
115+
"source": [
116+
"Let's create our **testenv.yml**\n",
117+
"\n",
118+
"```yaml\n",
119+
"name: testenv\n",
120+
"channels:\n",
121+
" - conda-forge\n",
122+
" - defaults\n",
123+
"dependencies:\n",
124+
" - python>3.6\n",
125+
" - pytest\n",
126+
" - pandas\n",
127+
" - matplotlib\n",
128+
" - pip:\n",
129+
" - nbval\n",
130+
"```\n",
131+
"\n",
132+
"<div class='info'> Note we are not specifying versions of the packages so by default conda will install the latest versions available </div>"
133+
]
134+
},
135+
{
136+
"cell_type": "markdown",
137+
"metadata": {},
138+
"source": [
139+
"Commit your changes and push this to github\n",
140+
"```\n",
141+
"$ git add .\n",
142+
"$ git commit -m \"Add files for CI\"\n",
143+
"$ git push\n",
144+
"```\n",
145+
"\n",
146+
"This will start an automated testing of your project"
147+
]
148+
},
149+
{
150+
"cell_type": "markdown",
151+
"metadata": {},
152+
"source": [
153+
"# Making your software citable \n",
154+
"\n",
155+
"Head to [https://zenodo.org/](https://zenodo.org/) and login using your GitHub account\n",
156+
"\n",
157+
"![zenodo](assets/zenodo-login.png)"
158+
]
159+
},
160+
{
161+
"cell_type": "markdown",
162+
"metadata": {},
163+
"source": [
164+
"Find your repository and toggle on Zenodo\n",
165+
"![toggle](assets/zenodo-toggle-on.png)\n",
166+
"\n",
167+
"We will be redirected to GitHub to create a release of the repository."
168+
]
169+
},
170+
{
171+
"cell_type": "markdown",
172+
"metadata": {},
173+
"source": [
174+
"After creating the release, go back to Zenodo and refresh the page. You should now see the newly created DOI 🤩\n",
175+
"\n",
176+
"Click on the DOI and copy the markdown text, add this to your README.md and push to GitHub!\n",
177+
"\n",
178+
"![doi](assets/DOI.PNG)"
179+
]
180+
},
181+
{
182+
"cell_type": "markdown",
183+
"metadata": {},
184+
"source": [
185+
"# Creating a citation file\n",
186+
"\n",
187+
"```\n",
188+
"cff-version: 1.0.3\n",
189+
"message: If you use this software, please cite it as below.\n",
190+
"authors:\n",
191+
" - family-names: Allard\n",
192+
" given-names: Tania\n",
193+
" orcid: https://orcid.org/0000-0003-4925-7248\n",
194+
"title: My reproducibel python workflow\n",
195+
"version: 0.1\n",
196+
"doi: 10.5281/zenodo.1241049\n",
197+
"date-released: 2018-05-09\n",
198+
"```\n",
199+
"\n",
200+
"Save as CITATION.cff and commit and push to GitHub\n"
201+
]
202+
},
203+
{
204+
"cell_type": "code",
205+
"execution_count": 1,
206+
"metadata": {},
207+
"outputs": [
208+
{
209+
"data": {
210+
"text/html": [
211+
"<link href=\"https://fonts.googleapis.com/css?family=Didact+Gothic|Dosis:400,500,700\" rel=\"stylesheet\"><style>\n",
212+
"@font-face {\n",
213+
" font-family: \"Computer Modern\";\n",
214+
" src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');\n",
215+
"}\n",
216+
"/* div.cell{\n",
217+
"width:800px;\n",
218+
"margin-left:16% !important;\n",
219+
"margin-right:auto;\n",
220+
"} */\n",
221+
"h1 {\n",
222+
" font-family: 'Dosis', \"Helvetica Neue\", Arial, sans-serif;\n",
223+
" color: #0B132B;\n",
224+
"}\n",
225+
"h2 {\n",
226+
" font-family: 'Dosis', sans-serif;\n",
227+
" color: #1C2541;\n",
228+
"}\n",
229+
"h3{\n",
230+
" font-family: 'Dosis', sans-serif;\n",
231+
" margin-top:12px;\n",
232+
" margin-bottom: 3px;\n",
233+
" color: #40a8a6;\n",
234+
"}\n",
235+
"h4{\n",
236+
" font-family: 'Dosis', sans-serif;\n",
237+
" color: #40a8a6;\n",
238+
"}\n",
239+
"h5 {\n",
240+
" font-family: 'Dosis', sans-serif;\n",
241+
" color: #40a8a6;\n",
242+
"}\n",
243+
"div.text_cell_render{\n",
244+
" font-family: 'Didact Gothic',Computer Modern, \"Helvetica Neue\", Arial, Helvetica,\n",
245+
" Geneva, sans-serif;\n",
246+
" line-height: 130%;\n",
247+
" font-size: 110%;\n",
248+
" /* width:600px; */\n",
249+
" /* margin-left:auto;\n",
250+
" margin-right:auto; */\n",
251+
"}\n",
252+
"\n",
253+
".text_cell_render h1 {\n",
254+
" font-weight: 200;\n",
255+
" font-size: 30pt;\n",
256+
" /* font-size: 50pt */\n",
257+
" line-height: 100%;\n",
258+
" color:#0B132B;\n",
259+
" margin-bottom: 0.5em;\n",
260+
" margin-top: 0.5em;\n",
261+
" display: block;\n",
262+
"}\n",
263+
"\n",
264+
".text_cell_render h2{\n",
265+
" font-weight: 500;\n",
266+
"}\n",
267+
"\n",
268+
".text_cell_render h3{\n",
269+
" font-weight: 500;\n",
270+
"}\n",
271+
"\n",
272+
"\n",
273+
".warning{\n",
274+
" color: rgb( 240, 20, 20 )\n",
275+
"}\n",
276+
"\n",
277+
"div.warn {\n",
278+
" background-color: #FF5A5F;\n",
279+
" border-color: #FF5A5F;\n",
280+
" border-left: 5px solid #C81D25;\n",
281+
" padding: 0.5em;\n",
282+
"\n",
283+
" color: #fff;\n",
284+
" opacity: 0.8;\n",
285+
"}\n",
286+
"\n",
287+
"div.info {\n",
288+
" background-color: #087E8B;\n",
289+
" border-color: #087E8B;\n",
290+
" border-left: 5px solid #0B3954;\n",
291+
" padding: 0.5em;\n",
292+
" color: #fff;\n",
293+
" opacity: 0.8;\n",
294+
"}\n",
295+
"\n",
296+
"</style>\n",
297+
"<script>\n",
298+
"MathJax.Hub.Config({\n",
299+
" TeX: {\n",
300+
" extensions: [\"AMSmath.js\"]\n",
301+
" },\n",
302+
" tex2jax: {\n",
303+
" inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
304+
" displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
305+
" },\n",
306+
" displayAlign: 'center', // Change this to 'center' to center equations.\n",
307+
" \"HTML-CSS\": {\n",
308+
" styles: {'.MathJax_Display': {\"margin\": 4}}\n",
309+
" }\n",
310+
" });\n",
311+
" </script>\n"
312+
],
313+
"text/plain": [
314+
"<IPython.core.display.HTML object>"
315+
]
316+
},
317+
"execution_count": 1,
318+
"metadata": {},
319+
"output_type": "execute_result"
320+
}
321+
],
322+
"source": [
323+
"from IPython.core.display import HTML\n",
324+
"\n",
325+
"\n",
326+
"def css_styling():\n",
327+
" styles = open(\"styles/custom.css\", \"r\").read()\n",
328+
" return HTML(styles)\n",
329+
"css_styling()"
330+
]
331+
}
332+
],
333+
"metadata": {
334+
"kernelspec": {
335+
"display_name": "Python 3",
336+
"language": "python",
337+
"name": "python3"
338+
},
339+
"language_info": {
340+
"codemirror_mode": {
341+
"name": "ipython",
342+
"version": 3
343+
},
344+
"file_extension": ".py",
345+
"mimetype": "text/x-python",
346+
"name": "python",
347+
"nbconvert_exporter": "python",
348+
"pygments_lexer": "ipython3",
349+
"version": "3.6.5"
350+
}
351+
},
352+
"nbformat": 4,
353+
"nbformat_minor": 2
354+
}

assets/DOI.PNG

9.18 KB
Loading

assets/github1.PNG

40.7 KB
Loading

assets/github2.PNG

8.54 KB
Loading

assets/tag.PNG

19.3 KB
Loading

assets/travisact.PNG

31.2 KB
Loading

assets/zenodo-login.png

105 KB
Loading

assets/zenodo-toggle-on.png

195 KB
Loading

testenv.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: testenv
2+
channels:
3+
- conda-forge
4+
- defaults
5+
dependencies:
6+
- python>3.6
7+
- pytest
8+
- pandas
9+
- matplotlib
10+
- pip:
11+
- nbval

0 commit comments

Comments
 (0)