Skip to content

Commit 4578c84

Browse files
Improve dev documentation (#835)
1 parent 5a32ed5 commit 4578c84

File tree

8 files changed

+209
-72
lines changed

8 files changed

+209
-72
lines changed

docs/development.rst

Lines changed: 0 additions & 69 deletions
This file was deleted.

docs/development/conda.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.. _conda_setup:
2+
3+
Development setup with Conda
4+
------------------------------
5+
6+
You can set up a development environment using Conda. Below are the instructions to do so.
7+
8+
First, clone the repository locally. You can use the following command:
9+
10+
.. code-block:: shell
11+
12+
git clone --branch develop git@github.com:ecmwf/earthkit-data.git
13+
14+
15+
Next, enter your git repository and run the following commands:
16+
17+
.. code-block:: shell
18+
19+
make conda-env-update
20+
conda activate earthkit-data
21+
make setup
22+
pip install -e .
23+
24+
This will create a new conda environment called "earthkit-data" with all the dependencies installed into it. This setup enables the `pre-commit`_ hooks, performing a series of quality control checks on every commit. If any of these checks fails the commit will be rejected.

docs/development/docs.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
.. _dev_docs:
2+
3+
4+
Documentation
5+
-------------------
6+
7+
Building the documentation locally
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
10+
To build the documentation locally, please install the Python dependencies first:
11+
12+
.. code-block:: shell
13+
14+
cd docs
15+
pip install -r requirements.txt
16+
17+
Then the documentation can be built by running the following command from the ``docs`` folder:
18+
19+
.. code-block:: shell
20+
21+
make html
22+
23+
To see the generated HTML documentation open the ``docs/_build/html/index.html`` file in your browser.
24+
25+
Notebook examples
26+
~~~~~~~~~~~~~~~~~~~~~~
27+
28+
The notebook examples are located in the ``docs/examples`` folder and are listed in ``docs/examples/index.rst``.
29+
30+
31+
If you add a new notebook example please:
32+
33+
- also add it to ``docs/examples/index.rst`` so that it appears in the documentation.
34+
- ensure the title and the subchapter headings have the same size as in the other notebook. Title with ``##``, subchapter with ``###``.

docs/development/index.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Development
2+
===========
3+
4+
5+
The code repository is hosted on `Github`_, testing, bug reports and contributions are highly welcomed and appreciated. Feel free to fork it and submit your PRs against the **develop** branch.
6+
7+
8+
Development guide
9+
~~~~~~~~~~~~~~~~~
10+
11+
.. toctree::
12+
:maxdepth: 1
13+
14+
setup
15+
conda
16+
tests
17+
docs
18+
19+
20+
21+
.. _`Github`: https://github.com/ecmwf/earthkit-data

docs/development/setup.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.. _dev_setup:
2+
3+
Development setup with virtualenv
4+
-----------------------------------
5+
6+
The recommended development environment is a **Python virtual environment**.
7+
8+
First, clone the repository locally. You can use the following command:
9+
10+
.. code-block:: shell
11+
12+
git clone --branch develop git@github.com:ecmwf/earthkit-data.git
13+
14+
15+
Next, create your Python virtual environment and activate it. E.g. assuming your virtual environment is called `earthkit-dev` you can do:
16+
17+
.. code-block:: shell
18+
19+
cd YOUR_VENVS_DIR
20+
python -m venv earthkit-dev
21+
source earthkit-dev/bin/activate
22+
23+
24+
Next, install your repo with the development dependencies in editable mode by running the following commands from the root of the repository:
25+
26+
.. code-block:: shell
27+
28+
pip install -e .[dev]
29+
30+
31+
When using zsh you might need to quote the square brackets like this:
32+
33+
.. code-block:: shell
34+
35+
pip install -e ."[dev]"
36+
37+
We strongly recommend using the `pre-commit`_ hooks for the developments. These hooks perform a series of quality control checks on every commit. If any of these checks fails the commit will be rejected. To install the hooks run the following commands in the root of the repository:
38+
39+
.. code-block:: shell
40+
41+
pip install pre-commit
42+
pre-commit install
43+
44+
.. _`pre-commit`: https://pre-commit.com/

docs/development/tests.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
.. _testing:
2+
3+
Testing
4+
-----------------------
5+
6+
To run the test suite, you can use the following command:
7+
8+
.. code-block:: shell
9+
10+
pytest
11+
12+
13+
Long tests
14+
~~~~~~~~~~~~~
15+
16+
Please note that by default all the tests based on remote services e.g. :ref:`data-sources-mars` are skipped. This is done because they can take a very long time to complete or just hang. To enable all these tests you need to run:
17+
18+
.. code-block:: shell
19+
20+
pytest -E long -v
21+
22+
If just want to run e.g. the :ref:`data-sources-mars` tests you can use:
23+
24+
.. code-block:: shell
25+
26+
pytest -E long -v -k mars
27+
28+
29+
Timeout for CDS tests
30+
~~~~~~~~~~~~~~~~~~~~~~
31+
32+
Some :ref:`data-sources-cds` retrieval tests used to hang so an execution timeout was added to all the tests in ``tests/sources/test_cds.py``. The default value is 30 seconds and it can be controlled via the ``--cds-timeout`` custom option to ``pytest``. Please note that some tests have a custom hardcoded timeout value that cannot be changed via this option.
33+
34+
E.g. to set the timeout to 60 seconds for all CDS tests run (supposing their names contain "test_cds"):
35+
36+
.. code-block:: shell
37+
38+
pytest -E long --cds-timeout=60 -v -k test_cds
39+
40+
41+
Credentials
42+
~~~~~~~~~~~~~~~
43+
44+
Some tests require credentials to access remote services. The existence of credentials are checked and the related tests are skipped accordingly. The logic can be found in ``src/earthkit/data/testing.py``.
45+
46+
FDB tests
47+
~~~~~~~~~~~~
48+
49+
The :ref:`data-sources-fdb` tests are only run if ``pyfdb`` can be imported and the ``FDB_HOME`` environment variable is set. See the logic in ``src/earthkit/data/testing.py``.
50+
51+
52+
Optional dependencies
53+
~~~~~~~~~~~~~~~~~~~~~~~~~~
54+
55+
Tests generally require all optional dependencies to be installed. However, the availability of some optional dependencies are checked and the related tests are skipped accordingly. This is typically used for dependencies which are not part of the ``[all]`` install option (see :ref:`install`). The logic can be found in ``src/earthkit/data/testing.py``.
56+
57+
58+
no_cache_init tests
59+
~~~~~~~~~~~~~~~~~~~
60+
61+
Tests marked with ``pytest.mark.no_cache_init`` use the ``pytest-forked`` plugin to run in a separate process. They must be run as:
62+
63+
.. code-block:: shell
64+
65+
pytest --forked -v -m no_cache_init
66+
67+
68+
Notebooks
69+
~~~~~~~~~~~~~
70+
71+
The notebook examples from the ``docs/examples`` folder are part of the test suite and are run automatically. However, some notebooks are skipped mainly because they use remote data sources. This is controlled via the ``SKIP`` list in ``tests/documentation/test_notebooks.py``. You can modify this list to add or remove notebooks to be skipped.
72+
73+
To run only the notebooks tests you can use:
74+
75+
.. code-block:: shell
76+
77+
pytest -v -m notebook
78+
79+
80+
Documentation code snippets
81+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
82+
83+
All ``.py`` files in the ``docs`` folder can potentially contain example code snippets and are part of the test suite and run automatically. Many of these are actually not examples and skipped. This is controlled via the ``SKIP`` list in ``tests/documentation/test_examples.py``. You can modify this list to add or remove snippets to be skipped.

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Quick start
5656
howtos
5757
guide/index
5858
api
59-
development
59+
development/index
6060

6161
.. toctree::
6262
:maxdepth: 1

tests/documentation/test_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from earthkit.data.testing import earthkit_file
1717

18-
IGNORE = [
18+
SKIP = [
1919
"conf.py",
2020
"xml2rst.py",
2121
"actions.py",
@@ -37,7 +37,7 @@ def example_list():
3737
for root, _, files in os.walk(EXAMPLES):
3838
for file in files:
3939
path = os.path.join(root, file)
40-
if path.endswith(".py") and file not in IGNORE:
40+
if path.endswith(".py") and file not in SKIP:
4141
n = len(EXAMPLES) + 1
4242
examples.append(path[n:])
4343

0 commit comments

Comments
 (0)