Skip to content

Commit

Permalink
[INFRA] Configure tools (#2)
Browse files Browse the repository at this point in the history
* configure pre-commit and add some metadata to pyproject

* add linting ci workflow

* add pytest in dev dependencies

* add basic example functions and tests with CI
  • Loading branch information
NicolasGensollen authored Nov 15, 2024
1 parent dbdaee9 commit 91b5334
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint

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

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/[email protected]
29 changes: 29 additions & 0 deletions .github/workflows/unit_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Unit Tests

on:
push:
branches: ["main"]
pull_request:
branches: ["maint"]

permissions:
contents: read

jobs:
test:
name: Run unit tests on ${{ matrix.os }} with Python ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ['3.9', '3.10', '3.11', '3.12']
steps:
- uses: actions/checkout@v4
- uses: snok/install-poetry@v1
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: poetry
- name: Run unit tests
run: make test
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/python-poetry/poetry
rev: '1.7.1'
hooks:
- id: poetry-check

default_language_version:
python: python3
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
POETRY ?= poetry

.PHONY: check.lock
check.lock:
@$(POETRY) check --lock

.PHONY: install
install: check.lock
@$(POETRY) install

.PHONY: test
test: install
@$(POETRY) run python -m pytest -v tests/unittests
101 changes: 101 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 45 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,58 @@
[tool.poetry]
name = "clinicaio"
version = "0.1.0"
description = ""
description = "A Python library for input/output management of all Clinica projects."
license = "MIT"
authors = ["ARAMIS Lab"]
maintainers = ["Clinica developers <[email protected]>"]
readme = "README.md"
repository = "https://github.com/aramis-lab/clinicaio.git"
packages = [{include = "clinicaio", from = "src"}]
keywords = [
"bids",
"image processing",
"machine learning",
"neuroimaging",
"neuroscience"
]
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: End Users/Desktop",
"Operating System :: OS Independent",
"Topic :: Scientific/Engineering :: Medical Science Apps.",
"Topic :: Scientific/Engineering :: Image Processing"
]

[tool.poetry.dependencies]
python = "^3.12"
python = ">=3.9,<3.13"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
target-version = "py39"
line-length = 88

[tool.ruff.lint]
select = [
"E",
"W",
"I001",
"PTH",
]
ignore = ["E203", "E501"]

[tool.ruff.lint.isort]
known-first-party = ["clinicaio"]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
16 changes: 16 additions & 0 deletions src/clinicaio/hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
__all__ = ["greet"]


def greet(name: str):
"""Greet the person with provided name.
Parameters
----------
name : str
The name of the person to greet.
"""
print(_build_greeting_message(name))


def _build_greeting_message(name: str) -> str:
return f"Hello {name} !"
16 changes: 16 additions & 0 deletions tests/unittests/test_hello.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def test_build_greeting_message():
from clinicaio.hello import _build_greeting_message

assert (
_build_greeting_message("ClinicaIO developers")
== "Hello ClinicaIO developers !"
)


def test_greet(capsys):
from clinicaio.hello import greet

greet("John Doe")

captured = capsys.readouterr()
assert captured.out == "Hello John Doe !\n"

0 comments on commit 91b5334

Please sign in to comment.