general: migrate modules to use 3.9 features
This commit is contained in:
parent
d3f9a8e8b6
commit
8496d131e7
125 changed files with 889 additions and 739 deletions
|
@ -3,8 +3,7 @@ Unified Github data (merged from GDPR export and periodic API updates)
|
|||
"""
|
||||
|
||||
from . import gdpr, ghexport
|
||||
|
||||
from .common import merge_events, Results
|
||||
from .common import Results, merge_events
|
||||
|
||||
|
||||
def events() -> Results:
|
||||
|
|
|
@ -1,24 +1,27 @@
|
|||
"""
|
||||
Github events and their metadata: comments/issues/pull requests
|
||||
"""
|
||||
from ..core import __NOT_HPI_MODULE__
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from my.core import __NOT_HPI_MODULE__ # isort: skip
|
||||
|
||||
|
||||
from collections.abc import Iterable
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional, NamedTuple, Iterable, Set, Tuple
|
||||
from typing import NamedTuple, Optional
|
||||
|
||||
from ..core import warn_if_empty, LazyLogger
|
||||
from ..core.error import Res
|
||||
from my.core import make_logger, warn_if_empty
|
||||
from my.core.error import Res
|
||||
|
||||
|
||||
logger = LazyLogger(__name__)
|
||||
logger = make_logger(__name__)
|
||||
|
||||
class Event(NamedTuple):
|
||||
dt: datetime
|
||||
summary: str
|
||||
eid: str
|
||||
link: Optional[str]
|
||||
body: Optional[str]=None
|
||||
body: Optional[str] = None
|
||||
is_bot: bool = False
|
||||
|
||||
|
||||
|
@ -27,7 +30,7 @@ Results = Iterable[Res[Event]]
|
|||
@warn_if_empty
|
||||
def merge_events(*sources: Results) -> Results:
|
||||
from itertools import chain
|
||||
emitted: Set[Tuple[datetime, str]] = set()
|
||||
emitted: set[tuple[datetime, str]] = set()
|
||||
for e in chain(*sources):
|
||||
if isinstance(e, Exception):
|
||||
yield e
|
||||
|
@ -52,7 +55,7 @@ def parse_dt(s: str) -> datetime:
|
|||
# experimental way of supportint event ids... not sure
|
||||
class EventIds:
|
||||
@staticmethod
|
||||
def repo_created(*, dts: str, name: str, ref_type: str, ref: Optional[str]) -> str:
|
||||
def repo_created(*, dts: str, name: str, ref_type: str, ref: str | None) -> str:
|
||||
return f'{dts}_repocreated_{name}_{ref_type}_{ref}'
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -6,8 +6,9 @@ from __future__ import annotations
|
|||
|
||||
import json
|
||||
from abc import abstractmethod
|
||||
from collections.abc import Iterator, Sequence
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterator, Sequence
|
||||
from typing import Any
|
||||
|
||||
from my.core import Paths, Res, Stats, get_files, make_logger, stat, warnings
|
||||
from my.core.error import echain
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
"""
|
||||
Github data: events, comments, etc. (API data)
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
REQUIRES = [
|
||||
'git+https://github.com/karlicoss/ghexport',
|
||||
]
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from my.core import Paths
|
||||
from my.config import github as user_config
|
||||
from my.core import Paths
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -21,7 +25,9 @@ class github(user_config):
|
|||
|
||||
###
|
||||
|
||||
from my.core.cfg import make_config, Attrs
|
||||
from my.core.cfg import Attrs, make_config
|
||||
|
||||
|
||||
def migration(attrs: Attrs) -> Attrs:
|
||||
export_dir = 'export_dir'
|
||||
if export_dir in attrs: # legacy name
|
||||
|
@ -41,15 +47,14 @@ except ModuleNotFoundError as e:
|
|||
|
||||
############################
|
||||
|
||||
from collections.abc import Sequence
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import Tuple, Dict, Sequence, Optional
|
||||
|
||||
from my.core import get_files, LazyLogger
|
||||
from my.core import LazyLogger, get_files
|
||||
from my.core.cachew import mcachew
|
||||
|
||||
from .common import Event, parse_dt, Results, EventIds
|
||||
|
||||
from .common import Event, EventIds, Results, parse_dt
|
||||
|
||||
logger = LazyLogger(__name__)
|
||||
|
||||
|
@ -82,7 +87,9 @@ def _events() -> Results:
|
|||
yield e
|
||||
|
||||
|
||||
from my.core import stat, Stats
|
||||
from my.core import Stats, stat
|
||||
|
||||
|
||||
def stats() -> Stats:
|
||||
return {
|
||||
**stat(events),
|
||||
|
@ -99,7 +106,7 @@ def _log_if_unhandled(e) -> None:
|
|||
Link = str
|
||||
EventId = str
|
||||
Body = str
|
||||
def _get_summary(e) -> Tuple[str, Optional[Link], Optional[EventId], Optional[Body]]:
|
||||
def _get_summary(e) -> tuple[str, Link | None, EventId | None, Body | None]:
|
||||
# TODO would be nice to give access to raw event within timeline
|
||||
dts = e['created_at']
|
||||
eid = e['id']
|
||||
|
@ -195,7 +202,7 @@ def _get_summary(e) -> Tuple[str, Optional[Link], Optional[EventId], Optional[Bo
|
|||
return tp, None, None, None
|
||||
|
||||
|
||||
def _parse_event(d: Dict) -> Event:
|
||||
def _parse_event(d: dict) -> Event:
|
||||
summary, link, eid, body = _get_summary(d)
|
||||
if eid is None:
|
||||
eid = d['id'] # meh
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue