chrisbase
Advanced tools
+1
-1
| Metadata-Version: 2.1 | ||
| Name: chrisbase | ||
| Version: 0.5.6 | ||
| Version: 0.5.7 | ||
| Summary: Base library for python coding | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/chrisjihee/chrisbase |
+1
-1
| [metadata] | ||
| name = chrisbase | ||
| version = 0.5.6 | ||
| version = 0.5.7 | ||
| author = Jihee Ryu | ||
@@ -5,0 +5,0 @@ author_email = chrisjihee@naver.com |
| Metadata-Version: 2.1 | ||
| Name: chrisbase | ||
| Version: 0.5.6 | ||
| Version: 0.5.7 | ||
| Summary: Base library for python coding | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/chrisjihee/chrisbase |
@@ -12,3 +12,3 @@ import json | ||
| from pathlib import Path | ||
| from typing import List, Optional, Mapping, Any, Iterable, Tuple | ||
| from typing import List, Optional, Mapping, Any, Iterable, Tuple, ClassVar | ||
@@ -26,3 +26,3 @@ import pandas as pd | ||
| from chrisbase.io import get_hostname, get_hostaddr, current_file, first_or, cwd, hr, flush_or, make_parent_dir, get_ip_addrs, setup_unit_logger, setup_dual_logger, open_file, file_lines, to_table_lines, new_path | ||
| from chrisbase.io import get_hostname, get_hostaddr, current_file, first_or, cwd, hr, flush_or, make_parent_dir, setup_unit_logger, setup_dual_logger, open_file, file_lines, to_table_lines, new_path, get_http_clients | ||
| from chrisbase.time import now, str_delta | ||
@@ -44,6 +44,6 @@ from chrisbase.util import tupled, SP, NO, to_dataframe | ||
| class TypedData(DataClassJsonMixin): | ||
| data_type = None | ||
| data_type: ClassVar[str] = None | ||
| def __post_init__(self): | ||
| self.data_type = self.__class__.__name__ | ||
| TypedData.data_type = self.__class__.__name__ | ||
@@ -510,3 +510,2 @@ | ||
| command_args: List[str] = field(init=False) | ||
| num_ip_addrs: int = field(init=False) | ||
| max_workers: int = field(default=1) | ||
@@ -522,2 +521,3 @@ calling_sec: float = field(default=0.001) | ||
| message_format: str = field(default=logging.BASIC_FORMAT) | ||
| http_clients = get_http_clients() | ||
@@ -534,3 +534,2 @@ def __post_init__(self): | ||
| self.command_args = sys.argv[1:] | ||
| self.ip_addrs, self.num_ip_addrs = get_ip_addrs() | ||
| self.logging_home = Path(self.logging_home).absolute() if self.logging_home else None | ||
@@ -574,4 +573,4 @@ self.logging_file = new_path(self.logging_file, post=self.time_stamp) if self.logging_file else None | ||
| class TimeChecker(ResultData): | ||
| t1 = datetime.now() | ||
| t2 = datetime.now() | ||
| t1: datetime = datetime.now() | ||
| t2: datetime = datetime.now() | ||
| started: str | None = field(default=None) | ||
@@ -578,0 +577,0 @@ settled: str | None = field(default=None) |
+40
-6
@@ -19,2 +19,3 @@ import bz2 | ||
| import httpx | ||
| import netifaces | ||
@@ -144,3 +145,3 @@ import pandas as pd | ||
| def current_file(known_path: Path or str = None): | ||
| def current_file(known_path: Path or str = None) -> Path: | ||
| if known_path and exists_or(Path(known_path)): | ||
@@ -378,2 +379,6 @@ return Path(known_path) | ||
| def key_lines(key, *args, **kwargs): | ||
| return [x for x in all_lines(*args, **kwargs) if key in x] | ||
| def new_path(path, post=None, pre=None, sep='-') -> Path: | ||
@@ -616,2 +621,3 @@ path = Path(path) | ||
| def yield_local_addrs(): | ||
@@ -626,7 +632,35 @@ for inf in netifaces.interfaces(): | ||
| def get_ip_addrs(): | ||
| local_addrs = list(yield_local_addrs()) | ||
| return local_addrs, len(local_addrs) | ||
| class HttpClients(Iterable[httpx.Client]): | ||
| http_clients = None | ||
| def __init__(self, ip_addrs: Iterable[str]): | ||
| self.http_clients = [ | ||
| httpx.Client( | ||
| transport=httpx.HTTPTransport(local_address=ip_addr), | ||
| timeout=httpx.Timeout(timeout=120.0), | ||
| ) for ip_addr in ip_addrs | ||
| ] | ||
| def __iter__(self): | ||
| return iter(self.http_clients) | ||
| def __len__(self): | ||
| return len(self.http_clients) | ||
| def __getitem__(self, ii): | ||
| return self.http_clients[ii % len(self)] | ||
| def get_local_addr(self, ii): | ||
| return self[ii]._transport._pool._local_address | ||
| def __del__(self): | ||
| if self.http_clients: | ||
| for http_client in self.http_clients: | ||
| http_client.close() | ||
| def get_http_clients(): | ||
| return HttpClients(yield_local_addrs()) | ||
| def prepend_to_global_path(*xs): | ||
@@ -648,3 +682,3 @@ os.environ['PATH'] = os.pathsep.join(map(str, xs)) + os.pathsep + os.environ['PATH'] | ||
| def setup_unit_logger(level=logging.INFO, force=True, | ||
| stream=sys_stdout, filename=None, filemode="a", existing_content=None, | ||
| stream=sys_stdout, filename: str | Path = None, filemode="a", existing_content=None, | ||
| fmt=logging.BASIC_FORMAT, datefmt="[%m.%d %H:%M:%S]"): | ||
@@ -658,3 +692,3 @@ formatter = logging.Formatter(fmt=fmt, datefmt=datefmt) | ||
| def setup_dual_logger(level=logging.INFO, force=True, | ||
| stream=sys_stdout, filename="running.log", filemode="a", existing_content=None, | ||
| stream=sys_stdout, filename: str | Path = "running.log", filemode="a", existing_content=None, | ||
| fmt=logging.BASIC_FORMAT, datefmt="[%m.%d %H:%M:%S]"): | ||
@@ -661,0 +695,0 @@ formatter = logging.Formatter(fmt=fmt, datefmt=datefmt) |
@@ -19,3 +19,3 @@ from __future__ import annotations | ||
| import pandas as pd | ||
| import tqdm.std as tqdm_std | ||
| import tqdm | ||
| from pydantic import BaseModel | ||
@@ -260,3 +260,3 @@ from sqlalchemy.util import OrderedSet | ||
| def __call__(self, *args, **kwargs): | ||
| def __call__(self, *args, **kwargs) -> tqdm.std.tqdm: | ||
| if 'desc' not in kwargs or not kwargs['desc']: | ||
@@ -268,10 +268,10 @@ kwargs['desc'] = 'processing' | ||
| kwargs.pop('bar_format', None) | ||
| return tqdm_std.tqdm(*args, bar_format=f"{{l_bar}}{{bar:{self.bar_size}}}{{r_bar}}", file=self.file, **kwargs) | ||
| return tqdm.std.tqdm(*args, bar_format=f"{{l_bar}}{{bar:{self.bar_size}}}{{r_bar}}", file=self.file, **kwargs) | ||
| def set_lock(self, *args, **kwargs): | ||
| self._lock = None | ||
| return tqdm_std.tqdm.set_lock(*args, **kwargs) | ||
| return tqdm.std.tqdm.set_lock(*args, **kwargs) | ||
| def get_lock(self): | ||
| return tqdm_std.tqdm.get_lock() | ||
| return tqdm.std.tqdm.get_lock() | ||
@@ -294,7 +294,7 @@ | ||
| logger.warning(f"{type(e)} on job[{i}]({job})") | ||
| if isinstance(jobs, tqdm_std.tqdm): | ||
| if isinstance(jobs, tqdm.std.tqdm): | ||
| if i > 0 and i % interval == 0: | ||
| logger.info(jobs) | ||
| if isinstance(jobs, tqdm_std.tqdm): | ||
| if isinstance(jobs, tqdm.std.tqdm): | ||
| logger.info(jobs) | ||
| terminate_processes(pool) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
70514
1.28%1522
1.47%