Skip to content

Commit

Permalink
feat: uv and deps update
Browse files Browse the repository at this point in the history
  • Loading branch information
clementpoiret committed Oct 29, 2024
1 parent 158c6a3 commit d0f01fd
Show file tree
Hide file tree
Showing 14 changed files with 1,945 additions and 78 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source_url "https://raw.githubusercontent.com/cachix/devenv/82c0147677e510b247d8b9165c54f73d32dfd899/direnvrc" "sha256-7u4iDd1nZpxL4tCzmPG0dQgC5V+/44Ba+tHkPob1v2k="

use devenv
43 changes: 13 additions & 30 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,32 @@ jobs:
strategy:
matrix:
operating-system: ["ubuntu-latest"]
python-version: ["3.9", "3.10", "3.11"]

runs-on: ${{ matrix.operating-system }}

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- uses: cachix/install-nix-action@v30
- uses: cachix/cachix-action@v15
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: false
virtualenvs-path: ~/.virtualenvs
installer-parallel: true

- name: Cache Poetry virtualenv
uses: actions/cache@v1
id: cache
with:
path: ~/.virtualenvs
key: poetry-${{ secrets.CACHE_VERSION }}-${{ matrix.python-version }}-${{ matrix.operating-system }}-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
poetry-${{ secrets.CACHE_VERSION }}-${{ matrix.python-version }}-${{ matrix.operating-system }}-${{ hashFiles('**/poetry.lock') }}
- name: Install Dependencies
run: poetry install --all-extras
if: steps.cache.outputs.cache-hit != 'true'

- name: Test & Coverage
run: poetry run coverage run --source=hsf -m pytest
name: devenv
- name: Install devenv.sh
run: nix profile install nixpkgs#devenv

- name: Run tests
shell: devenv shell bash -e {0}
run: |
uv sync
uv pip install onnxruntime>=1.8.0 deepsparse>=1.4.0
uv run coverage run --source=hsf -m pytest
uv run coverage xml
- name: Publish Coverage on CodeClimate
uses: paambaati/codeclimate-action@v3.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageCommand: poetry run coverage xml
coverageLocations: |
${{ github.workspace }}/coverage.xml:coverage.py
debug: true
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,12 @@ cython_debug/
.ionide

todolist.md
# Devenv
.devenv*
devenv.local.nix

# direnv
.direnv

# pre-commit
.pre-commit-config.yaml
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
6 changes: 4 additions & 2 deletions LAST_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

## Software

* Option to override already segmented mris.
* Minor fixes and optimizations.
* Updated ROILoc to v0.4.1 (latest ANTs version),
* Updated dependencies,
* Added a proper dev env using Nix,
* Switched from poetry to uv.

## Models

Expand Down
36 changes: 36 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ Table of Contents...

.. contents:: ...To guide you in the challenging world of hippocampal subfields segmentation :)

Development Environment
=======================

ROILoc relies on Nix_ and Devenv_.

.. _Nix: https://nixos.org/download/
.. _Devenv: https://devenv.sh

**Step 1**: Install Nix_:
::

sh <(curl -L https://nixos.org/nix/install) --daemon

**Step 2**: Install Devenv_:
::

nix-env -iA devenv -f https://github.com/NixOS/nixpkgs/tarball/nixpkgs-unstable

**Step 3**:
::

devenv shell

That's it :)

If you want something even easier, install direnv_ and
allow it to automatically activate the current env (``direnv allow``).

.. _direnv: https://direnv.net/

Installation
============
Expand Down Expand Up @@ -220,6 +249,13 @@ Changelogs
HSF
---

**Version 1.2.2**

* Updated ROILoc to v0.4.1 (latest ANTs version),
* Updated dependencies,
* Added a proper dev env using Nix,
* Switched from poetry to uv.

**Version 1.2.1**

* Option to override already segmented mris.
Expand Down
116 changes: 116 additions & 0 deletions devenv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"nodes": {
"devenv": {
"locked": {
"dir": "src/modules",
"lastModified": 1730028891,
"owner": "cachix",
"repo": "devenv",
"rev": "a337f8862efa9bde348c48a48b5b943f710604dd",
"type": "github"
},
"original": {
"dir": "src/modules",
"owner": "cachix",
"repo": "devenv",
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1729980323,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "86e78d3d2084ff87688da662cf78c2af085d8e73",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1729973466,
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "cd3e8833d70618c4eea8df06f95b364b016d4950",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1729104314,
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "3c3e88f0f544d6bb54329832616af7eb971b6be6",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"devenv": "devenv",
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
}
},
"root": "root",
"version": 7
}
31 changes: 31 additions & 0 deletions devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ pkgs, lib, config, inputs, ... }:
let
buildInputs = with pkgs; [
pythonManylinuxPackages.manylinux2014Package
stdenv.cc.cc
libuv
zlib
];
in {
# https://devenv.sh/packages/
#packages = [ pkgs.git ];
env = { LD_LIBRARY_PATH = "${with pkgs; lib.makeLibraryPath buildInputs}"; };

# https://devenv.sh/languages/
languages.python = {
enable = true;
uv = {
enable = true;
sync = { enable = true; };
};
};

enterShell = ''
uv sync
. ./.devenv/state/venv/bin/activate
'';

enterTest = ''
uv run pytest
'';
}
15 changes: 15 additions & 0 deletions devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# yaml-language-server: $schema=https://devenv.sh/devenv.schema.json
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable

# If you're using non-OSS software, you can set allowUnfree to true.
allowUnfree: true

# If you're willing to use a package that's vulnerable
# permittedInsecurePackages:
# - "openssl-1.1.1w"

# If you have more than one devenv you can merge them
#imports:
# - ./backend
8 changes: 8 additions & 0 deletions docs/about/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Current maintainers:

## HSF


### Version 1.2.1 (2024-10-29)

* Updated ROILoc to v0.4.1 (latest ANTs version),
* Updated dependencies,
* Added a proper dev env using Nix,
* Switched from poetry to uv.

### Version 1.2.1 (2024-03-29)

* Added an option to override already segmented mris.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<br>
<font size="+2"><b>Hippocampal</b> <i>Segmentation</i> Factory</font>
<br>
<b>Current HSF version:</b> 1.2.0<br>
<b>Current HSF version:</b> 1.2.2<br>
<b>Built-in Models version:</b> 4.0.0<br>
<b>Models in the Hub:</b> 4
</p>
Expand Down
15 changes: 9 additions & 6 deletions hsf/fetch_models.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import logging
from pathlib import Path

import wget
import requests
import xxhash
from omegaconf import DictConfig
from rich.logging import RichHandler

FORMAT = "%(message)s"
logging.basicConfig(level=logging.INFO,
format=FORMAT,
datefmt="[%X]",
handlers=[RichHandler()])
logging.basicConfig(
level=logging.INFO, format=FORMAT, datefmt="[%X]", handlers=[RichHandler()]
)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,7 +53,11 @@ def fetch(directory: str, filename: str, url: str, xxh3_64: str) -> None:
outfile.unlink()

log.info(f"Fetching {url}")
wget.download(url, out=str(outfile))
response = requests.get(url, stream=True)
response.raise_for_status()
with open(outfile, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print("\n")

if not xxh3_64 == get_hash(str(outfile)):
Expand Down
Loading

0 comments on commit d0f01fd

Please sign in to comment.