Skip to content

Commit

Permalink
build: Migrate to hatchling for packaging (#553)
Browse files Browse the repository at this point in the history
* Change from setuptools to hatchling for packaging and package
  distribution building.
   - Move all packaging information into pyproject.toml.
   - Use vcs information to determine version information.
   - Ignore the vcs generated _version.py file.
   - Remove setup.cfg and VERSION files.
* Switching to getting version information from importlib.metadata.version
  in the docs.
* Clone the full repository history as needed in CI to get all tag information.
  • Loading branch information
matthewfeickert authored May 14, 2024
1 parent 853ee6a commit b7f7916
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 74 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ on:
paths:
- "docs/**"
- "madminer/**"
- "setup.py"
pull_request:
branches:
- main
paths:
- "docs/**"
- "madminer/**"
- "setup.py"
workflow_dispatch:

concurrency:
Expand All @@ -29,6 +27,8 @@ jobs:
steps:
- name: "Set up GitHub Actions"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Set up Python"
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
steps:
- name: "Set up GitHub Actions"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Set up Python"
uses: actions/setup-python@v5
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,6 @@ patches/
black.sh
run_sphinx.sh
publish.sh

# version information
*_version.py
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
PKG_VERSION = $(shell cat VERSION)
DOCS_FOLDER = "docs"
SOURCE_FOLDER = "madminer"
TESTS_FOLDER = "tests"


.PHONY: build
build:
@echo "Building package"
Expand All @@ -26,7 +24,8 @@ docs:
.PHONY: tag
tag:
@echo "Tagging current commit"
@git tag --annotate "v$(PKG_VERSION)" --message "Tag v$(PKG_VERSION)"
@git tag --annotate "v$(shell python -c 'from importlib.metadata import version; print(version("madminer"))')" \
--message "Tag v$(shell python -c 'from importlib.metadata import version; print(version("madminer"))')"
@git push --follow-tags


Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

14 changes: 8 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
# sys.path.insert(0, os.path.abspath('.'))

from pathlib import Path
import importlib.metadata

# -- Project information -----------------------------------------------------

project_folder = Path(__file__).parent.parent
version_file = project_folder.joinpath("VERSION")

project = 'MadMiner'
authors = 'Johann Brehmer, Felix Kling, Irina Espejo, Sinclert Perez, Kyle Cranmer'
version = open(version_file).read().strip()
copyright = '{} 2018-2020'.format(authors)

# The full version, including alpha/beta/rc tags
release = version
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
# The full version, including alpha/beta/rc tags.
release = importlib.metadata.version("madminer")
# for example take major/minor/patch
version = ".".join(release.split(".")[:3])


# -- General configuration ---------------------------------------------------
Expand Down
122 changes: 116 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,118 @@
# Black formatting options
[build-system]
requires = [
"hatchling>=1.13.0",
"hatch-vcs>=0.3.0",
]
build-backend = "hatchling.build"

[project]
name = "madminer"
dynamic = ["version"]
description = "Mining gold from MadGraph to improve limit setting in particle physics"
readme = "README.md"
license = { text = "MIT" } # SPDX short identifier
requires-python = ">=3.8"
authors = [
{ name = "Johann Brehmer", email = "[email protected]" },
{ name = "Felix Kling" },
{ name = "Irina Espejo" },
{ name = "Sinclert Perez" },
{ name = "Kyle Cranmer", email = "[email protected]" },
]
maintainers = [ {name = "Matthew Feickert", email = "[email protected]"} ]
keywords = [
"physics",
"simulation based inference",
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"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",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Physics",
]
dependencies = [
"h5py",
"matplotlib>=2.0.0",
"particle>=0.16.0",
"scipy>=1.0.0",
"sympy>=0.7.4",
"torch>=1.0.0",
"uproot>=4.0.0",
"vector>=0.8.4",
"numpy", # compatible versions controlled through scipy
]

[project.urls]
Documentation = "https://madminer.readthedocs.io/"
Homepage = "https://github.com/madminer-tool/madminer"
"Issue Tracker" = "https://github.com/madminer-tool/madminer/issues"
"Releases" = "https://github.com/madminer-tool/madminer/releases"
"Source Code" = "https://github.com/madminer-tool/madminer"

[project.optional-dependencies]
examples = [
"bqplot",
"pandas",
]

# Developer extras
lint = [
"black[jupyter]",
"isort",
]
test = [
"pytest>=6.0",
]
docs = [
"myst-parser",
"numpydoc",
"sphinx>=7.0.0",
"sphinx-rtd-theme>=1.3.0",
]

[tool.hatch.version]
source = "vcs"

[tool.hatch.version.raw-options]
local_scheme = "no-local-version"

[tool.hatch.build.hooks.vcs]
version-file = "madminer/_version.py"

[tool.hatch.build.targets.sdist]
# hatchling always includes:
# pyproject.toml, .gitignore, any README, any LICENSE, AUTHORS
only-include = [
"/madminer",
"/CITATION.cff"
]

[tool.hatch.build.targets.wheel]
packages = ["madminer"]

[tool.black]
line-length = 120
target-version = ['py38', 'py39', 'py310']
include = '(\.py$|\.ipynb$)'
include = '(\.pyi?$|\.ipynb$)'
exclude = '''
(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.nox
| \.venv
| _build
| buck-out
| build
| dist
| mg_processes
)
'''

Expand All @@ -24,3 +121,16 @@ force_single_line = true
ignore_whitespace = true
only_sections = true
profile = "black"

[tool.coverage.run]
source = ["madminer"]
branch = true
omit = ["*/madminer/typing.py"]

[tool.coverage.report]
precision = 1
sort = "cover"
show_missing = true
exclude_also = [
"if TYPE_CHECKING:"
]
56 changes: 0 additions & 56 deletions setup.cfg

This file was deleted.

0 comments on commit b7f7916

Please sign in to comment.