Skip to content

Commit

Permalink
feat: Add stub of library (#1)
Browse files Browse the repository at this point in the history
* Add library with src/ directory layout
* Add tests with pytest
* Add CI with GitHub Actions
  • Loading branch information
matthewfeickert committed Aug 23, 2020
1 parent 7932810 commit 0f73c19
Show file tree
Hide file tree
Showing 19 changed files with 360 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .bumpversion.cfg
@@ -0,0 +1,8 @@
[bumpversion]
current_version = 0.0.1
commit = True
tag = True

[bumpversion:file:setup.py]

[bumpversion:file:src/heputils/version.py]
14 changes: 14 additions & 0 deletions .coveragerc
@@ -0,0 +1,14 @@
[run]
branch = True
source = src/heputils

[report]
exclude_lines =
if self.debug:
pragma: no cover
raise NotImplementedError
if __name__ == .__main__.:
ignore_errors = True
omit =
binder/*
tests/*
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,42 @@
name: CI

on:
push:
pull_request:
# Run daily at 0:01 UTC
schedule:
- cron: '1 0 * * *'

jobs:
test:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install -q --no-cache-dir --use-feature=2020-resolver -e .[complete]
python -m pip list
- name: Check MANIFEST
if: matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
run: |
check-manifest
- name: Test with pytest
run: |
python -m pytest -r sx
- name: Report coverage with Codecov
if: github.event_name == 'push' && matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
flags: unittests
28 changes: 28 additions & 0 deletions .github/workflows/lint.yml
@@ -0,0 +1,28 @@
name: Lint

on:
pull_request:

jobs:
lint:

name: Lint Codebase
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade -q --no-cache-dir --use-feature=2020-resolver -e .[lint]
python -m pip list
- name: Lint with Pyflakes
run: |
python -m pyflakes .
- name: Lint with Black
run: |
black --check --diff --verbose .
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.7
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at matthew.feickert@cern.ch. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
5 changes: 5 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,5 @@
graft src

include LICENSE

global-exclude __pycache__ *.py[cod]
60 changes: 60 additions & 0 deletions README.md
@@ -1,2 +1,62 @@
# heputils

[![GitHub Project](https://img.shields.io/badge/GitHub--blue?style=social&logo=GitHub)](https://github.com/matthewfeickert/heputils)
[![GitHub Actions Status: CI](https://github.com/matthewfeickert/heputils/workflows/CI/badge.svg?branch=master)](https://github.com/matthewfeickert/heputils/actions?query=workflow%3ACI+branch%3Amaster)
[![Code Coverage](https://codecov.io/gh/matthewfeickert/heputils/graph/badge.svg?branch=master)](https://codecov.io/gh/matthewfeickert/heputils?branch=master)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Helper utilities around the Scikit-HEP ecosystem for common tasks in HEP

**This library is not meant for wide use and will probably be deprecated in favor of [`scikit-hep`](https://github.com/scikit-hep/scikit-hep) soon.**
This library should be viewed as a testing grounds for API design decisions, hence it will not be put up on PyPI.

## Installation

In a fresh virtual environment

```
$ python -m pip install "git+https://github.com/matthewfeickert/heputils.git"
```

The above is actually cloning and installing directly from the Git repository.
However, if you want to, you can of course also install it directly from the Git repository "locally" by first cloning the repo and then from the top level of it running

```
$ python -m pip install .
```

## Contributing

As this library is experimental contributions of all forms are welcome.
If you have ideas on how to improve the API or conceptually how a library meant to introduce people to the Scikit-HEP ecosystem should be structured please open an Issue.
You are of course also most welcome and encouraged to open PRs.

### Developing

To develop, use a virtual environment.
Once the environment is activated, clone the repo from GitHub

```
git clone git@github.com:matthewfeickert/heputils.git
```

and install all necessary packages for development

```
python -m pip install --ignore-installed --upgrade -e .[complete]
```

Then setup the Git pre-commit hooks by running

```
pre-commit install
```

## Acknowledgements

This library is built upon the hard work of many people in the [Scikit-HEP ecosystem](https://scikit-hep.org/) and is only possible because of the exchange of ideas and contributions of people working together, across experiments and fields to improve science.
This is not an inevitability, but rather the result of directed thought, time, and effort, to which I am most thankful to have benefited from and have been involved in.

## Requests

Cite the software you use in your papers.
1 change: 1 addition & 0 deletions binder/postBuild
@@ -0,0 +1 @@
python -m pip install --upgrade .[complete]
20 changes: 20 additions & 0 deletions pyproject.toml
@@ -0,0 +1,20 @@
[tool.black]
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
\.git
| .eggs
| build
)/
'''

[tool.check-manifest]
ignore = [
'tests/**',
'binder/**',
'.*',
'pyproject.toml',
'pytest.ini',
'CODE_OF_CONDUCT.md',
]
2 changes: 2 additions & 0 deletions pytest.ini
@@ -0,0 +1,2 @@
[pytest]
addopts = --ignore=setup.py --ignore=binder/ --cov=heputils --cov-report=term-missing --cov-config=.coveragerc --cov-report xml --doctest-modules --doctest-glob='*.rst'
57 changes: 57 additions & 0 deletions setup.cfg
@@ -0,0 +1,57 @@
[metadata]
name = heputils
version = 0.0.1
description = Helper utilities around the Scikit-HEP ecosystem for common tasks in HEP
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/matthewfeickert/heputils
author = Matthew Feickert
author_email = matthew.feickert@cern.ch
license = BSD 3-Clause
license_file = LICENSE
keywords = hep utilities scikit-hep physics
project_urls =
Documentation = https://matthewfeickert.github.io/heputils/
Source = https://github.com/matthewfeickert/heputils
Tracker = https://github.com/matthewfeickert/heputils/issues
classifiers =
Development Status :: 3 - Alpha
License :: OSI Approved :: Apache Software License
Intended Audience :: Science/Research
Topic :: Scientific/Engineering
Topic :: Scientific/Engineering :: Physics
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8

[bdist_wheel]
universal = 1

[options]
setup_requires =
setuptools_scm>=1.15.0
setuptools_scm_git_archive>=1.0
package_dir =
= src
packages = find:
include_package_data = True
python_requires = >=3.6
install_requires =
click>=6.0
uproot~=3.12
mplhep>=0.1.31

[options.packages.find]
where = src

[options.entry_points]
console_scripts =
heputils = heputils.cli:cli

[build_sphinx]
project = heputils
source-dir = docs
build-dir = docs/_build
all-files = 1
warning-is-error = 1
25 changes: 25 additions & 0 deletions setup.py
@@ -0,0 +1,25 @@
from setuptools import setup

extras_require = {}
extras_require["lint"] = sorted(set(["pyflakes", "black"]))
extras_require["test"] = sorted(
set(
[
"check-manifest",
"pytest~=6.0",
"pytest-cov~=2.8",
"pytest-console-scripts~=0.2",
"pytest-mock~=3.0",
]
)
)
extras_require["develop"] = sorted(
set(
extras_require["test"]
+ extras_require["lint"]
+ ["check-manifest", "bumpversion~=0.5", "pre-commit", "twine"]
)
)
extras_require["complete"] = sorted(set(sum(extras_require.values(), [])))

setup(extras_require=extras_require)
3 changes: 3 additions & 0 deletions src/heputils/__init__.py
@@ -0,0 +1,3 @@
from .version import __version__

__all__ = ["__version__"]
4 changes: 4 additions & 0 deletions src/heputils/cli/__init__.py
@@ -0,0 +1,4 @@
"""The heputils command line interface."""
from .cli import heputils as cli

__all__ = ["cli"]
13 changes: 13 additions & 0 deletions src/heputils/cli/cli.py
@@ -0,0 +1,13 @@
import logging
import click

from ..version import __version__

logging.basicConfig()
log = logging.getLogger(__name__)


@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
@click.version_option(version=__version__)
def heputils():
pass
5 changes: 5 additions & 0 deletions src/heputils/version.py
@@ -0,0 +1,5 @@
"""Define heputils version information."""

# Use semantic versioning (https://semver.org/)
# The version number is controlled through bumpversion.cfg
__version__ = "0.0.1"
16 changes: 16 additions & 0 deletions tests/test_cli.py
@@ -0,0 +1,16 @@
import shlex
import heputils
import time


def test_version(script_runner):
command = "heputils --version"
start = time.time()
ret = script_runner.run(*shlex.split(command))
end = time.time()
elapsed = end - start
assert ret.success
assert heputils.__version__ in ret.stdout
assert ret.stderr == ""
# make sure it took less than a second
assert elapsed < 1.0
5 changes: 5 additions & 0 deletions tests/test_import.py
@@ -0,0 +1,5 @@
import heputils


def test_import():
assert heputils

0 comments on commit 0f73c19

Please sign in to comment.