Skip to content

Getting started with neuralfields

This pages explains how to install neuralfields via the package management system uv, how the CI/CD pipelines are set up using Task, and how pre-commit hooks are configured to keep the commits clean.

Installation

Installation of uv

This project is managed by uv, a Python packaging and dependency management tool. Therefore, uv must be installed first.

Please have a look at the official uv documentation on how to install uv on different platforms and under different conditions.

Installation of Task

The project commands are defined with Task. Install Task using the instructions in its official documentation.

Installation of neuralfields

The installation of this project is quite straightforward. Simply go to the project's directory, and run

uv sync

No project development intended?

If you don't need any development setup, run uv sync --no-dev to skip the development dependencies.

Computer says no...

Please find a collection of known failure cases below, and feel free to report more.

Symptom Hint
Something is wrong with my uv environment Delete the .venv folder and run uv sync again.

Dependency Management & Packaging

As mentioned in the Installation section, uv keeps the dependencies of different projects from interfering with each other. By running uv sync in the project's root folder, a separate .venv is created into which all runtime and development dependencies are installed automatically (typically takes a few seconds to minutes). This is similar to running pip install -r requirements.txt in an isolated virtual environment.

Project Tasks

Common project tasks are exposed through Task and run their Python tools through uv:

task test
Available tasks

To get a list of available tasks, execute task --list.

task: Available tasks for this project:
* bump-version-tag:              Create a new version tag
* clean:                         Remove generated files
* default:                       List available tasks
* deploy-docs:                   Deploy the documentation
* deploy-package:                Build and publish the package
* docs:                          Build the documentation
* format:                        Format Python files
* hooks:                         Install pre-commit hooks
* install-prerequisites:         Install system prerequisites for the current OS
* lint:                          Write mypy, pylint, and bandit reports
* push-latest-version-tag:       Push the latest version tag
* release:                       Test, build, and publish a stable release
* sync:                          Install runtime and development dependencies
* test:                          Run tests and generate coverage reports
* format:check:                  Check Black, isort, and autoflake without modifying files

Git Hooks

This project uses pre-commit hooks to automatically check for common formatting issues. The hooks are executed before every commit, but can be disabled by adding --no-verify when committing, e.g. git commit . -m "Fixed something" --no-verify.

Installation of pre-commit

After you cloned this project and plan to develop in it, don't forget to install these hooks via

task hooks
Available pre-commit hooks

The pre-commit hooks are configured in the .pre-commit-config.yaml file as follows

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.4.0
  hooks:
  - id: check-added-large-files
    args: [--maxkb=5000] # limit to 5MB per file
  - id: check-toml
  - id: check-yaml
    args: [--unsafe] # instead of loading the files, simply parse them for syntax
  - id: destroyed-symlinks
  - id: detect-private-key
  - id: end-of-file-fixer
  - id: fix-byte-order-marker
  - id: mixed-line-ending
  - id: name-tests-test
    args: [--pytest-test-first]
  - id: trailing-whitespace
- repo: https://github.com/psf/black
  rev: 23.1.0
  hooks:
  - id: black
- repo: https://github.com/pycqa/isort
  rev: 9.0.2
  hooks:
  - id: isort

GitHub Actions

There are basic CI, CD, and Release pipelines which are executed as GitHub actions workflow on pushing changes or opening pull requests.

Available workflows
name: Continuous Integration

on:
  pull_request:
  push:
    branches: [main]
  workflow_dispatch:

defaults:
  run:
    shell: bash

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: true

