Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/python_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ concurrency:
jobs:
call-workflow-static-analysis:
name: Static analysis
uses: MiraGeoscience/CI-tools/.github/workflows/reusable-python-static_analysis.yml@9d0728c5214f5e416e580139fe0e7f1cea1237aa # GA-9681-pixi-workflow
uses: MiraGeoscience/CI-tools/.github/workflows/reusable-python-static_analysis.yml@4a000ba323d8818b874c907dd7cfb3b29960cba4 # v4.1.0
permissions:
contents: read
pull-requests: read
Expand All @@ -35,9 +35,12 @@ jobs:
app-name: 'grid_apps'
python-version: '3.12'
pixi-version: 'v0.84.2'
secrets:
JFROG_ARTIFACTORY_URL: ${{ secrets.JFROG_ARTIFACTORY_URL }}
JFROG_ARTIFACTORY_TOKEN: ${{ secrets.JFROG_ARTIFACTORY_TOKEN }}
Comment on lines +39 to +40
call-workflow-pytest:
name: Pytest
uses: MiraGeoscience/CI-tools/.github/workflows/reusable-python-pytest.yml@9d0728c5214f5e416e580139fe0e7f1cea1237aa # GA-9681-pixi-workflow
uses: MiraGeoscience/CI-tools/.github/workflows/reusable-python-pytest.yml@4a000ba323d8818b874c907dd7cfb3b29960cba4 # v4.1.0
permissions:
contents: read
pull-requests: read
Expand All @@ -51,4 +54,6 @@ jobs:
codecov-reference-python-version: '3.12'
codecov-reference-os: '["windows-latest"]'
secrets:
JFROG_ARTIFACTORY_URL: ${{ secrets.JFROG_ARTIFACTORY_URL }}
JFROG_ARTIFACTORY_TOKEN: ${{ secrets.JFROG_ARTIFACTORY_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ repos:
rev: v2.4.3
hooks:
- id: codespell
exclude: (\.lock|-lock\.ya?ml|\benvironments/.*\.ya?ml|\.ipynb|^THIRD_PARTY_SOFTWARE\.rst)$
exclude: (\.lock|\.ipynb|^THIRD_PARTY_SOFTWARE\.rst)$
entry: codespell -I .codespellignore
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
Expand Down
305 changes: 88 additions & 217 deletions README-dev.rst
Original file line number Diff line number Diff line change
@@ -1,250 +1,121 @@

Setup for development
=====================

.. contents:: Table of Contents
:local:
:depth: 2

After you have cloned the Git repository, you will need to:

#. install the Pixi environments for the project
#. execute the tests
#. setup Git LFS if needed
#. configure the prek hooks for static code analysis and auto-formatting
#. configure the Python IDE (PyCharm)


.. _Pixi: https://pixi.sh/
.. _prek: https://prek.j178.dev/


Install the Pixi environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Install `Pixi`_ version 0.84.2 or newer and external `uv <https://docs.astral.sh/uv/>`_.
Keep both commands on ``PATH``; uv is not installed by Pixi. From the project root,
install the default development environment with::

pixi install

The default environment includes the test and lint tools. Run the tests with::

pixi run test

The project also provides ``py312``, ``py313`` and ``py314`` test environments,
plus ``runtime`` environments for application use.
On Windows, run ``install_in_analyst.bat`` to install the locked runtime in Geoscience
Analyst; pass ``-e`` for an editable installation.
Prerequisites
^^^^^^^^^^^^^

* **Pixi and uv:** Install `Pixi <https://pixi.sh/>`_ 0.84.2 and external
`uv <https://docs.astral.sh/uv/>`_. Keep both commands on ``PATH``; uv is not
installed by Pixi.
* **Git LFS:** This repository uses Git LFS. Follow GitHub's `installation
instructions
<https://docs.github.com/en/repositories/working-with-files/managing-large-files/installing-git-large-file-storage>`_.
* **prek:** Install `prek <https://prek.j178.dev/>`_ for the configured Git
hooks.
* **IDE interpreter:** Configure your IDE to use the interpreter inside
``.pixi/envs/default`` and exclude ``.pixi`` from source indexing.
For **PyCharm**, follow Pixi's `JetBrains integration guide
<https://pixi.prefix.dev/latest/integration/editor/jetbrains/>`_.
* **JFrog authentication:** Pixi uses uv's PyPI authentication, which is
separate from ``pixi auth login``. Configure a protected ``.netrc`` file
(``%HOME%\_netrc`` on Windows) with your Artifactory machine, login, and
password or access token, as described in `Pixi's authentication guide
<https://pixi.prefix.dev/latest/deployment/authentication/#netrc-file>`_.
Never add credentials to ``pixi.toml`` or ``pixi.lock``.

.. note:: External contributors using Pixi

If you do not have Mira Artifactory credentials, comment out ``index-url``
under ``[feature.mira-pypi.pypi-options]`` in ``pixi.toml``, then run
``pixi lock``. Packages configured with version references will resolve from
public PyPI if the required versions are available there; packages configured
with Git references will resolve from Git.
Keep these local ``pixi.toml`` and ``pixi.lock`` changes uncommitted.

Install and test
^^^^^^^^^^^^^^^^

The shared lock covers Windows and Linux with multiple Python versions::

pixi install --locked -e py312
pixi run --frozen -e py312 install
pixi run --frozen -e py312 test

The ``install`` task installs this checkout in editable mode without changing
locked dependencies, then checks package compatibility.

The ``runtime`` environment omits test and lint tools.

On Windows, install the locked runtime into Geoscience Analyst with::

install_in_analyst.bat
install_in_analyst.bat -e --name mirageo-dev

Possibly, replace ``mirageo-dev`` with a dedicated environment name of your choice.

The script exports the locked ``win-64`` runtime, installs its dependencies
through Analyst, and installs this checkout without resolving dependencies
again. Pass ``-e`` first for editable mode; optional ``--conda`` and ``--name``
arguments are forwarded to Analyst. A valid ``pixi.lock`` is required. When the
lock points to JFrog, Analyst's pip installation also needs access, for example
through the same ``.netrc`` credentials.

Building documentation
^^^^^^^^^^^^^^^^^^^^^^

Install `uv <https://docs.astral.sh/uv/>`_ alongside Pixi and keep both commands
available on ``PATH``. Read the Docs installs uv 0.13.8 separately.

The separate ``docs`` environment uses Python 3.14. Build the HTML documentation with::
The separate ``docs`` environment uses Python 3.14 and Sphinx. Read the Docs
installs uv separately. Fetch the Git LFS documentation images, then
build HTML with::

git lfs pull
pixi run --frozen --environment docs build-docs

The output is written to ``docs/_build/html``. Read the Docs uses the same task and
also creates the downloadable ``grid-apps-docs.zip`` archive.

The task installs the local package without dependencies, uses the checked-in
configuration ``docs/source/conf.py``, and builds the documentation from
``docs/source`` into ``docs/_build/html``. Read the Docs uses the same task.

Updating dependencies
^^^^^^^^^^^^^^^^^^^^^

Runtime dependency constraints are maintained in ``pyproject.toml`` and ``pixi.toml``.
After changing either file, refresh the resolved environment with::

pixi update
Keep published package requirements in ``pyproject.toml`` and their Conda/PyPI
environment equivalents in ``pixi.toml`` aligned. Update the recipe's matching
runtime requirements when a dependency constraint changes.

After editing requirements, run ``pixi update`` to update dependencies, or
``pixi lock`` to resolve the manifest and refresh the lock file without
installing the environments.

Adding a dependency
-------------------
Add runtime requirements to both the PEP 621 dependency list in ``pyproject.toml``
and the matching Pixi package requirements in ``pixi.toml``. Put development-only
tools in the appropriate Pixi feature. Run ``pixi update`` after changing them.
Commit ``pixi.lock`` with the manifest changes. In ``pixi.toml``, the
``mira-pypi`` feature lists Mira packages resolved from PyPI or GitHub:

- On a development branch, comment out published versions and use git sources.
- When preparing a release, use published versions and comment out git sources.

Configure prek hooks
^^^^^^^^^^^^^^^^^^^^
The lock file is checked by ``tests/pixi_lock_test.py``: it ensures all dependencies
are resolved from Conda, except for the Mira packages listed under the
``mira-pypi`` feature. Keep compatibility bounds on indirect Conda dependencies:
Pixi solves Conda before PyPI and does not backtrack between them.

`prek`_ runs the checks configured in ``.pre-commit-config.yaml``. Install it with::

uv tool install prek
Git hooks
^^^^^^^^^

From the project directory, install the Git hook and run all checks with::
Install `prek <https://prek.j178.dev/>`_ and use the existing hook configuration::

prek install --prepare-hooks
prek install -t prepare-commit-msg -t commit-msg -t pre-commit -f --prepare-hooks
prek run --all-files

Run ``prek run`` to check only the files selected for the current commit. Update
hook revisions with ``prek auto-update``.


Running the tests
^^^^^^^^^^^^^^^^^

Test files are placed under the ``tests`` folder. Inside this folder and sub-folders,
Python test files are to be named with ``_test.py`` as a suffix.
The test function within this files must have a ``test_`` prefix.


Install pytest
--------------
.. _pytest: https://docs.pytest.org/

After installing the default Pixi environment, run pytest from the project folder::

pixi run pytest tests


Code coverage with Pytest
-------------------------
.. _pytest-cov: https://pypi.org/project/pytest-cov/

`pytest-cov`_ is installed in the default environment. Run the tests with HTML coverage::

pixi run pytest --cov-report html tests

The html report is generated in the folder ``htmlcov`` at the root of the project.
You can then explore the report by opening ``index.html`` in a browser.


Git LFS
^^^^^^^
In the case your package requires large files, `git-lfs`_ can be used to store those files.
Copy it from the `git-lfs`_ website, and install it.

Then, in the project folder, run the following command to install git-lfs::

$ git lfs install


It will update the file ``.gitattributes`` with the list of files to track.

Then, add the files and the ``.gitattributes`` to the git repository, and commit.

.. _git-lfs: https://git-lfs.com/
The local pylint hook runs in the locked ``py312`` environment.

Then, add the files to track with git-lfs::
Test layout
^^^^^^^^^^^

$ git lfs track "*.desire_extension"
Tests live under ``tests`` and use the ``_test.py`` filename suffix.


IDE : PyCharm
^^^^^^^^^^^^^
`PyCharm`_, by JetBrains, is a very good IDE for developing with Python.


Configure the Python interpreter in PyCharm
--------------------------------------------

First, exclude the ``.pixi`` folder from PyCharm by right-clicking it and selecting
``Mark Directory as > Excluded``.

.. image:: devtools/images/pycharm-exclude_conda_env.png
:alt: PyCharm: Exclude Pixi environment
:align: center
:width: 40%

Add the Pixi environment's Python interpreter (``.pixi/envs/default/Scripts/python.exe``
on Windows or ``.pixi/envs/default/bin/python`` on Linux).

In PyCharm settings, open ``File > Settings``, go to ``Python Interpreter``,
and add click add interpreter (at the top left):

.. image:: devtools/images/pycharm-add_Python_interpreter.png
:alt: PyCharm: Python interpreter settings
:align: center
:width: 80%

Select the option for an existing or system interpreter and choose the Python executable
inside ``.pixi/envs/default``:

.. image:: devtools/images/pycharm-set_conda_env_as_interpreter.png
:alt: PyCharm: Set Pixi environment as interpreter
:align: center
:width: 80%

Then you can check the list of installed packages in the ``Packages`` table. You should see
this source package and its dependencies. Make sure to turn off the ``Use Conda Package Manager``
option to see also the packages installed through pip:

.. image:: devtools/images/pycharm-list_all_conda_packages.png
:alt: PyCharm: Pixi environment packages
:align: center
:width: 80%


Run the tests from PyCharm
--------------------------
First, right click on the ``tests`` folder and select ``Mark Directory as > Test Sources Root``:

.. image:: devtools/images/pycharm-mark_directory_as_tests.png
:alt: PyCharm: Add Python interpreter
:align: center
:width: 40%

You can now start tests with a right click on the ``tests`` folder and
select ``Run 'pytest in tests'``, or select the folder and just hit ``Ctrl+Shift+F10``.

PyCharm will nicely present the test results and logs:

.. image:: devtools/images/pycharm-test_results.png
:alt: PyCharm: Run tests
:align: center
:width: 80%

---------

Execute tests with coverage from PyCharm
----------------------------------------

You can run the tests with a nice report of the code coverage, thanks to the pytest-cov plugin
(already installed in the virtual environment as development dependency as per `pyproject.toml`_).


To set up this option in PyCharm, right click on the ``tests`` folder and ``Modify Run Configuration...``,
then add the following option in the ``Additional Arguments`` field:

.. image:: devtools/images/pycharm-menu_modify_test_run_config.png
:alt: PyCharm tests contextual menu: modify run configuration
:width: 30%

.. image:: devtools/images/pycharm-dialog_edit_test_run_config.png
:alt: PyCharm dialog: edit tests run configuration
:width: 60%

Select ``pytest in tests``, and add the following option in the ``Additional Arguments`` field::

--cov --cov-report html

Then, run the tests as usual, and you will get a nice report of the code coverage.

.. note::

Running tests with coverage disables the debugger, so breakpoints will be ignored.

Some useful plugins for PyCharm
--------------------------------
Here is a suggestion for some plugins you can install in PyCharm.

- `Toml`_, to edit and validate ``pyproject.toml`` file.
- `IdeaVim`_, for Vim lovers.
- `GitHub Copilot`_, for AI assisted coding.

.. _PyCharm: https://www.jetbrains.com/pycharm/

.. _Toml: https://plugins.jetbrains.com/plugin/8195-toml/
.. _IdeaVim: https://plugins.jetbrains.com/plugin/164-ideavim/
.. _GitHub Copilot: https://plugins.jetbrains.com/plugin/17718-github-copilot

.. _pyproject.toml: pyproject.toml
.. _.pre-commit-config.yaml: .pre-commit-config.yaml


Copyright
^^^^^^^^^
Copyright (c) 2024-2026 Mira Geoscience Ltd.
*Copyright (c) 2026 Mira Geoscience Ltd.*
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ License
^^^^^^^
MIT License

Copyright (c) 2024-2025 Mira Geoscience
Copyright (c) 2026 Mira Geoscience Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -194,4 +194,4 @@ Trademarks

Copyright
^^^^^^^^^
Copyright (c) 2024-2026 Mira Geoscience Ltd.
Copyright (c) 2026 Mira Geoscience Ltd.
Binary file not shown.
Binary file not shown.
Binary file removed devtools/images/pycharm-exclude_conda_env.png
Binary file not shown.
Binary file not shown.
Binary file removed devtools/images/pycharm-mark_directory_as_tests.png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed devtools/images/pycharm-test_results.png
Binary file not shown.
Loading
Loading