Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
rkansal47 committed Feb 26, 2025
2 parents 09291c1 + 6313432 commit 92124c6
Show file tree
Hide file tree
Showing 20 changed files with 220 additions and 141 deletions.
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

85 changes: 37 additions & 48 deletions .github/workflows/pr_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,55 @@ name: PR Tests
on:
pull_request:
branches:
- master
- master

jobs:
linter:
name: Linter
pre-commit:
name: Format
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v1
- uses: actions/checkout@v4
with:
python-version: 3.9

- name: Install Python dependencies
run: pip install black flake8

- name: Run black
uses: wearerequired/lint-action@v2
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- uses: pre-commit/action@v3.0.1
with:
auto_fix: true
black: true
black_auto_fix: true

- name: Lint with flake8
run: flake8 rhalphalib --count --show-source --statistics
extra_args: --hook-stage manual --all-files

test:
name: Run pytest (Python ${{ matrix.python-version }}, ROOT ${{ matrix.root-version }})
needs: linter
name:
Run pytest (Python ${{ matrix.python-version }}, ROOT ${{
matrix.root-version }})
needs: pre-commit
runs-on: ubuntu-latest
strategy:
max-parallel: 4
fail-fast: true
matrix:
python-version: [3.7]
root-version: [6.16, 6.22]
python-version: ["3.10"]
root-version: ["6.30.04", "6.32.10"]
include:
- python-version: "3.9"
root-version: "6.22.8"

steps:
- uses: actions/checkout@v1
- name: Set up Conda
uses: conda-incubator/setup-miniconda@v2.2.0
with:
python-version: ${{ matrix.python-version }}
miniforge-variant: Mambaforge
channels: conda-forge,defaults
channel-priority: true
activate-environment: condaenv
- name: Install ROOT ${{ matrix.root-version }}
shell: bash -l {0}
run: |
mamba install -c conda-forge numpy scipy nomkl root==${{ matrix.root-version }}
- name: Install package
shell: bash -l {0}
run: |
pip install -e .
- name: Test with pytest
shell: bash -l {0}
run: |
pip install pytest
pytest tests
- uses: actions/checkout@v1
- name: Set up Conda
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
miniforge-version: latest
- name: Install ROOT ${{ matrix.root-version }}
shell: bash -l {0}
run: |
mamba install -c conda-forge numpy scipy nomkl root==${{ matrix.root-version }}
- name: Install package
shell: bash -l {0}
run: |
pip install .[test]
- name: Test with pytest
shell: bash -l {0}
run: |
pytest tests
32 changes: 16 additions & 16 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ __pycache__
*.egg-info
build
dist
.vscode
.vscode
81 changes: 76 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,80 @@
ci:
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

exclude: ^.cruft.json|.copier-answers.yml$

repos:
- repo: https://github.com/adamchainz/blacken-docs
rev: "1.19.1"
hooks:
- id: blacken-docs
additional_dependencies: [black==24.*]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
rev: "v5.0.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: name-tests-test
args: ["--pytest-test-first"]
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.4.2"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.9.2"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/codespell-project/codespell
rev: "v2.3.0"
hooks:
- id: codespell

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.10.0.1"
hooks:
- id: shellcheck

- repo: local
hooks:
- id: disallow-caps
name: Disallow improper capitalization
language: pygrep
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
exclude: .pre-commit-config.yaml

- repo: https://github.com/abravalheri/validate-pyproject
rev: "v0.23"
hooks:
- id: flake8
- repo: https://github.com/psf/black-pre-commit-mirror
rev: "23.10.1"
- id: validate-pyproject
additional_dependencies: ["validate-pyproject-schema-store[all]"]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.31.0"
hooks:
- id: black-jupyter
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

## Quickstart

