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

BREAK: drop Python 3.6 support #39

Merged
merged 2 commits into from
Apr 5, 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
2 changes: 0 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
".vscode/*",
"codecov.yml",
"pyproject.toml",
"setup.cfg",
"setup.py",
"tox.ini"
],
"language": "en-US",
Expand Down
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ repos:
- id: check-hooks-apply
- id: check-useless-excludes

- repo: https://github.com/ComPWA/policy
rev: 0.2.2
hooks:
- id: check-dev-files
args:
- --no-notebooks
- --no-prettierrc
- --repo-name=sphinx-hep-pdgref
- --repo-title=sphinx-hep-pdgref
- id: format-setup-cfg

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down Expand Up @@ -62,6 +51,16 @@ repos:
hooks:
- id: blacken-docs

- repo: https://github.com/ComPWA/policy
rev: 0.2.2
hooks:
- id: check-dev-files
args:
- --no-notebooks
- --no-prettierrc
- --repo-name=sphinx-hep-pdgref
- --repo-title=sphinx-hep-pdgref

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.3.0
hooks:
Expand Down
97 changes: 94 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,101 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=36.2.1", # environment markers
"setuptools>=61.2",
"setuptools_scm",
"wheel",
]

[project]
authors = [{name = "Common Partial Wave Analysis", email = "[email protected]"}]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python",
"Topic :: Documentation",
"Topic :: Utilities",
"Typing :: Typed",
]
dependencies = [
"Sphinx",
"attrs >=20.1.0", # on_setattr and https://www.attrs.org/en/stable/api.html#next-gen
"docutils",
]
description = "Sphinx role for linking to PDG reviews and listing"
dynamic = ["version"]
keywords = [
"particle data group",
"pdg",
"reference",
"sphinx",
]
license = {text = "BSD 3-Clause License"}
maintainers = [{email = "[email protected]"}]
name = "sphinx-hep-pdgref"
requires-python = ">=3.7"

[project.optional-dependencies]
dev = [
"sphinx-hep-pdgref[sty]",
"sphinx-hep-pdgref[test]",
"tox >=1.9", # for skip_install, use_develop
]
format = [
"black",
]
lint = [
"ruff",
"sphinx-hep-pdgref[mypy]",
]
mypy = [
"mypy >=0.730", # attrs and error code support
"types-docutils",
"types-setuptools",
]
sty = [
"pre-commit >=1.4.0",
"sphinx-hep-pdgref[format]",
"sphinx-hep-pdgref[lint]",
"sphinx-hep-pdgref[test]", # for pytest type hints
]
test = [
"pyquery", # for checking HTML output
"pytest",
"pytest-cov",
"pytest-xdist",
'importlib-metadata; python_version <"3.8.0"',
]

[project.readme]
content-type = "text/markdown"
file = "README.md"

[project.urls]
Changelog = "https://github.com/ComPWA/sphinx-hep-pdgref/releases"
Documentation = "https://github.com/ComPWA/sphinx-hep-pdgref/blob/main/README.md"
Source = "https://github.com/ComPWA/sphinx-hep-pdgref"
Tracker = "https://github.com/ComPWA/sphinx-hep-pdgref/issues"

[tool.setuptools]
include-package-data = true
license-files = ["LICENSE"]
package-dir = {"" = "src"}

[tool.setuptools.package-data]
"*" = ["py.typed"]

[tool.setuptools.packages.find]
namespaces = false
where = ["src"]

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

