Compare commits
20 Commits
c974ce242c
...
84aea8d273
| Author | SHA1 | Date |
|---|---|---|
|
|
84aea8d273 | |
|
|
6ab4cffc8d | |
|
|
fbf7ac76cd | |
|
|
e015ad62e5 | |
|
|
03c9c4808b | |
|
|
8548eee0fd | |
|
|
bd4743e176 | |
|
|
973750b938 | |
|
|
3befe0940e | |
|
|
13c8e753d5 | |
|
|
f6d3415b53 | |
|
|
f34537aa70 | |
|
|
ac9228a101 | |
|
|
b5765d8221 | |
|
|
3ef6bc769a | |
|
|
bfc6caf2e7 | |
|
|
2e0ba81f98 | |
|
|
7ccd7aa227 | |
|
|
6d16c6347f | |
|
|
f8b24082b9 |
20
flake.nix
20
flake.nix
|
|
@ -2,7 +2,7 @@
|
||||||
# https://pyproject-nix.github.io/pyproject.nix/templates.html#impure
|
# https://pyproject-nix.github.io/pyproject.nix/templates.html#impure
|
||||||
# https://github.com/pyproject-nix/pyproject.nix/blob/master/templates/impure/flake.nix
|
# https://github.com/pyproject-nix/pyproject.nix/blob/master/templates/impure/flake.nix
|
||||||
{
|
{
|
||||||
description = "An impure overlay (w dev-shell) using `uv`";
|
description = "An impure overlay using `uv` with Nix(OS)";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
|
|
@ -29,17 +29,17 @@
|
||||||
{
|
{
|
||||||
default = pkgs.mkShell {
|
default = pkgs.mkShell {
|
||||||
|
|
||||||
packages = [
|
packages = with pkgs; [
|
||||||
# XXX, ensure sh completions activate!
|
# XXX, ensure sh completions activate!
|
||||||
pkgs.bashInteractive
|
bashInteractive
|
||||||
pkgs.bash-completion
|
bash-completion
|
||||||
|
|
||||||
# XXX, on nix(os), use pkgs version to avoid
|
# on nixos, use pkg(s)
|
||||||
# build/sys-sh-integration issues
|
ruff
|
||||||
pkgs.ruff
|
pypkgs.ruff
|
||||||
|
|
||||||
pkgs.uv
|
uv
|
||||||
pkgs.${cpython}# ?TODO^ how to set from `cpython` above?
|
python313 # ?TODO^ how to set from `cpython` above?
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
|
@ -56,7 +56,7 @@
|
||||||
# - always use the ./py313/ venv-subdir
|
# - always use the ./py313/ venv-subdir
|
||||||
# - sync env with all extras
|
# - sync env with all extras
|
||||||
export UV_PROJECT_ENVIRONMENT=${venv_dir}
|
export UV_PROJECT_ENVIRONMENT=${venv_dir}
|
||||||
uv sync --dev --all-extras
|
uv sync --dev --all-extras --no-group lint
|
||||||
|
|
||||||
# ------ TIPS ------
|
# ------ TIPS ------
|
||||||
# NOTE, to launch the py-venv installed `xonsh` (like @goodboy)
|
# NOTE, to launch the py-venv installed `xonsh` (like @goodboy)
|
||||||
|
|
|
||||||
|
|
@ -1020,9 +1020,6 @@ def test_peer_spawns_and_cancels_service_subactor(
|
||||||
raise_client_error: str,
|
raise_client_error: str,
|
||||||
reg_addr: tuple[str, int],
|
reg_addr: tuple[str, int],
|
||||||
raise_sub_spawn_error_after: float|None,
|
raise_sub_spawn_error_after: float|None,
|
||||||
loglevel: str,
|
|
||||||
# ^XXX, set to 'warning' to see masked-exc warnings
|
|
||||||
# that may transpire during actor-nursery teardown.
|
|
||||||
):
|
):
|
||||||
# NOTE: this tests for the modden `mod wks open piker` bug
|
# NOTE: this tests for the modden `mod wks open piker` bug
|
||||||
# discovered as part of implementing workspace ctx
|
# discovered as part of implementing workspace ctx
|
||||||
|
|
@ -1052,7 +1049,6 @@ def test_peer_spawns_and_cancels_service_subactor(
|
||||||
# NOTE: to halt the peer tasks on ctxc, uncomment this.
|
# NOTE: to halt the peer tasks on ctxc, uncomment this.
|
||||||
debug_mode=debug_mode,
|
debug_mode=debug_mode,
|
||||||
registry_addrs=[reg_addr],
|
registry_addrs=[reg_addr],
|
||||||
loglevel=loglevel,
|
|
||||||
) as an:
|
) as an:
|
||||||
server: Portal = await an.start_actor(
|
server: Portal = await an.start_actor(
|
||||||
(server_name := 'spawn_server'),
|
(server_name := 'spawn_server'),
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,10 @@
|
||||||
'''
|
'''
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
from types import ModuleType
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import tractor
|
import tractor
|
||||||
from tractor import (
|
from tractor import _code_load
|
||||||
_code_load,
|
|
||||||
log,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_root_pkg_not_duplicated_in_logger_name():
|
def test_root_pkg_not_duplicated_in_logger_name():
|
||||||
|
|
@ -24,15 +20,12 @@ def test_root_pkg_not_duplicated_in_logger_name():
|
||||||
project_name: str = 'pylib'
|
project_name: str = 'pylib'
|
||||||
pkg_path: str = 'pylib.subpkg.mod'
|
pkg_path: str = 'pylib.subpkg.mod'
|
||||||
|
|
||||||
assert not tractor.current_actor(
|
proj_log = tractor.log.get_logger(
|
||||||
err_on_no_runtime=False,
|
|
||||||
)
|
|
||||||
proj_log = log.get_logger(
|
|
||||||
pkg_name=project_name,
|
pkg_name=project_name,
|
||||||
mk_sublog=False,
|
mk_sublog=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
sublog = log.get_logger(
|
sublog = tractor.log.get_logger(
|
||||||
pkg_name=project_name,
|
pkg_name=project_name,
|
||||||
name=pkg_path,
|
name=pkg_path,
|
||||||
)
|
)
|
||||||
|
|
@ -58,86 +51,56 @@ def test_implicit_mod_name_applied_for_child(
|
||||||
mod_code: str = (
|
mod_code: str = (
|
||||||
f'import tractor\n'
|
f'import tractor\n'
|
||||||
f'\n'
|
f'\n'
|
||||||
# if you need to trace `testdir` stuff @ import-time..
|
|
||||||
# f'breakpoint()\n'
|
|
||||||
f'log = tractor.log.get_logger(pkg_name="{proj_name}")\n'
|
f'log = tractor.log.get_logger(pkg_name="{proj_name}")\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
# create a sub-module for each pkg layer
|
# create a sub-module for each pkg layer
|
||||||
_lib = testdir.mkpydir(proj_name)
|
_lib = testdir.mkpydir(proj_name)
|
||||||
pkg: Path = Path(_lib)
|
pkg: Path = Path(_lib)
|
||||||
pkg_init_mod: Path = pkg / "__init__.py"
|
|
||||||
pkg_init_mod.write_text(mod_code)
|
|
||||||
|
|
||||||
subpkg: Path = pkg / 'subpkg'
|
subpkg: Path = pkg / 'subpkg'
|
||||||
subpkg.mkdir()
|
subpkg.mkdir()
|
||||||
subpkgmod: Path = subpkg / "__init__.py"
|
|
||||||
subpkgmod.touch()
|
pkgmod: Path = subpkg / "__init__.py"
|
||||||
subpkgmod.write_text(mod_code)
|
pkgmod.touch()
|
||||||
|
|
||||||
_submod: Path = testdir.makepyfile(
|
_submod: Path = testdir.makepyfile(
|
||||||
_mod=mod_code,
|
_mod=mod_code,
|
||||||
)
|
)
|
||||||
|
|
||||||
pkg_submod = pkg / 'mod.py'
|
pkg_mod = pkg / 'mod.py'
|
||||||
pkg_subpkg_submod = subpkg / 'submod.py'
|
pkg_subpkg_submod = subpkg / 'submod.py'
|
||||||
shutil.copyfile(
|
shutil.copyfile(
|
||||||
_submod,
|
_submod,
|
||||||
pkg_submod,
|
pkg_mod,
|
||||||
)
|
)
|
||||||
shutil.copyfile(
|
shutil.copyfile(
|
||||||
_submod,
|
_submod,
|
||||||
pkg_subpkg_submod,
|
pkg_subpkg_submod,
|
||||||
)
|
)
|
||||||
testdir.chdir()
|
testdir.chdir()
|
||||||
# NOTE, to introspect the py-file-module-layout use (in .xsh
|
|
||||||
# syntax): `ranger @str(testdir)`
|
|
||||||
|
|
||||||
# XXX NOTE, once the "top level" pkg mod has been
|
# XXX NOTE, once the "top level" pkg mod has been
|
||||||
# imported, we can then use `import` syntax to
|
# imported, we can then use `import` syntax to
|
||||||
# import it's sub-pkgs and modules.
|
# import it's sub-pkgs and modules.
|
||||||
subpkgmod: ModuleType = _code_load.load_module_from_path(
|
pkgmod = _code_load.load_module_from_path(
|
||||||
Path(pkg / '__init__.py'),
|
Path(pkg / '__init__.py'),
|
||||||
module_name=proj_name,
|
module_name=proj_name,
|
||||||
)
|
)
|
||||||
|
pkg_root_log = tractor.log.get_logger(
|
||||||
pkg_root_log = log.get_logger(
|
|
||||||
pkg_name=proj_name,
|
pkg_name=proj_name,
|
||||||
mk_sublog=False,
|
mk_sublog=False,
|
||||||
)
|
)
|
||||||
# the top level pkg-mod, created just now,
|
|
||||||
# by above API call.
|
|
||||||
assert pkg_root_log.name == proj_name
|
assert pkg_root_log.name == proj_name
|
||||||
assert not pkg_root_log.logger.getChildren()
|
assert not pkg_root_log.logger.getChildren()
|
||||||
#
|
|
||||||
# ^TODO! test this same output but created via a `get_logger()`
|
|
||||||
# call in the `snakelib.__init__py`!!
|
|
||||||
|
|
||||||
# NOTE, the pkg-level "init mod" should of course
|
|
||||||
# have the same name as the package ns-path.
|
|
||||||
import snakelib as init_mod
|
|
||||||
assert init_mod.log.name == proj_name
|
|
||||||
|
|
||||||
# NOTE, a first-pkg-level sub-module should only
|
|
||||||
# use the package-name since the leaf-node-module
|
|
||||||
# will be included in log headers by default.
|
|
||||||
from snakelib import mod
|
from snakelib import mod
|
||||||
assert mod.log.name == proj_name
|
assert mod.log.name == proj_name
|
||||||
|
|
||||||
from snakelib import subpkg
|
|
||||||
assert (
|
|
||||||
subpkg.log.name
|
|
||||||
==
|
|
||||||
subpkg.__package__
|
|
||||||
==
|
|
||||||
f'{proj_name}.subpkg'
|
|
||||||
)
|
|
||||||
|
|
||||||
from snakelib.subpkg import submod
|
from snakelib.subpkg import submod
|
||||||
assert (
|
assert (
|
||||||
submod.log.name
|
submod.log.name
|
||||||
==
|
==
|
||||||
submod.__package__
|
submod.__package__ # ?TODO, use this in `.get_logger()` instead?
|
||||||
==
|
==
|
||||||
f'{proj_name}.subpkg'
|
f'{proj_name}.subpkg'
|
||||||
)
|
)
|
||||||
|
|
@ -146,6 +109,8 @@ def test_implicit_mod_name_applied_for_child(
|
||||||
assert len(sub_logs) == 1 # only one nested sub-pkg module
|
assert len(sub_logs) == 1 # only one nested sub-pkg module
|
||||||
assert submod.log.logger in sub_logs
|
assert submod.log.logger in sub_logs
|
||||||
|
|
||||||
|
# breakpoint()
|
||||||
|
|
||||||
|
|
||||||
# TODO, moar tests against existing feats:
|
# TODO, moar tests against existing feats:
|
||||||
# ------ - ------
|
# ------ - ------
|
||||||
|
|
|
||||||
|
|
@ -897,9 +897,9 @@ async def _invoke(
|
||||||
)
|
)
|
||||||
|
|
||||||
logmeth(
|
logmeth(
|
||||||
f'{message}'
|
f'{message}\n'
|
||||||
f'\n'
|
f'\n'
|
||||||
f'{descr_str}'
|
f'{descr_str}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -459,23 +459,21 @@ class MsgpackTransport(MsgTransport):
|
||||||
)
|
)
|
||||||
raise tpt_closed from trans_err
|
raise tpt_closed from trans_err
|
||||||
|
|
||||||
# ??TODO??, what case in piker does this and HOW
|
# case trio.ClosedResourceError() if (
|
||||||
# CAN WE RE-PRODUCE IT?!?!?
|
# 'this socket was already closed'
|
||||||
case trio.ClosedResourceError() if (
|
# in
|
||||||
'this socket was already closed'
|
# trans_err.args[0]
|
||||||
in
|
# ):
|
||||||
trans_err.args[0]
|
# tpt_closed = TransportClosed.from_src_exc(
|
||||||
):
|
# message=(
|
||||||
tpt_closed = TransportClosed.from_src_exc(
|
# f'{tpt_name} already closed by peer\n'
|
||||||
message=(
|
# ),
|
||||||
f'{tpt_name} already closed by peer\n'
|
# body=f'{self}\n',
|
||||||
),
|
# src_exc=trans_err,
|
||||||
body=f'{self}\n',
|
# raise_on_report=True,
|
||||||
src_exc=trans_err,
|
# loglevel='transport',
|
||||||
raise_on_report=True,
|
# )
|
||||||
loglevel='transport',
|
# raise tpt_closed from trans_err
|
||||||
)
|
|
||||||
raise tpt_closed from trans_err
|
|
||||||
|
|
||||||
# unless the disconnect condition falls under "a
|
# unless the disconnect condition falls under "a
|
||||||
# normal operation breakage" we usualy console warn
|
# normal operation breakage" we usualy console warn
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ class UDSAddress(
|
||||||
# ?^TODO, for `multiaddr`'s parser we can't use the `::`
|
# ?^TODO, for `multiaddr`'s parser we can't use the `::`
|
||||||
# above^, SO maybe a `.` or something else here?
|
# above^, SO maybe a `.` or something else here?
|
||||||
# sockname: str = '.'.join(actor.uid) + f'@{pid}'
|
# sockname: str = '.'.join(actor.uid) + f'@{pid}'
|
||||||
# -[ ] CURRENTLY using `.` BREAKS TEST SUITE tho..
|
# -[ ] CURRETLY using `.` BREAKS TEST SUITE tho..
|
||||||
else:
|
else:
|
||||||
prefix: str = '<unknown-actor>'
|
prefix: str = '<unknown-actor>'
|
||||||
if is_root_process():
|
if is_root_process():
|
||||||
|
|
|
||||||
|
|
@ -42,9 +42,6 @@ from types import ModuleType
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import colorlog # type: ignore
|
import colorlog # type: ignore
|
||||||
# ?TODO, some other (modern) alt libs?
|
|
||||||
# import coloredlogs
|
|
||||||
# import colored_traceback.auto # ?TODO, need better config?
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
from ._state import current_actor
|
from ._state import current_actor
|
||||||
|
|
@ -416,6 +413,9 @@ def get_logger(
|
||||||
|
|
||||||
mod_ns_path: str = caller_mod.__name__
|
mod_ns_path: str = caller_mod.__name__
|
||||||
mod_pkg_ns_path: str = caller_mod.__package__
|
mod_pkg_ns_path: str = caller_mod.__package__
|
||||||
|
# if 'snakelib' in mod_pkg_ns_path:
|
||||||
|
# import pdbp
|
||||||
|
# breakpoint()
|
||||||
if (
|
if (
|
||||||
mod_pkg_ns_path in mod_ns_path
|
mod_pkg_ns_path in mod_ns_path
|
||||||
or
|
or
|
||||||
|
|
@ -488,6 +488,10 @@ def get_logger(
|
||||||
proper_name: str = name.removeprefix(
|
proper_name: str = name.removeprefix(
|
||||||
f'{pkg_name}.'
|
f'{pkg_name}.'
|
||||||
)
|
)
|
||||||
|
# if 'pylib' in name:
|
||||||
|
# import pdbp
|
||||||
|
# breakpoint()
|
||||||
|
|
||||||
msg: str = (
|
msg: str = (
|
||||||
f'@ {get_caller_mod()}\n'
|
f'@ {get_caller_mod()}\n'
|
||||||
f'Duplicate pkg-name in sub-logger `name`-key?\n'
|
f'Duplicate pkg-name in sub-logger `name`-key?\n'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue