22title : " Development and contribution"
33teaching : 10
44exercises : 20
5- compatibility : ESMValTool v2.5 .0
5+ compatibility : ESMValTool v2.9 .0
66
77questions :
88- " What is a development installation?"
@@ -56,11 +56,12 @@ The ESMValTool source code is available on a public GitHub repository:
5656[ https://github.com/ESMValGroup/ESMValTool ] ( https://github.com/ESMValGroup/ESMValTool ) .
5757To obtain the code, there are two options:
5858
59- 1 . download the code from the repository. A ZIP file called
60- `` ESMValTool-master.zip `` is downloaded. To continue the installation, unzip
61- the file, move to the `` ESMValTool-master `` directory and then follow the
62- sequence of steps starting from ** 2 ESMValTool dependencies** .
63- 2 . clone the repository if you want to contribute to the ESMValTool development:
59+ 1 . Download the code from the repository. A ZIP file called
60+ `` ESMValTool-main.zip `` is downloaded. To continue the installation, unzip
61+ the file, move to the `` ESMValTool-main `` directory and then follow the
62+ sequence of steps starting from the section on
63+ ** ESMValTool dependencies** below.
64+ 2 . Clone the repository if you want to contribute to the ESMValTool development:
6465
6566~~~ bash
6667git clone https://github.com/ESMValGroup/ESMValTool.git
@@ -69,8 +70,10 @@ git clone https://github.com/ESMValGroup/ESMValTool.git
6970This command will ask your GitHub username and a personal ** token** as password.
7071Please follow instructions on
7172[ GitHub token authentication requirements] [ token-authentication-requirements ]
72- to create a personal access token. After the authentication,
73- the output might look like:
73+ to create a personal access token.
74+ Alternatively, you could [ generate a new SSH key] [ generate-ssh-key ] and
75+ [ add it to your GitHub account] [ add-ssh-key ] .
76+ After the authentication, the output might look like:
7477
7578~~~
7679Cloning into 'ESMValTool'...
@@ -91,31 +94,39 @@ To continue the installation, we move into the ``ESMValTool`` directory:
9194cd ESMValTool
9295~~~
9396
94- Note that the `` master `` branch is checked out by default.
97+ Note that the `` main `` branch is checked out by default.
9598We can see this if we run:
9699
97100~~~ bash
98101git status
99102~~~
100103
101104~~~
102- On branch master
103- Your branch is up to date with 'origin/master '.
105+ On branch main
106+ Your branch is up to date with 'origin/main '.
104107
105108nothing to commit, working tree clean
106109~~~
107110{: .output}
108111
109112### 2 ESMValTool dependencies
110113
111- It is recommended to use conda to manage ESMValTool dependencies. For a minimal
112- conda installation, see section ** Install Conda ** in lesson
114+ ESMValTool now uses ` mamba ` instead of ` conda ` for the recommended installation.
115+ For a minimal mamba installation, see section ** Install Mamba ** in lesson
113116[ Installation] ({{ page.root }}{% link _ episodes/02-installation.md %}).
117+
118+ It is good practice to update the version of mamba and conda on your machine before
119+ setting up ESMValTool. This can be done as follows:
120+
121+ ~~~ bash
122+ mamba update --name base mamba conda
123+ ~~~
124+
114125To simplify the installation process, an environment file `` environment.yml `` is
115126provided in the ESMValTool directory. We create an environment by running:
116127
117128~~~ bash
118- conda env create --file environment.yml
129+ mamba env create --name esmvaltool --file environment.yml
119130~~~
120131
121132The environment is called `` esmvaltool `` by default.
@@ -124,15 +135,20 @@ If an ``esmvaltool`` environment is already created following the lesson
124135we should choose another name for the new environment in this lesson by:
125136
126137~~~ bash
127- conda env create -n a_new_name --file environment.yml
138+ mamba env create --name a_new_name --file environment.yml
128139~~~
140+ This will create a new conda environment and install ESMValTool (with all
141+ dependencies that are needed for development purposes) into it with a single command.
129142
130143For more information see [ conda managing environments] [ manage-environments ] .
144+
131145Now, we should activate the environment:
132146
133147~~~ bash
134148conda activate esmvaltool
135149~~~
150+ where `` esmvaltool `` is the name of the environment (replace by `` a_new_name ``
151+ in case another environment name was used).
136152
137153### 3 ESMValTool installation
138154
@@ -154,7 +170,7 @@ If the installation is successful, ESMValTool prints a help message to the conso
154170
155171> ## Checking the development installation
156172>
157- > We can use the command `` conda list`` to list installed packages in
173+ > We can use the command `` mamba list`` to list installed packages in
158174> the `` esmvaltool `` environment.
159175> Use this command to check that ESMValTool is installed in a `` develop `` mode.
160176>
@@ -166,33 +182,29 @@ If the installation is successful, ESMValTool prints a help message to the conso
166182>> Run:
167183>>
168184>> ~~~ bash
169- >> conda list esmvaltool
185+ >> mamba list esmvaltool
170186>> ~~~
171187>>
172188>> ~ ~~bash
173189>> # Name Version Build Channel
174- >> esmvaltool 2.1.1 dev_0 < develop >
190+ >> esmvaltool 2.10.0.dev3+g2dbc2cfcc pypi_0 pypi
175191>> ~~~
176192>>
177- >> As can be seen, it is mentioned ` ` < develop> ` ` under the ` ` Channel` ` .
178193> {: .solution}
179194{: .challenge}
180195
181196# ## 4 Updating ESMValTool
182197
183- The ` ` master ` ` branch has the latest features of ESMValTool. Please make sure
198+ The ` ` main ` ` branch has the latest features of ESMValTool. Please make sure
184199that the source code on your machine is up-to-date. If you obtain the source
185200code using git clone as explained in step ** 1 Source code** , you can run ` ` git pull` `
186201to update the source code. Then ESMValTool installation will be updated
187- with changes from the ` ` master ` ` branch.
202+ with changes from the ` ` main ` ` branch.
188203
189204# # Contribution
190205
191206We have seen how to install ESMValTool in a ` ` develop` ` mode.
192- Now, we try to contribute to its development. Let' s see how we can achieve this.
193-
194- ### Review process
195-
207+ Now, we try to contribute to its development. Let' s see how we this can be achieved.
196208We first discuss our ideas in an
197209**[issue](https://github.com/ESMValGroup/ESMValTool/issues)** in ESMValTool repository.
198210This can avoid disappointment at a later stage, for example,
@@ -201,31 +213,46 @@ It also gives other people an early opportunity to provide input and suggestions
201213which results in more valuable contributions.
202214
203215Then, we create a new ``branch`` locally and start developing new codes.
216+ To create a new branch:
217+ ~~~bash
218+ git checkout -b your_branch_name
219+ ~~~
220+ If needed, a link to a git tutorial can be found in [Setup]({{ page.root }}{% link setup.md %}).
221+
204222Once our development is finished, we can initiate a ``pull request``.
205- For a full description of the GitHub workflow, please see ESMValTool documentation on
206- [GitHub Workflow](https://docs.esmvaltool.org/en/latest/community/repository.html#github-workflow).
223+ To this end, we encourage you to join the ESMValTool development team.
207224
208- The pull request will be tested, discussed and merged. This is called "**review process**".
225+ For more extensive documentation on contributing code, including a section on the
226+ [GitHubWorkflow](https://docs.esmvaltool.org/en/latest/community/repository.html#github-workflow),
227+ please see the
228+ [Contributing code and documentation][code-documentation]
229+ section in the ESMValtool documentation.
230+
231+ ### Review process
232+
233+ The pull request will be tested, discussed and merged as part of the "**review process**".
209234The process will take some effort and time to learn.
210235However, a few (command line) tools can get you a long way,
211236and we’ll cover those essentials in the next sections.
212237
213238**Tip**: we encourage you to keep the pull requests small.
214239Reviewing small incremental changes are more efficient.
215240
216- ### Background
241+ ### Working example
217242
218- We saw ' warming stripes' in lesson
243+ We saw the ' warming stripes' diagnostic in lesson
219244[Writing your own recipe]({{ page.root }}{% link _episodes/06-preprocessor.md %}).
220245Imagine the following task: you want to contribute warming stripes recipe and diagnostics
221246to ESMValTool. You have to add the diagnostics
222247[warming_stripes.py](../files/warming_stripes.py) and the recipe
223248[recipe_warming_stripes.yml](../files/recipe_warming_stripes.yml)
224249to their locations in ESMValTool directory.
225- After these changes, you should also check if everthing works fine.
250+ After these changes, you should also check if everything works fine.
226251This is where we take advantage of the tools that are introduced later.
227252
228- Let’s get started.
253+ Let’s get started. Note that since this is an exercise to get familiar with the
254+ development and contribution process, we will not create a GitHub issue at this time
255+ but proceed as though it has been done.
229256
230257### Check code quality
231258
@@ -270,7 +297,7 @@ To explore other tools, have a look at ESMValTool documentation on
270297>
271298>> # # Solution
272299>>
273- >> The output of ` ` pre-commit` ` :
300+ >> The tail of the output of ` ` pre-commit` ` :
274301>>
275302>> ~ ~~ bash
276303>> Check for added large files..............................................Passed
@@ -302,17 +329,25 @@ To explore other tools, have a look at ESMValTool documentation on
302329>>
303330>> 1. ` ` docformatter` ` : it is mentioned that " files were modified by this hook" .
304331>> We run ` ` git diff` ` to see the modifications.
305- >> The syntax ` ` " " " ` ` at the end of docstring is moved by one line.
332+ >> The output includes the following:
333+ >> ~ ~~bash
334+ >> +in the form of the popular warming stripes figure by Ed Hawkins." " "
335+ >> ~~~
336+ >> The syntax ` ` " " " ` ` at the end of docstring is moved by one line.
337+ >> Shifting it to the next line should fix this error.
338+ >>
306339>> 2. ` ` flake8` ` : the error message is about an unused local variable ` ` nx` ` .
307340>> We should check our codes regarding the usage of ` ` nx` ` .
308341>> For now, let' s assume that it is added by mistake and remove it.
342+ >> Note that you have to run `git add` again to re-stage the file.
343+ >> Then rerun pre-commit and check that it passes.
309344> {: .solution}
310345{: .challenge}
311346
312347### Run unit tests
313348
314349Previous section introduced some tools to check code style and quality.
315- What it hasn’t done is show us how to tell whether our code is getting the right answer.
350+ What it has not done is show us how to tell whether our code is getting the right answer.
316351To achieve that, we need to write and run tests for widely-used functions.
317352ESMValTool comes with a lot of tests that are in the folder ``tests``.
318353
@@ -328,15 +363,16 @@ when you submit a pull request.
328363
329364> ## Running tests
330365>
331- > Let's checkout our local branch and add the recipe
366+ > Make sure our local branch is checked out and add the recipe
332367> [recipe_warming_stripes.yml](../files/recipe_warming_stripes.yml)
333- > to the the ` ` esmvaltool/recipes` ` directory:
368+ > to the ``esmvaltool/recipes`` directory:
334369>
335370> ~~~bash
336371> cp path_of_recipe_warming_stripes.yml esmvaltool/recipes/
337372> ~~~
338373>
339- > Run ` ` pytest` ` and inspect the results. If a test is failed, try to fix it.
374+ > Run ``pytest`` and inspect the results, this might take a few minutes.
375+ > If a test is failed, try to fix it.
340376>
341377>> ## Solution
342378>>
@@ -391,7 +427,7 @@ To build documentation locally, first we make sure that the working directory is
391427and our local branch is checked out. Then, we run:
392428
393429~~~bash
394- python setup.py build_sphinx -Ea
430+ sphinx-build -Ea doc/sphinx/source/ doc/sphinx/build/
395431~~~
396432
397433Similar to code, documentation should be well written and adhere to standards.
@@ -400,19 +436,19 @@ If the documentation is built properly, the previous command prints a message to
400436~~~
401437build succeeded.
402438
403- The HTML pages are in doc/sphinx/build/html .
439+ The HTML pages are in doc/sphinx/build.
404440~~~
405441{: .output}
406442
407443The main page of the documentation has been built into ``index.html``
408- in ` ` doc/sphinx/build/html ` ` directory.
444+ in ``doc/sphinx/build/`` directory.
409445To preview this page locally, we open the file in a web browser:
410446
411447~~~bash
412- xdg-open doc/sphinx/build/html/ index.html
448+ xdg-open doc/sphinx/build/index.html
413449~~~
414450
415- > ## Creating a documenation
451+ > ## Creating a documentation
416452>
417453> In previous exercises, we added the recipe
418454> [recipe_warming_stripes.yml](../files/recipe_warming_stripes.yml) to ESMValTool.
@@ -435,6 +471,8 @@ xdg-open doc/sphinx/build/html/index.html
435471> ` ` `
436472>
437473> Save and close the file. We can think of this file as one page of a book.
474+ > Examples of documentation pages can be found in the folder
475+ > ` ` ESMValTool/doc/sphinx/source/recipes` ` .
438476> Then, we need to decide where this page should be located inside the book.
439477> The table of content is defined by ` ` index.rst` ` . Let' s have a look at the content:
440478>
@@ -462,8 +500,8 @@ xdg-open doc/sphinx/build/html/index.html
462500>> Then, we build and preview the documentation page:
463501>>
464502>> ~~~bash
465- >> python setup.py build_sphinx -Ea
466- >> xdg-open doc/sphinx/build/html/ recipes/recipe_warming_stripes.html
503+ >> sphinx-build -Ea doc/sphinx/source/ doc/sphinx/build/
504+ >> xdg-open doc/sphinx/build/recipes/recipe_warming_stripes.html
467505>> ~~~
468506>>
469507> {: .solution}
0 commit comments