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

2 update template #3

Merged
merged 8 commits into from
Oct 2, 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
17 changes: 13 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest] #, windows-latest, macos-latest] # Extend to your needs
python-version: ["3.9", "3.10", "3.11", "3.12"] # Extend to your needs

steps:
- uses: actions/checkout@v4
Expand All @@ -27,14 +28,22 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install flake8 pytest pytest-cov
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# TODO adapt package_name to the name of your package
- name: Test with pytest
run: |
pytest
pytest --cov package_name
# Add the following block to upload coverage to Codecov, requires a CODECOV_TOKEN secret to be set in the repository
# - name: Upload results to Codecov
# # Only upload to Codecov after a merge to the main branch
# if: github.ref == 'refs/heads/main' && github.event_name == 'push'
# uses: codecov/codecov-action@v4
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

# Contributing to BraTS

First off, thanks for taking the time to contribute! 🎉


## Contribute Code
Fork the repository, clone it and implement your contribution.

**Setup:**
- We use [poetry](https://python-poetry.org/), make sure it is installed: `pip install poetry`
- Install dependencies by running: `poetry install`

**Requirements:**
- Our project follows the [black code style](https://github.com/psf/black). Make sure your code is formatted accordingly.
- Please add _meaningful_ docstring for your functions and annotate types
- Please add _meaningful_ tests for your contribution in `/tests` and make sure _all_ tests are passing by running `python -m pytest`



Once done, create a Pull Request to integrate the code into our project!
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# brainles-template
Template for new BrainLes repositories
# PACKAGE_NAME

[![Python Versions](https://img.shields.io/pypi/pyversions/PACKAGE_NAME)](https://pypi.org/project/PACKAGE_NAME/)
[![Stable Version](https://img.shields.io/pypi/v/PACKAGE_NAME?label=stable)](https://pypi.python.org/pypi/PACKAGE_NAME/)
[![Documentation Status](https://readthedocs.org/projects/PACKAGE_NAME/badge/?version=latest)](http://PACKAGE_NAME.readthedocs.io/?badge=latest)
[![tests](https://github.com/BrainLesion/PACKAGE_NAME/actions/workflows/tests.yml/badge.svg)](https://github.com/BrainLesion/PACKAGE_NAME/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/BrainLesion/PACKAGE_NAME/graph/badge.svg?token=A7FWUKO9Y4)](https://codecov.io/gh/BrainLesion/PACKAGE_NAME)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

Description
## Features


## Installation

With a Python 3.8+ environment, you can install `PACKAGE_NAME` directly from [PyPI](https://pypi.org/project/brats/):

```bash
pip install PACKAGE_NAME
```


## Use Cases and Tutorials

A minimal example to create a segmentation could look like this:

```python
# example
```

<!-- For more examples and details please refer to our extensive Notebook tutorials here [NBViewer](https://nbviewer.org/github/BrainLesion/tutorials/blob/main/PACKAGE_NAME/tutorial.ipynb) ([GitHub](https://github.com/BrainLesion/tutorials/blob/main/PACKAGE_NAME/tutorial.ipynb)). For the best experience open the notebook in Colab. -->


## Citation

If you use PACKAGE_NAME in your research, please cite it to support the development!

```
TODO: citation will be added asap
```

## Contributing

We welcome all kinds of contributions from the community!

### Reporting Bugs, Feature Requests and Questions

Please open a new issue [here](https://github.com/BrainLesion/PACKAGE_NAME/issues).

### Code contributions

Nice to have you on board! Please have a look at our [CONTRIBUTING.md](CONTRIBUTING.md) file.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
49 changes: 49 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import sys
from subprocess import run


sys.path.insert(0, os.path.abspath("../../"))


run(["python", "preprocess_readme.py"])

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = "PACKAGE_NAME"
copyright = "2024, Marcel Rosier et al."
author = "Marcel Rosier, Florian Kofler"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
"sphinx_copybutton",
"myst_parser",
]

templates_path = ["_templates"]
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "furo"
# html_static_path = ["_static"]

autodoc_default_options = {
"members": True,
"undoc-members": True,
"private-members": False,
"show-inheritance": True,
}
22 changes: 22 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PACKAGE_NAME documentation
===================

.. include:: ../README_preprocessed.md
:parser: myst_parser.sphinx_


Sections
===================



.. toctree::
:maxdepth: 1
:caption: Getting Started:

readme

.. toctree::
:maxdepth: 2
:caption: API Reference:

36 changes: 36 additions & 0 deletions docs/source/preprocess_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import re


def preprocess_readme(input_file: str, output_file: str) -> None:
"""Preprocess a README file to replace GitHub admonitions with Sphinx-style admonitions.

Args:
input_file (str): original README file
output_file (str): processed README file

"""
with open(input_file, "r") as file:
content = file.read()

admonition_types = ["IMPORTANT", "NOTE", "TIP", "WARNING", "CAUTION"]

for ad_type in admonition_types:
# Replace > [!ad_type] with Sphinx admonition syntax
content = re.sub(
r"> \[!"
+ ad_type
+ "\]\s*\n((?:> .*\n)*)", # Match the > [!ad_type] and subsequent lines
lambda m: "```{"
+ ad_type
+ "}\n"
+ m.group(1).replace("> ", "").strip()
+ "\n```", # Replace with MyST syntax
content,
)
# Write the transformed content to the output file
with open(output_file, "w") as file:
file.write(content)


if __name__ == "__main__":
preprocess_readme("../../README.md", "../README_preprocessed.md")
6 changes: 6 additions & 0 deletions docs/source/readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Readme
==============


.. include:: ../README_preprocessed.md
:parser: myst_parser.sphinx_
Empty file added package_name/.gitignore
Empty file.
19 changes: 10 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@ build-backend = "poetry_dynamic_versioning.backend"
enable = true

[tool.poetry]
name = ""
name = "package_name"
version = "0.0.0"
description = ""
authors = ["Florian Kofler <[email protected]>"]
repository = ""
homepage = ""
documentation = ""
repository = "https://www.TODO.com"
homepage = "https://www.TODO.com"
documentation = "https://www.TODO.com"
readme = "README.md"


# Add the exclude field directly under [tool.poetry]
exclude = ["examples", "benchmark"]

[tool.poetry.dependencies]
python = "^3.10"
python = ">=3.9"


[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
pytest = ">=8.0.0"
pytest-cov = ">=5.0.0"

[tool.poetry.group.docs]
optional = true

[tool.poetry.group.docs.dependencies]
Sphinx = ">=7.0.0"
Sphinx = ">=7.0.0"
sphinx-copybutton = ">=0.5.2"
sphinx-rtd-theme = ">=1.3.0"
myst-parser = ">=2.0.0"
furo = ">=2024.8.6"
myst-parser = ">=2.0.0"
Loading