|
| 1 | +Development |
| 2 | +=========== |
| 3 | + |
| 4 | +The following document covers how to develop the InfluxDB client library |
| 5 | +locally. Including how to run tests and build the docs. |
| 6 | + |
| 7 | +.. contents:: |
| 8 | + :local: |
| 9 | + |
| 10 | +tl;dr |
| 11 | +^^^^^ |
| 12 | + |
| 13 | +.. code-block:: bash |
| 14 | +
|
| 15 | + # from your forked repo, create and activate a virtualenv |
| 16 | + python -m virtualenv venv |
| 17 | + . venv/bin/activate |
| 18 | + # install the library as editable with all dependencies |
| 19 | + make install |
| 20 | + # make edits |
| 21 | + # run lint and tests |
| 22 | + make lint test |
| 23 | +
|
| 24 | +Getting Started |
| 25 | +^^^^^^^^^^^^^^^ |
| 26 | + |
| 27 | +1. Install Python |
| 28 | + |
| 29 | + Most distributions include Python by default, so before going too far, try |
| 30 | + running ``python --version`` to see if it already exists. You may |
| 31 | + also have to specify ``python3 --version``, for example, on Ubuntu. |
| 32 | + |
| 33 | +2. Fork and clone the repo |
| 34 | + |
| 35 | + The rest of this assumes you have cloned your fork of the upstream |
| 36 | + `client library <https://github.com/influxdata/influxdb-client-python>`_ |
| 37 | + and are in the same directory of the forked repo. |
| 38 | + |
| 39 | +3. Set up a virtual environment. |
| 40 | + |
| 41 | + Python virtual environments let you install specific versioned dependencies |
| 42 | + in a contained manner. This way, you do not pollute or have conflicts on |
| 43 | + your system with different versions. |
| 44 | + |
| 45 | + .. code-block:: bash |
| 46 | +
|
| 47 | + python -m virtualenv venv |
| 48 | + . venv/bin/activate |
| 49 | +
|
| 50 | + Having a shell prompt change via `starship <https://starship.rs/>`_ |
| 51 | + or something similar is nice as it will let you know when and which |
| 52 | + virtual environment in you are in. |
| 53 | + |
| 54 | + To exit the virtual environment, run ``deactivate``. |
| 55 | + |
| 56 | +4. Install the client library |
| 57 | + |
| 58 | + To install the local version of the client library run: |
| 59 | + |
| 60 | + .. code-block:: bash |
| 61 | +
|
| 62 | + make install |
| 63 | +
|
| 64 | + This will install the library as editable with all dependencies. This |
| 65 | + includes all dependencies that are used for all possible features as well |
| 66 | + as testing requirements. |
| 67 | + |
| 68 | +5. Make changes and test |
| 69 | + |
| 70 | + At this point, a user can make the required changes necessary and run |
| 71 | + any tests or scripts they have. |
| 72 | + |
| 73 | + Before putting up a PR, the user should attempt to run the `lint` and `tests` |
| 74 | + locally. Lint will ensure the formatting of the code, while tests will run |
| 75 | + integration tests against an InfluxDB instance. For details on that set up |
| 76 | + see the next section. |
| 77 | + |
| 78 | + .. code-block:: bash |
| 79 | +
|
| 80 | + make lint test |
| 81 | +
|
| 82 | +Linting |
| 83 | +^^^^^^^ |
| 84 | + |
| 85 | +The library uses flake8 to do linting and can be run with: |
| 86 | + |
| 87 | + .. code-block:: bash |
| 88 | +
|
| 89 | + make lint |
| 90 | +
|
| 91 | +Testing |
| 92 | +^^^^^^^ |
| 93 | + |
| 94 | +The built-in tests assume that there is a running instance of InfluxDB 2.x up |
| 95 | +and running. This can be accomplished by running the |
| 96 | +``scripts/influxdb-restart.sh`` script. It will launch an InfluxDB 2.x instance |
| 97 | +with Docker and make it available locally on port 8086. |
| 98 | + |
| 99 | +Once InfluxDB is available, run all the tests with: |
| 100 | + |
| 101 | + .. code-block:: bash |
| 102 | +
|
| 103 | + make test |
| 104 | +
|
| 105 | +Code Coverage |
| 106 | +------------- |
| 107 | + |
| 108 | +After running the tests, an HTML report of the tests is available in the |
| 109 | +``htmlcov`` directory. Users can open ``html/index.html`` file in a browser |
| 110 | +and see a full report for code coverage across the whole project. Clicking |
| 111 | +on a specific file will show a line-by-line report of what lines were or |
| 112 | +were not covered. |
| 113 | + |
| 114 | +Documentation |
| 115 | +^^^^^^^^^^^^^ |
| 116 | + |
| 117 | +The docs are built using Sphinx. To build all the docs run: |
| 118 | + |
| 119 | + .. code-block:: bash |
| 120 | +
|
| 121 | + make docs |
| 122 | +
|
| 123 | +This will build and produce a sample version of the web docs at |
| 124 | +``docs/_build/html/index.html``. From there the user can view the entire site |
| 125 | +and ensure changes are rendered correctly. |
0 commit comments