First, install [Combine v9](https://cms-analysis.github.io/HiggsAnalysis-CombinedLimit/#installation-instructions) using
your choice of installation instructions (with CMSSW, using LCG, or inside a Conda environment), then in that environment, run:
First, install
[Combine v9](https://cms-analysis.github.io/HiggsAnalysis-CombinedLimit/#installation-instructions)
using your choice of installation instructions (with CMSSW, using LCG, or inside
a Conda environment), then in that environment, run:

```bash
python3 -m pip install --user https://github.com/nsmith-/rhalphalib/archive/master.zip
```
Take a look at [test_rhalphalib.py](https://github.com/nsmith-/rhalphalib/blob/master/tests/test_rhalphalib.py)

Take a look at
[test_rhalphalib.py](https://github.com/nsmith-/rhalphalib/blob/master/tests/test_rhalphalib.py)
for examples of how to use the package.
60 changes: 58 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
[tool.black]
line-length = 199
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "rhalphalib"
dynamic = ["version"]
authors = [
{name = "Nick Smith", email = "nick.smith@cern.ch"},
]
maintainers = [
{name = "Nick Smith", email = "nick.smith@cern.ch"},
]
description = "A binned fit intermediate representation library"
readme = "README.md"
license = {text = "BSD-3-Clause"}
# keywords = []
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Physics",
]
requires-python = ">=3.8"
dependencies = [
"numpy >=1.14",
"scipy",
"mplhep",
]

[project.optional-dependencies]
test = [
"pytest",
]
dev = [
"pre-commit",
]
docs = [
"sphinx>=7.0",
"myst_parser>=0.13",
"sphinx_copybutton",
"sphinx_autodoc_typehints",
"furo>=2023.08.17",
]

[project.urls]
Homepage = "https://github.com/nsmith-/rhalphalib"

[tool.setuptools_scm]
write_to = "src/rhalphalib/version.py"

[tool.ruff]
line-length = 199

[tool.codespell]
ignore-words-list = "fpt"
1 change: 0 additions & 1 deletion rhalphalib/version.py

This file was deleted.

50 changes: 2 additions & 48 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os.path
from setuptools import (
setup,
find_packages,
)
from setuptools import setup


about = {}
with open(os.path.join("rhalphalib", "version.py")) as f:
exec(f.read(), about)


needs_pytest = {"pytest", "test", "ptr"}.intersection(sys.argv)
pytest_runner = ["pytest-runner"] if needs_pytest else []

setup(
name="rhalphalib",
version=about["__version__"],
packages=find_packages(),
scripts=[],
include_package_data=True,
description="A binned fit intermediate representation library",
long_description=open("README.md", "rb").read().decode("utf8", "ignore"),
long_description_content_type="text/markdown",
maintainer="Nick Smith",
maintainer_email="nick.smith@cern.ch",
url="https://github.com/nsmith-/rhalphalib",
download_url="https://github.com/nsmith-/rhalphalib/releases",
license="BSD 3-clause",
test_suite="tests",
install_requires=[
"numpy>=1.14",
"scipy",
],
setup_requires=["flake8"] + pytest_runner,
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Scientific/Engineering :: Physics",
],
)
setup()
File renamed without changes.
File renamed without changes.
11 changes: 8 additions & 3 deletions rhalphalib/model.py → src/rhalphalib/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ def renderRoofit(self, workspace):

workspace.add(rooSimul)
rooObservable = ROOT.RooArgList(channel.observable.renderRoofit(workspace))
# that's right I don't need no CombDataSetFactory
rooData = ROOT.RooDataHist(self.name + "_observation", "Combined observation", rooObservable, channelCat, obsmap)
rooData = ROOT.RooDataHist(
self.name + "_observation",
"Combined observation",
rooObservable,
ROOT.RooFit.Index(channelCat),
ROOT.RooFit.Import(obsmap),
)
workspace.add(rooData)
elif rooSimul == None or rooData == None: # noqa: E711
raise RuntimeError("Model %r has a pdf or dataset already embedded in workspace %r" % (self, workspace))
Expand Down Expand Up @@ -168,7 +173,7 @@ def addSample(self, sample):
if sample.name in self._samples:
raise ValueError("Channel %r already has a sample named %s" % (self, sample.name))
if sample.name[: sample.name.find("_")] != self.name:
raise ValueError("Naming convention requires begining of sample %r name to be %s" % (sample, self.name))
raise ValueError("Naming convention requires beginning of sample %r name to be %s" % (sample, self.name))
if self._observable is not None:
if not sample.observable == self._observable:
raise ValueError("Sample %r has an incompatible observable with channel %r" % (sample, self))
Expand Down
Loading

0 comments on commit 92124c6

Please sign in to comment.