Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6291d178d4 | |||
| 87a46fcf28 | |||
| df16f90a8f | |||
| 25aecabd34 |
@@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
__version__ = "1.0.18"
|
__version__ = "1.0.19"
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from typing import Callable
|
from typing import Callable
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import datetime
|
||||||
|
import shlex
|
||||||
|
from pathlib import Path
|
||||||
|
from subprocess import check_output
|
||||||
|
from typing import NamedTuple
|
||||||
|
|
||||||
|
import dateutil
|
||||||
|
|
||||||
|
|
||||||
|
class ExtractedCommit(NamedTuple):
|
||||||
|
sha: str
|
||||||
|
author: str
|
||||||
|
email: str
|
||||||
|
time: str
|
||||||
|
message: str
|
||||||
|
file_names: list[str]
|
||||||
|
|
||||||
|
def get_time(self) -> datetime:
|
||||||
|
return dateutil.parser.isoparse(self.time)
|
||||||
|
|
||||||
|
|
||||||
|
def git_log(path: Path, fail_silently: False) -> list[ExtractedCommit]:
|
||||||
|
"""
|
||||||
|
Call and parse git log. This function requires that git>=2.37.1 is installed on your system.
|
||||||
|
|
||||||
|
:param path: Path of git repository
|
||||||
|
:param fail_silently: If true, ignore errors. If false, raise exception when errors occur.
|
||||||
|
:return: List of commits
|
||||||
|
"""
|
||||||
|
# check_call(shlex.split('git config diff.renames 0'))
|
||||||
|
cmd = f"git -c 'diff.renamelimit=0' -c 'diff.renames=0' -C '{path.absolute()}' log --name-status --diff-filter=AMD --pretty=format:'START_COMMIT_QwQ %H%n%aN%n%aE%n%aI%n%s%n'"
|
||||||
|
log = check_output(shlex.split(cmd)).decode('utf-8', 'ignore')
|
||||||
|
|
||||||
|
def extract_commit(block: str) -> ExtractedCommit:
|
||||||
|
try:
|
||||||
|
lines = block.split('\n')
|
||||||
|
sha, author, email, date, message = lines + [""] if len(lines) == 4 else lines[:5]
|
||||||
|
files = [f.replace('\t', '/') for f in lines[6:]]
|
||||||
|
return ExtractedCommit(sha, author, email, date, message, files)
|
||||||
|
except Exception as e:
|
||||||
|
print(f'========== Commit Extract Error {e} ==========\n{block}\n==========')
|
||||||
|
if not fail_silently:
|
||||||
|
raise e
|
||||||
|
|
||||||
|
return [extract_commit(c.strip()) for c in log.split('START_COMMIT_QwQ') if c]
|
||||||
@@ -2,7 +2,7 @@ import requests
|
|||||||
|
|
||||||
|
|
||||||
def setup_proxy(session: requests.Session, addr: str = 'socks5://localhost:9050', verbose: bool = True):
|
def setup_proxy(session: requests.Session, addr: str = 'socks5://localhost:9050', verbose: bool = True):
|
||||||
url = 'https://ifconfig.me/ip'
|
url = 'https://ip.me'
|
||||||
|
|
||||||
# Setup proxy
|
# Setup proxy
|
||||||
ip = session.get(url).text.strip()
|
ip = session.get(url).text.strip()
|
||||||
|
|||||||
@@ -119,8 +119,16 @@ def json_stringify(obj: object, forced: bool = True, **kwargs) -> str:
|
|||||||
return json.dumps(obj, **args)
|
return json.dumps(obj, **args)
|
||||||
|
|
||||||
|
|
||||||
def jsn(s: str) -> SimpleNamespace:
|
class SafeNamespace(SimpleNamespace):
|
||||||
return json.loads(s, object_hook=lambda d: SimpleNamespace(**d))
|
def __getattr__(self, attr):
|
||||||
|
try:
|
||||||
|
return super().__getattr__(attr)
|
||||||
|
except AttributeError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def jsn(s: str) -> SafeNamespace:
|
||||||
|
return json.loads(s, object_hook=lambda d: SafeNamespace(**d))
|
||||||
|
|
||||||
|
|
||||||
def ensure_dir(path: Path | str) -> Path:
|
def ensure_dir(path: Path | str) -> Path:
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ setup(
|
|||||||
"Programming Language :: Python :: 3.8",
|
"Programming Language :: Python :: 3.8",
|
||||||
"Programming Language :: Python :: 3.9",
|
"Programming Language :: Python :: 3.9",
|
||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3.11",
|
||||||
],
|
],
|
||||||
packages=find_packages(exclude=("tests",)),
|
packages=find_packages(exclude=("tests",)),
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user