Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move from mamba to pixi #594

Merged
merged 12 commits into from
Sep 14, 2023
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
22 changes: 9 additions & 13 deletions .github/workflows/core_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
test:
name: Julia ${{ matrix.julia_version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
Expand All @@ -29,18 +26,17 @@ jobs:
- x64
steps:
- uses: actions/checkout@v4
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/[email protected]
with:
cache-downloads: true
cache-environment: true
environment-file: ./environment.yml
- name: Install ribasim
run: pip install --editable python/ribasim
- name: Install ribasim_testmodels
run: pip install --editable python/ribasim_testmodels
pixi-version: latest
cache: true
- name: Prepare pixi
run: |
pixi install
pixi run post-install
- name: Prepare model input
run: python python/ribasim/tests/conftest.py
run: |
pixi run generate-testmodels
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia_version }}
Expand Down
37 changes: 10 additions & 27 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: write
defaults:
run:
shell: bash -l {0}
strategy:
matrix:
julia_version:
Expand All @@ -40,37 +37,23 @@ jobs:
cache-compiled: "true"
cache-registries: "true"

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/[email protected]
with:
cache-downloads: true
cache-environment: true
environment-file: ./environment.yml

- name: Install ribasim-python
run: pip install --editable python/ribasim

- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
pixi-version: latest
cache: true
- name: Prepare pixi
run: |
pixi install
pixi run post-install

- name: Check Quarto installation and all engines
run: quarto check all

- name: Generate API pages
working-directory: docs
# objects.json: https://github.com/machow/quartodoc/issues/63
run: |
quartodoc build
rm objects.json
run: pixi run quarto-check

- name: Generate Julia docs
working-directory: docs
run: |
julia --project -e "using Pkg; Pkg.instantiate()"
julia --project make.jl
run: pixi run build-julia-docs

- name: Render Quarto Project
run: "quarto render docs --to html --execute"
run: pixi run quarto-render

- name: Publish Quarto Project
if: github.ref == 'refs/heads/main'
Expand Down
24 changes: 9 additions & 15 deletions .github/workflows/python_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,22 @@ jobs:
name: Mypy
runs-on: ubuntu-latest
continue-on-error: true
defaults:
run:
shell: bash -l {0}
steps:
- uses: actions/checkout@v4
- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/[email protected]
with:
cache-downloads: true
cache-environment: true
environment-file: ./environment.yml
- name: Install python packages
pixi-version: "latest"
cache: true
- name: Prepare pixi
run: |
pip install python/ribasim
pip install python/ribasim_testmodels
pip install python/ribasim_api
pixi install
pixi run post-install
- name: Run mypy on python/ribasim
run: |
mypy --ignore-missing-imports python/ribasim/ribasim
pixi run mypy-ribasim-python
- name: Run mypy on python/ribasim_testmodels
run: |
mypy --ignore-missing-imports python/ribasim_testmodels/ribasim_testmodels
pixi run mypy-ribasim-testmodels
- name: Run mypy on python/ribasim_api
run: |
mypy --ignore-missing-imports python/ribasim_api/ribasim_api
pixi run mypy-ribasim-api
25 changes: 8 additions & 17 deletions .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ jobs:
test:
name: Python ${{ matrix.python_version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
strategy:
fail-fast: false
matrix:
Expand All @@ -32,23 +29,17 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Setup Micromamba
uses: mamba-org/setup-micromamba@v1
- uses: prefix-dev/[email protected]
with:
cache-downloads: true
cache-environment: true
environment-file: ./environment.yml
create-args: >-
python=${{ matrix.python_version }}

- name: Install ribasim
run: pip install --editable python/ribasim

- name: Install ribasim_testmodels
run: pip install --editable python/ribasim_testmodels
pixi-version: latest
cache: true
- name: Prepare pixi
run: |
pixi install
pixi run post-install

- name: Run tests
run: pytest --cov=ribasim --cov-report=xml python/ribasim/tests
run: pixi run test-ribasim-python-cov

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,5 @@ dmypy.json
.vscode/settings.json

/.luarc.json
build/ribasim_cli/tests/temp/
report.xml
3 changes: 0 additions & 3 deletions docs/contribute/addnode.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,5 @@ To generate the Python module `models.py` from the JSON Schemas, run:
datamodel-codegen --use-title-as-name --input docs/schema/root.schema.json --output python/ribasim/ribasim/models.py
```

Run [Black](python.qmd#sec-black) to format the generated code.
To catch possible Python issues run [Ruff](python.qmd#sec-ruff).

Since adding a node type touches both the Python and Julia code,
it is a good idea to run both the [Python test suite](python.qmd#test) and [Julia test suite](core.qmd#test) locally before creating a pull request.
25 changes: 3 additions & 22 deletions docs/contribute/core.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ pkg> add Revise TestEnv
Revise.jl is a library that allows you to modify code and use the changes without restarting Julia.
You can let it start automatically by following these [instructions](https://timholy.github.io/Revise.jl/stable/config/#Using-Revise-by-default-1).

## Install Quarto

Quarto is the publishing system that builds our documentation.
The installation instructions can be found on their [web page](https://quarto.org/docs/get-started/).

## Clone Ribasim

In order to have the Ribasim repository locally available, you can clone it with Git.
Expand Down Expand Up @@ -107,32 +102,18 @@ That way you don't have to type `activate core` every time you open the REPL.
## Render documentation

Example models are created and simulated as part of the rendering of the documentation.
Therefore you need to have both the `ribasim` Python package and the Julia `Ribasim` package
installed. Furthermore you need these 3 Python packages installed: `jupyter quartodoc xarray`.

The Python API reference is created using quartodoc by running this command from the `docs/`
folder:

```bash
quartodoc build
```

You typically only have to run this once, or if you want to check out how it looks after
changing Python docstrings.

The Julia API reference is created using Documenter.jl by running this command from the `docs/` folder:
The Julia API reference is created using Documenter.jl by running this command:

```bash
julia --project -e "using Pkg; Pkg.instantiate()" # needed once
julia --project make.jl # after changing the Julia docstrings
pixi run build-julia-docs
```

In order to preview documentation you can run the following command from the `docs/` folder.
Afterwards, a browser tab will open with the rendered documentation, updating it as you
make changes.

```bash
quarto preview
pixi run quarto-preview
```

The documentation also includes [Jupyter notebooks](https://jupyter.org/).
Expand Down
105 changes: 13 additions & 92 deletions docs/contribute/python.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,89 +4,26 @@ title: "Python tooling development"

# Set up the developer environment

## Setting up conda
## Setting up pixi

In order to develop on `ribasim` locally, please follow the following steps:
First, set up pixi as described on their getting started [page](https://prefix.dev/docs/pixi/overview).

- Download and install [miniconda](https://docs.conda.io/en/latest/miniconda.html).
Then set up the environment by running the following commands:

- Initialize `conda` by running the following in the `Miniconda prompt`:

```
conda init
```

- Depending on your company settings, you might also have to run the following in a Powershell terminal as administrator:

```
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
```

## Creating (or updating) the environment

- Create (or update) the environment by executing the following in your terminal:

```
conda env create --file=environment.yml --force
```

## Installing Python packages

- Activate the environment

```
conda activate ribasim
```

In order to develop on `ribasim` locally, execute the following line inside your virtual environment with the repo root as your working directory:

```bash
pip install --editable python/ribasim
pip install --editable python/ribasim_testmodels
pip install --editable python/ribasim_api
```

## Install the pre-commit hook {#sec-precommit}

If not already done, activate the environment:

```
conda activate ribasim
```

Pre-commit ensures that all linters are happy with your code before you commit your files.
In order to install the pre-commit hook run:

```bash
pre-commit install
pixi install
pixi run post-install
```


## Running the tests {#sec-test}

If not already done, activate the environment:

```
conda activate ribasim
```

To run the tests call `pytest` with the path to the Python package.
Here the the root of the repository is the working directory:
In order to run tests on Ribasim Python execute

```bash
pytest python/ribasim
```

## Building the documentation

Run in the docs folder:

```
quartodoc build
pixi run test-ribasim-python
```

This will generate the `.qmd` files in `docs/python/reference` for inspection.

## Updating example notebooks

Make sure to run `Clear All Outputs` on the notebook before committing.
Expand Down Expand Up @@ -136,42 +73,26 @@ twine check dist/*
twine upload dist/*
```

## Automatic code formatting with Black {#sec-black}

We use the [Black](https://black.readthedocs.io/en/stable/) code formatter.
Code only passes the continuous integration checks if it is fully formatted according to the Black code style.
When working in VS Code the settings suggested in @sec-vscode run Black automatically when saving Python files.

If you want to run Black manually, you can run it from the command line.
To run it on the entire repository, use the command below.
Here the repository root is the working directory.

```
black .
```

## Code linting with Ruff {#sec-ruff}

We use the [Ruff](https://github.com/charliermarsh/ruff) linter to help finding issues with Python code.
Code only passes the continuous integration checks if Ruff does not find any issues.
## Linting

To run Ruff on the entire repository, use the command below.
Here the repository root is the working directory.
To run our linting suite locally, execute:

```
ruff .
pixi run lint
```

# Code maintenance {#sec-codecov}

For new features new tests have to be added. To monitor how much of the code is covered by the tests we use [Codecov](https://about.codecov.io/).
For a simple overview of the local code coverage run
```
pixi shell
pytest --cov=ribasim tests/
```
from `python/ribasim`. For an extensive overview in `html` format use
```
ytest --cov=ribasim --cov-report=html tests/
pixi shell
pytest --cov=ribasim --cov-report=html tests/
```
which creates a folder `htmlcov` in the working directory. To see te contents open `htmlcov/index.html` in a browser.

Expand Down
Loading