Expand All @@ -28,7 +119,6 @@ target-version = [
"py310",
"py311",
"py312",
"py36",
"py37",
"py38",
"py39",
Expand Down Expand Up @@ -116,6 +206,7 @@ extend-select = [
"D",
"EM",
"ERA",
"FA",
"I",
"ICN",
"INP",
Expand Down
83 changes: 0 additions & 83 deletions setup.cfg

This file was deleted.

6 changes: 0 additions & 6 deletions setup.py

This file was deleted.

9 changes: 6 additions & 3 deletions src/sphinx_hep_pdgref/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Link to PDG reviews and listings in Sphinx documentation."""

from typing import Any, Dict
from __future__ import annotations

from sphinx.application import Sphinx
from typing import TYPE_CHECKING, Any

from .role import URLPattern, pdgref

if TYPE_CHECKING:
from sphinx.application import Sphinx

def setup(app: Sphinx) -> Dict[str, Any]:

def setup(app: Sphinx) -> dict[str, Any]:
app.add_role("pdg-listing", role=pdgref(pattern=URLPattern.LISTING))
app.add_role("pdg-review", role=pdgref(pattern=URLPattern.REVIEW))
return {
Expand Down
13 changes: 7 additions & 6 deletions src/sphinx_hep_pdgref/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
directly lead to the correct page number when clicking the generated link.
"""

from __future__ import annotations

import re
from typing import Optional

from attrs import field, frozen

Expand All @@ -26,8 +27,8 @@ class PDGEntry:

section: str
year: int
pages: Optional[str]
first_page: Optional[int] = field(init=False, repr=False)
pages: str | None
first_page: int | None = field(init=False, repr=False)

def __attrs_post_init__(self) -> None:
if self.pages is None:
Expand All @@ -37,7 +38,7 @@ def __attrs_post_init__(self) -> None:
object.__setattr__(self, "first_page", first_page)

@staticmethod
def from_str(text: str) -> "PDGEntry":
def from_str(text: str) -> PDGEntry:
"""Create an entry from the contents of the :code:`pdg` role.

>>> from sphinx_hep_pdgref.entry import PDGEntry
Expand Down Expand Up @@ -76,7 +77,7 @@ def get_first_page(text: str) -> int:
return int(first_page_nr)


def get_page_numbers(text: str) -> Optional[str]:
def get_page_numbers(text: str) -> str | None:
text = text.strip()
matches = re.match(r"pp?\.?\s*(\d+.*)", text)
if matches is None:
Expand All @@ -85,7 +86,7 @@ def get_page_numbers(text: str) -> Optional[str]:
return page_nr_def.replace(" ", "")


def get_year(text: str) -> Optional[int]:
def get_year(text: str) -> int | None:
text = text.strip()
matches = re.match(r"\d{4}", text)
if matches is None:
Expand Down
18 changes: 11 additions & 7 deletions src/sphinx_hep_pdgref/role.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
"""Link to PDG reviews and listings in Sphinx documentation."""

from typing import Dict, List, Optional, Tuple
from __future__ import annotations

from typing import TYPE_CHECKING

from docutils import nodes
from docutils.nodes import Node, system_message
from docutils.parsers.rst.states import Inliner
from sphinx.util.typing import RoleFunction

from .entry import PDGEntry
from .url import URLPattern, create_link_text, create_url

if TYPE_CHECKING:
from docutils.nodes import Node, system_message
from docutils.parsers.rst.states import Inliner
from sphinx.util.typing import RoleFunction


def pdgref(pattern: URLPattern) -> RoleFunction:
def role( # noqa: PLR0913
Expand All @@ -18,9 +22,9 @@ def role( # noqa: PLR0913
text: str,
lineno: int,
inliner: Inliner,
options: Optional[Dict] = None,
content: Optional[List[str]] = None,
) -> Tuple[List[Node], List[system_message]]:
options: dict | None = None,
content: list[str] | None = None,
) -> tuple[list[Node], list[system_message]]:
try:
pdg_entry = PDGEntry.from_str(text)
link_text = create_link_text(pdg_entry, pattern=pattern)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_entry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from __future__ import annotations

import pytest

Expand Down Expand Up @@ -35,8 +35,8 @@ class TestPDGEntry:
def test_from_str(
self,
text: str,
expected: Optional[PDGEntry],
first_page: Optional[int],
expected: PDGEntry | None,
first_page: int | None,
):
if expected is None:
with pytest.raises(
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_from_str(
],
)
def test_get_page_numbers(
text: str, formatted_pages: Optional[str], first_page: Optional[int]
text: str, formatted_pages: str | None, first_page: int | None
):
assert get_page_numbers(text) == formatted_pages
if first_page is None:
Expand All @@ -93,5 +93,5 @@ def test_get_page_numbers(
("p. 12-15", None),
],
)
def test_get_year(text: str, expected: Optional[int]):
def test_get_year(text: str, expected: int | None):
assert get_year(text) == expected
Loading