jobs:
  ci:
    name: CI
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest] # [ubuntu-latest, macos-latest, windows-latest]
        python-version: ["3.10", "3.13"]
    runs-on: ${{ matrix.os }}
    env:
      os: ${{ matrix.os }}
      python: ${{ matrix.python-version }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Task
        uses: go-task/setup-task@v2
        with:
          version: 3.x

      - name: Install prerequisites
        run: task install-prerequisites

      - name: Set up uv
        uses: astral-sh/setup-uv@v6
        with:
          version: "0.12.9"
          python-version: ${{ matrix.python-version }}
          enable-cache: true

      - name: Configure git
        run: |
          git config user.name "${GITHUB_ACTOR}"
          git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

      - name: Install dependencies
        run: uv sync --locked

      - name: Install and run pre-commit hooks
        env:
          SKIP: no-commit-to-branch
        run: |
          task hooks
          uv run --locked pre-commit run --all-files --show-diff-on-failure

      - name: Run tests
        run: task test

      - name: Code Coverage Summary
        if: runner.os == 'Linux'
        uses: irongut/CodeCoverageSummary@v1.3.0
        with:
          filename: coverage.xml
          format: markdown
          output: both

      - name: Build docs
        run: task docs

      - name: Deploy temporary docs
        if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10'
        run: |
          task deploy-docs \
          PUSH=true \
          ALIAS=pr-${{ github.event.number }} \
          VERSION_POSTFIX=pr-${{ github.event.number }}

      - name: Write PR note
        if: github.event_name == 'pull_request'
        run: |
          cat <<EOT>> pr_ci_note.md

          [temporary docs](https://github.com/famura/neuralfields/pr-${{ github.event.number }}").
          [tests](https://github.com/famura/neuralfields/pr-${{ github.event.number }}/exported/tests/report.html)
          [coverage](https://github.com/famura/neuralfields/pr-${{ github.event.number }}/exported/coverage/report.html)

          EOT

      - name: Add PR note
        if: github.event_name == 'pull_request'
        uses: marocchino/sticky-pull-request-comment@v2.3.1
        with:
          path: pr_ci_note.md
name: Continuous Deployment

on:
  push:
    branches: [main]
  workflow_dispatch:

defaults:
  run:
    shell: bash

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: true

jobs:
  cd:
    name: CD
    if: github.repository == 'famura/neuralfields'
    runs-on: ubuntu-latest
    permissions: # https://docs.github.com/en/actions/security-guides/automatic-token-authentication
      contents: write # to publish the docs to gh-pages
    env:
      os: ubuntu-latest
      python: "3.10"

    steps:
      - name: Install prerequisites
        env:
          DEBIAN_FRONTEND: noninteractive
        run: |
          sudo apt-get update
          sudo apt-get install --yes curl gcc git

      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Task
        uses: go-task/setup-task@v2
        with:
          version: 3.x

      - name: Set up uv
        uses: astral-sh/setup-uv@v6
        with:
          version: "0.12.9"
          python-version: "3.10"
          enable-cache: true

      - name: Configure git
        run: |
          git config user.name "${GITHUB_ACTOR}"
          git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

      - name: Install dependencies
        run: uv sync --locked

      - name: Bump patch version
        run: task bump-version-tag PART=patch

      - name: Deploy docs
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          task test
          task docs
          task deploy-docs PUSH=true ALIAS=latest

      - name: Deploy package
        env:
          USERNAME: ${{ secrets.PYPI_USER }}
          PASSWORD: ${{ secrets.PYPI_TOKEN }}
        run: |
          task deploy-package

      - name: Push version tag
        run: task push-latest-version-tag

  release_draft:
    name: Update release notes
    runs-on: ubuntu-latest
    permissions: # https://docs.github.com/en/actions/security-guides/automatic-token-authentication
      contents: write

    steps:
      - uses: release-drafter/release-drafter@v5.22.0
        with:
          config-name: release_drafter.yaml
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Release

on:
  workflow_dispatch:
    inputs:
      bumped-version-part:
        description: "The version part to bump."
        type: choice
        options:
          - major
          - minor
          - patch
        default: "minor"
        required: true

defaults:
  run:
    shell: bash

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: true

jobs:
  release:
    name: Release
    if: github.repository == 'famura/neuralfields'
    runs-on: ubuntu-latest
    permissions: # https://docs.github.com/en/actions/security-guides/automatic-token-authentication
      contents: write # to publish the docs to gh-pages
    env:
      os: ubuntu-latest
      python: "3.10"

    steps:
      - name: Install prerequisites
        env:
          DEBIAN_FRONTEND: noninteractive
        run: |
          sudo apt-get update
          sudo apt-get install --yes curl gcc git

      - name: Checkout repository
        uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Task
        uses: go-task/setup-task@v2
        with:
          version: 3.x

      - name: Set up uv
        uses: astral-sh/setup-uv@v6
        with:
          version: "0.12.9"
          python-version: "3.10"
          enable-cache: true

      - name: Configure git
        run: |
          git config user.name "${GITHUB_ACTOR}"
          git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

      - name: Install dependencies
        run: uv sync --locked

      - name: Publish to PyPI
        env:
          USERNAME: ${{ secrets.PYPI_USER }}
          PASSWORD: ${{ secrets.PYPI_TOKEN }}
        run: |
          task release PART=${{ github.event.inputs.bumped-version-part }}