Skip to content

Commit

Permalink
MAINT: drop Python 3.8 support due to EOL (#227)
Browse files Browse the repository at this point in the history
* MAINT: ignore links to PRD
* MAINT: modernize Python syntax to Python 3.9
* MAINT: remove redundant `linkcheck_ignore` item
  • Loading branch information
redeboer authored Oct 11, 2024
1 parent 7f8e1e7 commit ea1f521
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 245 deletions.
223 changes: 0 additions & 223 deletions .constraints/py3.8.txt

This file was deleted.

3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
api_github_repo = f"{ORGANIZATION}/{REPO_NAME}"
api_target_substitutions: dict[str, str | tuple[str, str]] = {
"datetime": "datetime.datetime",
"Path": "pathlib.Path",
}
author = "Common Partial Wave Analysis"
autodoc_default_options = {
Expand Down Expand Up @@ -126,10 +127,10 @@
}
linkcheck_anchors = False
linkcheck_ignore = [
"http://127.0.0.1:8000",
"http://cgl.soic.indiana.edu/jpac/References.html",
"https://doi.org/10.1002/andp.19955070504", # 403 for onlinelibrary.wiley.com
"https://doi.org/10.1093/ptep/ptaa104",
"https://doi.org/10.1103",
"https://doi.org/10.1155/2020/6674595", # 403 hidawi.com
"https://home.fnal.gov/~kutschke/Angdist/angdist.ps",
"https://physique.cuso.ch",
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python",
"Topic :: Scientific/Engineering :: Physics",
Expand Down Expand Up @@ -48,7 +47,7 @@ keywords = [
license = {file = "LICENSE"}
maintainers = [{email = "[email protected]"}]
name = "PWA-pages"
requires-python = ">=3.8"
requires-python = ">=3.9"

[project.optional-dependencies]
dev = [
Expand Down
41 changes: 22 additions & 19 deletions src/pwa_pages/project_inventory.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
"""Helper tools for writing tables."""

from __future__ import annotations

import argparse
import json
import re
import sys
from datetime import datetime
from functools import partial
from pathlib import Path
from typing import Callable, Dict, Iterable, List, Optional, Sequence, Union
from typing import TYPE_CHECKING, Callable, Optional, Union

import yaml
from pydantic import BaseModel, model_validator
from pytablewriter import HtmlTableWriter

from .repo import Repo, get_repo

if TYPE_CHECKING:
from collections.abc import Iterable, Sequence
from datetime import datetime
from pathlib import Path

if sys.version_info < (3, 11):
from typing_extensions import Self
else:
from typing import Self


def load_yaml(path: Union[Path, str]) -> dict:
def load_yaml(path: Path | str) -> dict:
with open(path) as stream:
return yaml.load(stream, Loader=yaml.SafeLoader)


def to_html_table(
inventory: "ProjectInventory",
selected_languages: List[str],
inventory: ProjectInventory,
selected_languages: list[str],
*,
fetch: bool = False,
min_percentage: float = 2.5,
hide_columns: Optional[Iterable[str]] = None,
hide_columns: Iterable[str] | None = None,
) -> str:
header_to_formatters: Dict[str, Callable[[Project], str]] = {
header_to_formatters: dict[str, Callable[[Project], str]] = {
"Project": _create_project_entry,
"Collaboration": partial(_format_collaboration, inventory=inventory),
"Since": _fetch_first_commit_year if fetch else lambda _: "",
Expand Down Expand Up @@ -85,15 +90,15 @@ class SubProject(BaseModel):
class Project(BaseModel):
name: str
url: str
collaboration: Optional[Union[List[str], str]] = None
languages: List[str] = []
sub_projects: Optional[List[SubProject]] = None
collaboration: Optional[Union[list[str], str]] = None
languages: list[str] = []
sub_projects: Optional[list[SubProject]] = None
since: int = 0


class ProjectInventory(BaseModel):
projects: List[Project]
collaborations: Dict[str, str] = {}
projects: list[Project]
collaborations: dict[str, str] = {}

@model_validator(mode="after")
def _check_collaboration_exists(self) -> Self:
Expand Down Expand Up @@ -154,9 +159,7 @@ def __replace_language(language: str) -> str:
return language


def _fetch_languages(
project: Union[Project, SubProject], min_percentage: float
) -> List[str]:
def _fetch_languages(project: Project | SubProject, min_percentage: float) -> list[str]:
repo = get_repo(project.url)
if repo is None:
return []
Expand Down Expand Up @@ -203,7 +206,7 @@ def _get_date(

def _get_subproject_timestamps(
project: Project, date_getter: Callable[[Repo], datetime]
) -> List[datetime]:
) -> list[datetime]:
if project.sub_projects is None:
return []
timestamps = []
Expand All @@ -216,7 +219,7 @@ def _get_subproject_timestamps(
return timestamps


def _format_collaboration(project: Project, inventory: "ProjectInventory") -> str:
def _format_collaboration(project: Project, inventory: ProjectInventory) -> str:
collaborations = project.collaboration
if collaborations is None:
return ""
Expand Down Expand Up @@ -249,7 +252,7 @@ def _enumerate_html_links(list_of_entries: Sequence[str]) -> str:
return "<li>" + html


def export_json_schema(argv: Optional[Sequence[str]] = None) -> int:
def export_json_schema(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser(
"Create a JSON validation schema for a software project inventory file\n"
)
Expand Down

0 comments on commit ea1f521

Please sign in to comment.