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

Update to match neurodatascience/nipoppy:main #53

Merged
merged 1 commit into from
Apr 29, 2024
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
11 changes: 9 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ exclude =
venv,
per-file-ignores =
# - docstrings rules that should not be applied to tests
tests/*: D100, D103, D104
**/test_*: D100, D103, D104
__init__.py:F401
# allow "weird indentation"
tests/test_workflow_*.py: D100, D103, D104, E131, E127, E501
max-line-length = 90
docstring-convention = numpy
max_complexity = 12
max_function_length = 150
# for compatibility with black
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
max-line-length = 88
extend-ignore = D105, E203, E704
49 changes: 49 additions & 0 deletions .github/workflows/run_tests_new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Run tests

on:
push:
branches: ['*']
pull_request:
branches: ['*']

# cancel previous runs if new one is triggered
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:

test:

runs-on: ubuntu-latest

# only trigger on upstream repo
if: github.repository_owner == 'neurodatascience' && github.event.repository.name == 'nipoppy'

steps:

- uses: actions/checkout@v3
with:
submodules: recursive

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install package
run: |
cd nipoppy_cli
pip install -U pip
pip install .[tests]

- name: Run tests
run: |
python -m pytest nipoppy_cli --cov=nipoppy_cli/nipoppy --cov-report=xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
name: codecov-umbrella
token: ${{ secrets.CODECOV_TOKEN }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ htmlcov


env/

# VS Code
.vscode/
21 changes: 17 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
# See https://pre-commit.com/hooks.html for more hooks

repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-ast
- id: check-case-conflict
Expand All @@ -15,9 +14,23 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-toml

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
hooks:
- id: black
args: [--config=pyproject.toml]
- repo: https://github.com/pyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
args: [--verbose, --config, .flake8]
additional_dependencies: [flake8-docstrings]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.5
rev: v2.2.6
hooks:
- id: codespell
args: [--toml=pyproject.toml]
Expand Down
21 changes: 21 additions & 0 deletions nipoppy_cli/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 NeuroDataScience

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions nipoppy_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
![License](https://img.shields.io/badge/license-MIT-blue.svg)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.8084759.svg)](https://doi.org/10.5281/zenodo.8084759)
![https://github.com/psf/black](https://img.shields.io/badge/code%20style-black-000000.svg)

# Nipoppy

A framework for standardized organization and processing of neuroimaging-clinical datasets.

## Developer setup

Clone this repo:

```bash
git clone https://github.com/neurodatascience/nipoppy.git
```

Install `nipoppy` in editable mode with `dev` dependencies:
```bash
cd nipoppy
pip install -e .[dev]
```

Set up `pre-commit`:
```bash
pre-commit install
```
1 change: 1 addition & 0 deletions nipoppy_cli/nipoppy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Nipoppy."""
71 changes: 71 additions & 0 deletions nipoppy_cli/nipoppy/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Base class."""

import inspect
from abc import ABC
from typing import Optional, Sequence


class Base(ABC):
"""Base class with utilities for pretty string representations."""

def _str_helper(
self,
components: Optional[Sequence] = None,
names: Optional[Sequence[str]] = None,
sep=", ",
) -> str:
"""Generate a custom string representation of an object.

The output string is of the form: ClassName(component1[sep]component2[sep]...)

Parameters
----------
components : Sequence, optional
Components to concatenate, by default None
names : Sequence[str], optional
Name of attributes to be added to the components as key-value pairs,
by default None
sep : str, optional
Separator between components, by default ", "

Returns
-------
str
String representation of the object.
"""
if components is None:
components = []

if names is not None:
for name in names:
components.append(f"{name}={getattr(self, name)}")

return f"{type(self).__name__}({sep.join([str(c) for c in components])})"

def __str__(self) -> str:
"""Return a string representation of the object based on its __init__ arguments.

Raises
------
RuntimeError
If the parameter names obtained from the __init__ method do not match the
attributes of the object.
"""
signature = inspect.signature(type(self))
names = [
name
for name, parameter in signature.parameters.items()
if parameter.kind is inspect.Parameter.POSITIONAL_OR_KEYWORD
]
try:
return self._str_helper(names=names)
except AttributeError:
raise RuntimeError(
f"The __init__ method of the {type(self)} class has positional and/or"
" keyword arguments that are not set as attributes of the object"
". Failed to build string representation: need to override the"
" __str__ method"
)

def __repr__(self) -> str:
return self.__str__()
1 change: 1 addition & 0 deletions nipoppy_cli/nipoppy/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Parsers and entrypoint for the command-line interface."""
Loading
Loading