Skip to content

Commit

Permalink
Setup pre-commit hoooks and change installation to use pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuen committed Apr 10, 2024
1 parent c3eecd1 commit 82092e7
Show file tree
Hide file tree
Showing 10 changed files with 263 additions and 28 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# .coveragerc

[run]
branch = True
source = ic3_labels

[report]

omit = ic3_labels/__about__.py
45 changes: 45 additions & 0 deletions .github/workflows/test_suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Unit Tests

on:
workflow_dispatch:
push:
branches:
- main
pull_request:

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [
"3.8",
"3.9",
"3.10",
"3.11",
"3.12",
]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: pre-commit/action@v3.0.0
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[test]
- name: Test with pytest
run: |
coverage run -m pytest -v -s
- name: Generate Coverage Report
run: |
coverage report -m
continue-on-error: false

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
67 changes: 67 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Adapted from simweights
# SPDX-FileCopyrightText: © 2022 the SimWeights contributors
#
# SPDX-License-Identifier: BSD-2-Clause

ci:
autoupdate_commit_msg: autoupdate pre-commit hooks
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/asottile/blacken-docs
rev: "1.16.0"
hooks:
- id: blacken-docs
args: [-l 100]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
hooks:
- id: ruff
args: [--fix, --show-fixes]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: [-L, livetime]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-no-log-warn
- id: python-no-eval
exclude: ^tests/.*
- id: python-use-type-annotations
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
- id: forbid-crlf
- id: forbid-tabs
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-toml
- id: check-vcs-permalinks
- id: debug-statements
- 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
exclude: \.svg$
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Contributing

Welcome and thanks for considering to contribute to this repository!

## Pre-commit Hooks

When contributing to this project, please utilize the pre-commit hooks. If not installed yet, you will need to add the python package `pre-commit`:

pip install pre-commit

Once the package is installed, simply install the pre-commit hooks defined in the repository by executing:

pre-commit install

from within the repository directory.

The pre-commit hooks will now automatically run when invoking `git commit`. Note, however, that this requires an active shell that has `pre-commit` installed.
You can also manually run the pre-commit on single files or on all files via:

pre-commit run --all-files

If you need to commit something even though there are errors (this should not have to be done!), then you can add the flag `--no-verify` to the `git commit` command. This will bypass the pre-commit hooks.

Additional information is provided here: https://pre-commit.com/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
| Testing | Coverage |
| :-----: | :------: |
| [![Unit Tests](https://github.com/icecube/ic3_labels/actions/workflows/test_suite.yml/badge.svg)](https://github.com/icecube/ic3_labels/actions/workflows/test_suite.yml) | [![codecov](https://codecov.io/github/icecube/ic3_labels/graph/badge.svg?token=ZQ6K8V9F4U)](https://codecov.io/github/icecube/ic3_labels)



# ic3-labels
Helper functions and I3-Modules to create labels for IceCube data
16 changes: 14 additions & 2 deletions ic3_labels/__about__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
__version__ = '1.1.0-dev'
__version__ = "1.1.0-dev"
__author__ = "Mirco Huennefeld"
__author_email__ = "mirco.huennefeld@tu-dortmund.de"
__description__ = "Creates MC labels for IceCube simulation data"
__description__ = "MC weights and labels for IceCube simulation data"
__url__ = "https://github.com/mhuen/ic3-labels"

__version_major__ = 1
__version_minor__ = 1
__version_patch__ = 0
__version_info__ = "-dev"

__version__ = "{}.{}.{}{}".format(
__version_major__,
__version_minor__,
__version_patch__,
__version_info__,
)
20 changes: 19 additions & 1 deletion ic3_labels/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
from ic3_labels.__about__ import __version__, __description__, __url__
from .__about__ import (
__version_major__,
__version_minor__,
__version_patch__,
__version_info__,
__version__,
__description__,
__url__,
)

__all__ = [
"__version_major__",
"__version_minor__",
"__version_patch__",
"__version_info__",
"__version__",
"__description__",
"__url__",
]
77 changes: 77 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "ic3_labels"
description = "MC weights and labels for IceCube simulation data"
readme = "README.md"
dynamic = ["version"]
authors = [
{ name = "Mirco Huennefeld", email = "mirco.huennefeld@tu-dortmund.de" },
]
maintainers = [
{ name = "Mirco Huennefeld", email = "mirco.huennefeld@tu-dortmund.de" },
]
requires-python = ">=3.7"

dependencies = [
'numpy', 'click', 'pyyaml', 'scipy', 'MCEq', 'crflux',
'nuVeto',
]

classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Statistics",
]

[project.optional-dependencies]
dev = ["pre-commit","black","ruff"]
test = ["pytest", "coverage", "codecov"]

[project.urls]
Homepage = "https://github.com/icecube/ic3_labels"
Documentation = "https://github.com/icecube/ic3_labels"
"Bug Tracker" = "https://github.com/icecube/ic3_labels/issues"
Discussions = "https://github.com/icecube/ic3_labels/discussions"

[tool.setuptools]
packages = ["ic3_labels"]

[tool.setuptools.dynamic]
version = {attr = "ic3_labels.__version__"}

[tool.black]
line-length = 79
target-version = ["py38"]

[tool.ruff]
# select = ["ALL"]
fixable = ["I"]
ignore = [
"D213", # multi-line-summary-second-line incompatible with multi-line-summary-first-line
"D203", # one-blank-line-before-class" incompatible with no-blank-line-before-class
"D401", # non-imperative-mood
"D417", # undocumented-param
"ANN101", # missing-type-self
"ANN401", # any-type
"FBT", # flake8-boolean-trap
"INP", # flake8-no-pep420
"T20", # flake8-print
"TCH", # flake8-type-checking
"S101", # assert-used
"F401", # imported but unused. NOTE: sooner or later, we should not ignore this
]
line-length = 79
target-version = "py38"

[tool.ruff.pydocstyle]
convention = "numpy"
27 changes: 2 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
#!/usr/bin/env python
import os
from setuptools import setup, find_packages
from setuptools import setup

here = os.path.dirname(__file__)

about = {}
with open(os.path.join(here, 'ic3_labels', '__about__.py')) as fobj:
exec(fobj.read(), about)

setup(
name='ic3_labels',
version=about['__version__'],
packages=find_packages(),
install_requires=[
'numpy', 'click', 'pyyaml', 'scipy', 'MCEq', 'crflux',
'nuVeto',
],
include_package_data=True,
author=about['__author__'],
author_email=about['__author_email__'],
maintainer=about['__author__'],
maintainer_email=about['__author_email__'],
description=about['__description__'],
url=about['__url__']
)
setup()
Empty file added test/__init__.py
Empty file.

0 comments on commit 82092e7

Please sign in to comment.