Skip to content

Commit

Permalink
Expose show path option to command argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
YooSunYoung committed Dec 16, 2024
1 parent 1385eb6 commit bf567ef
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
cachetools==5.5.0
# via tox
certifi==2024.8.30
certifi==2024.12.14
# via requests
chardet==5.2.0
# via tox
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pydantic==2.10.3
# via copier
pydantic-core==2.27.1
# via pydantic
python-json-logger==3.2.0
python-json-logger==3.2.1
# via jupyter-events
questionary==1.10.0
# via copier
Expand Down
1 change: 1 addition & 0 deletions requirements/docs.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ sphinx
sphinx-autodoc-typehints
sphinx-copybutton
sphinx-design
rich
13 changes: 9 additions & 4 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:2175813590b5d31dc1cdf3e3c820f699647e9043
# SHA1:ad5367aa9314d3fcada2550ed872890326403fe2
#
# This file is autogenerated by pip-compile-multi
# To update, run:
Expand All @@ -14,7 +14,7 @@ appnope==0.1.4
# via ipykernel
asttokens==3.0.0
# via stack-data
attrs==24.2.0
attrs==24.3.0
# via
# jsonschema
# referencing
Expand All @@ -28,13 +28,13 @@ beautifulsoup4==4.12.3
# pydata-sphinx-theme
bleach==6.2.0
# via nbconvert
certifi==2024.8.30
certifi==2024.12.14
# via requests
charset-normalizer==3.4.0
# via requests
comm==0.2.2
# via ipykernel
debugpy==1.8.9
debugpy==1.8.11
# via ipykernel
decorator==5.1.1
# via ipython
Expand Down Expand Up @@ -91,6 +91,7 @@ markdown-it-py==3.0.0
# via
# mdit-py-plugins
# myst-parser
# rich
markupsafe==3.0.2
# via
# jinja2
Expand Down Expand Up @@ -149,6 +150,7 @@ pygments==2.18.0
# ipython
# nbconvert
# pydata-sphinx-theme
# rich
# sphinx
python-dateutil==2.9.0.post0
# via jupyter-client
Expand All @@ -164,6 +166,8 @@ referencing==0.35.1
# jsonschema-specifications
requests==2.32.3
# via sphinx
rich==13.9.4
# via -r docs.in
rpds-py==0.22.3
# via
# jsonschema
Expand Down Expand Up @@ -227,6 +231,7 @@ typing-extensions==4.12.2
# via
# ipython
# pydata-sphinx-theme
# rich
urllib3==2.2.3
# via requests
wcwidth==0.2.13
Expand Down
5 changes: 4 additions & 1 deletion requirements/make_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def as_nightly(repo: str) -> str:
"--extra-index-url=https://pypi.org/simple\n"
"--pre"
)
return f"{repo} @ git+https://github.com/{org}/{repo}@main"
if org == 'Textualize' and repo == 'rich':
return f"{repo} @ git+https://github.com/{org}/{repo}@master"
else:
return f"{repo} @ git+https://github.com/{org}/{repo}@main"


nightly = tuple(args.nightly.split(",") if args.nightly else [])
Expand Down
1 change: 1 addition & 0 deletions requirements/nightly.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY!
pytest
rich
rich @ git+https://github.com/Textualize/rich@master
4 changes: 2 additions & 2 deletions requirements/nightly.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SHA1:21abe2b0c1ccc7e1bf1e32124611780befe7c0d8
# SHA1:c46f90eedbb75ef00fdfcff3f08b4d64a1664ff1
#
# This file is autogenerated by pip-compile-multi
# To update, run:
Expand All @@ -21,7 +21,7 @@ pygments==2.18.0
# via rich
pytest==8.3.4
# via -r nightly.in
rich==13.9.4
rich @ git+https://github.com/Textualize/rich@master
# via -r nightly.in
tomli==2.2.1
# via pytest
Expand Down
8 changes: 7 additions & 1 deletion src/appstract/logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from logging import FileHandler
from typing import NewType

from rich.logging import RichHandler

Expand Down Expand Up @@ -32,10 +33,15 @@ def provide_appstract_filehandler(
class AppCrafterStreamHandler(RichHandler): ...


ShowPath = NewType("ShowPath", bool)
DEFAULT_SHOW_PATH = ShowPath(True)


@_handler_providers.provider
def provide_appstract_streamhandler(
highlighter: AppCrafterStreamHighlighter,
show_path: ShowPath = DEFAULT_SHOW_PATH,
) -> AppCrafterStreamHandler:
"""Returns a ``RichHandler`` with :py:class:``AppCrafterStreamHighlighter``."""

return AppCrafterStreamHandler(highlighter=highlighter)
return AppCrafterStreamHandler(highlighter=highlighter, show_path=show_path)
14 changes: 12 additions & 2 deletions src/appstract/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
SyncApplication,
)
from .logging import AppLogger
from .logging.handlers import ShowPath
from .logging.providers import log_providers
from .mixins import LogMixin

Expand All @@ -42,6 +43,9 @@ def build_arg_parser(*sub_group_classes: type) -> argparse.ArgumentParser:
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
default="INFO",
)
parser.add_argument(
'--no-path', help='Do not show path in log messages.', action='store_true'
)
for sub_group_class in sub_group_classes:
if callable(add_arg := getattr(sub_group_class, "add_argument_group", None)):
add_arg(parser)
Expand Down Expand Up @@ -109,7 +113,10 @@ def sync_shout(self) -> Generator[EventMessageProtocol, None, None]:

def run_async_helloworld():
arg_name_space: argparse.Namespace = build_arg_parser().parse_args()
parameters = {argparse.Namespace: arg_name_space}
parameters = {
argparse.Namespace: arg_name_space,
ShowPath: not arg_name_space.no_path,
}

factory = Factory(
log_providers,
Expand Down Expand Up @@ -137,7 +144,10 @@ def run_async_helloworld():

def run_sync_helloworld():
arg_name_space: argparse.Namespace = build_arg_parser().parse_args()
parameters = {argparse.Namespace: arg_name_space}
parameters = {
argparse.Namespace: arg_name_space,
ShowPath: not arg_name_space.no_path,
}

factory = Factory(
log_providers,
Expand Down

0 comments on commit bf567ef

Please sign in to comment.