| 1 |
.. _install_developers: |
| 2 |
|
| 3 |
------------------------------ |
| 4 |
Installing HDMF for Developers |
| 5 |
------------------------------ |
| 6 |
|
| 7 |
|
| 8 |
Set up a virtual environment |
| 9 |
---------------------------- |
| 10 |
|
| 11 |
For development, we recommend installing HDMF in a virtual environment in editable mode. You can use |
| 12 |
the venv_ tool that comes packaged with Python to create a new virtual environment. Or you can use the |
| 13 |
`conda package and environment management system`_ for managing virtual environments. |
| 14 |
|
| 15 |
.. _venv: https://docs.python.org/3/library/venv.html |
| 16 |
.. _conda package and environment management system: https://conda.io/projects/conda/en/latest/index.html |
| 17 |
|
| 18 |
|
| 19 |
Option 1: Using venv |
| 20 |
^^^^^^^^^^^^^^^^^^^^ |
| 21 |
|
| 22 |
First, create a new virtual environment using the ``venv`` tool. This |
| 23 |
virtual environment will be stored in a new directory called ``"hdmf-env"`` in the current directory. |
| 24 |
|
| 25 |
.. code:: bash |
| 26 |
|
| 27 |
venv hdmf-env |
| 28 |
|
| 29 |
On macOS or Linux, run the following to activate your new virtual environment: |
| 30 |
|
| 31 |
.. code:: bash |
| 32 |
|
| 33 |
source hdmf-env/bin/activate |
| 34 |
|
| 35 |
On Windows, run the following to activate your new virtual environment: |
| 36 |
|
| 37 |
.. code:: batch |
| 38 |
|
| 39 |
hdmf-env\Scripts\activate |
| 40 |
|
| 41 |
This virtual environment is a space where you can install Python packages that are isolated from other virtual |
| 42 |
environments. This is especially useful when working on multiple Python projects that have different package |
| 43 |
requirements and for testing Python code with different sets of installed packages or versions of Python. |
| 44 |
|
| 45 |
Activate your newly created virtual environment using the above command whenever you want to work on HDMF. You can also |
| 46 |
deactivate it using the ``deactivate`` command to return to the base environment. And you can delete the virtual |
| 47 |
environment by deleting the directory that was created. |
| 48 |
|
| 49 |
|
| 50 |
Option 2: Using conda |
| 51 |
^^^^^^^^^^^^^^^^^^^^^ |
| 52 |
|
| 53 |
The `conda package and environment management system`_ is an alternate way of managing virtual environments. |
| 54 |
First, install Anaconda_ to install the ``conda`` tool. Then create and |
| 55 |
activate a new virtual environment called ``"hdmf-env"`` with Python 3.12 installed. |
| 56 |
|
| 57 |
.. code:: bash |
| 58 |
|
| 59 |
conda create --name hdmf-env python=3.12 |
| 60 |
conda activate hdmf-env |
| 61 |
|
| 62 |
Similar to a virtual environment created with ``venv``, a conda environment |
| 63 |
is a space where you can install Python packages that are isolated from other virtual |
| 64 |
environments. In general, you should use ``conda install`` instead of ``pip install`` to install packages |
| 65 |
in a conda environment. |
| 66 |
|
| 67 |
Activate your newly created virtual environment using the above command whenever you want to work on HDMF. You can also |
| 68 |
deactivate it using the ``conda deactivate`` command to return to the base environment. And you can delete the virtual |
| 69 |
environment by using the ``conda remove --name hdmf-venv --all`` command. |
| 70 |
|
| 71 |
.. note:: |
| 72 |
|
| 73 |
For advanced users, we recommend using Mambaforge_, a faster version of the conda package manager |
| 74 |
that includes conda-forge as a default channel. |
| 75 |
|
| 76 |
.. _Anaconda: https://www.anaconda.com/download |
| 77 |
.. _Mambaforge: https://github.com/conda-forge/miniforge |
| 78 |
|
| 79 |
Install from GitHub |
| 80 |
------------------- |
| 81 |
|
| 82 |
After you have created and activated a virtual environment, clone the HDMF git repository from GitHub, install the |
| 83 |
package requirements using the pip_ Python package manager, and install HDMF in editable mode. |
| 84 |
|
| 85 |
.. _pip: https://pip.pypa.io/en/stable/ |
| 86 |
|
| 87 |
.. code:: bash |
| 88 |
|
| 89 |
git clone --recurse-submodules https://github.com/hdmf-dev/hdmf.git |
| 90 |
cd hdmf |
| 91 |
pip install -r requirements.txt -r requirements-dev.txt -r requirements-doc.txt -r requirements-opt.txt |
| 92 |
pip install -e . |
| 93 |
|
| 94 |
.. note:: |
| 95 |
|
| 96 |
When using ``conda``, you may use ``pip install`` to install dependencies as shown above; however, it is generally |
| 97 |
recommended that dependencies should be installed via ``conda install``. |
| 98 |
|
| 99 |
|
| 100 |
Run tests |
| 101 |
--------- |
| 102 |
|
| 103 |
You can run the full test suite by running: |
| 104 |
|
| 105 |
.. code:: bash |
| 106 |
|
| 107 |
pytest |
| 108 |
|
| 109 |
This will run all the tests and compute the test coverage. The coverage report can be found in ``/htmlcov``. |
| 110 |
You can also run a specific test module or class, or you can configure ``pytest`` to start the |
| 111 |
Python debugger (PDB) prompt on an error, e.g., |
| 112 |
|
| 113 |
.. code:: bash |
| 114 |
|
| 115 |
pytest tests/unit/test_container.py # run all tests in the module |
| 116 |
pytest tests/unit/test_container.py::TestContainer # run all tests in this class |
| 117 |
pytest tests/unit/test_container.py::TestContainer::test_constructor # run this test method |
| 118 |
pytest --pdb tests/unit/test_container.py # start pdb on error |
| 119 |
|
| 120 |
|
| 121 |
You can run tests across multiple Python versions using the tox_ automated testing tool. Running ``tox`` will |
| 122 |
create a virtual environment, install dependencies, and run the test suite for different versions of Python. |
| 123 |
This can take some time to run. |
| 124 |
|
| 125 |
.. _pytest: https://docs.pytest.org/ |
| 126 |
.. _tox: https://tox.wiki/en/latest/ |
| 127 |
|
| 128 |
.. code:: bash |
| 129 |
|
| 130 |
tox |
| 131 |
|
| 132 |
You can also test that the Sphinx Gallery files run without warnings or errors by running: |
| 133 |
|
| 134 |
.. code:: bash |
| 135 |
|
| 136 |
python test_gallery.py |
| 137 |
|
| 138 |
|
| 139 |
Install latest pre-release |
| 140 |
-------------------------- |
| 141 |
|
| 142 |
To try out the latest features or set up continuous integration of your own project against the |
| 143 |
latest version of HDMF, install the latest release from GitHub. |
| 144 |
|
| 145 |
.. code:: bash |
| 146 |
|
| 147 |
pip install -U hdmf --find-links https://github.com/hdmf-dev/hdmf/releases/tag/latest --no-index |