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

Add pre-commit hook #13

Merged
merged 6 commits into from
Apr 10, 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
24 changes: 24 additions & 0 deletions .github/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/
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/[email protected]
- 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 }}
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,3 @@ configs/user/*

# exclude everything
tfscripts.egg-info/*


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$
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
| Testing | Coverage |
| :-----: | :------: |
| [![Build Status](https://travis-ci.org/icecubeopensource/tfscripts.svg?branch=master)](https://travis-ci.org/icecubeopensource/tfscripts) | [![Coverage Status](https://codecov.io/gh/icecubeopensource/tfscripts/branch/master/graph/badge.svg)](https://codecov.io/gh/icecubeopensource/tfscripts/branch/master)
| [![Unit Tests](https://github.com/icecube/tfscripts/actions/workflows/test_suite.yml/badge.svg)](https://github.com/icecube/tfscripts/actions/workflows/test_suite.yml)
[![codecov](https://codecov.io/github/icecube/tfscripts/graph/badge.svg?token=ZQ6K8V9F4U)](https://codecov.io/github/icecube/tfscripts)



# TFScripts
Expand Down
74 changes: 74 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "tfscripts"
description = "Collection of TF functions and helpful additions"
readme = "README.md"
dynamic = ["version"]
authors = [
{ name = "Mirco Huennefeld", email = "[email protected]" },
]
maintainers = [
{ name = "Mirco Huennefeld", email = "[email protected]" },
]
requires-python = ">=3.7"

dependencies = ["numpy", "matplotlib", "tensorflow"]

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/TFScripts"
Documentation = "https://github.com/icecube/TFScripts"
"Bug Tracker" = "https://github.com/icecube/TFScripts/issues"
Discussions = "https://github.com/icecube/TFScripts/discussions"

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

[tool.setuptools.dynamic]
version = {attr = "tfscripts.__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"
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

26 changes: 2 additions & 24 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,25 +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, 'tfscripts', '__about__.py')) as fobj:
exec(fobj.read(), about)

setup(
name='tfscripts',
version=about['__version__'],
packages=find_packages(),
install_requires=[
'numpy', 'matplotlib',
],
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()
Loading
Loading