Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Dev #6

Merged
merged 7 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: Install dependencies
run: |
poetry install --only main
poetry install --only main,test,extras

- name: Test with pytest
run: |
Expand Down
1 change: 1 addition & 0 deletions calmlib/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .main import *
from .read_write import *
from .whisper_utils import *
from .run_utils import *

# from .notion_utils import *
# from .telegram_utils import *
Expand Down
2 changes: 1 addition & 1 deletion calmlib/utils/langchain_utils/fewshot_prompt_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from textwrap import dedent

from calmlib.gpt_utils.langchain_fewshot_prompt_base import LangchainFewshotPromptBase
from calmlib.utils.langchain_utils.langchain_fewshot_prompt_base import LangchainFewshotPromptBase
from langchain_openai import ChatOpenAI


Expand Down
25 changes: 24 additions & 1 deletion calmlib/utils/logging_utils/logging_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import logging
from pathlib import Path

from typing_extensions import deprecated
from loguru import logger as loguru_logger

DEFAULT_LEVEL = logging.INFO
DEFAULT_SEP = " ~~ "
DEFAULT_FORMAT_COMPONENTS = ["%(asctime)-15s", "%(name)s", "%(levelname)s", "%(message)s"]

# Default log directory and file
DEFAULT_LOG_DIR = Path("~/.calmmage/logs").expanduser()
DEFAULT_LOG_FILE = "calmlib.log"
Expand Down Expand Up @@ -41,3 +46,21 @@ def get_logger(name=None, level="INFO", format=None, log_file=None):
if not is_logger_configured(logger):
configure_calmmage_logger(logger)
return logger


@deprecated("Use get_logger instead")
def get_personal_logger(name, level=None, sep=None, format_components=None):
level = level or DEFAULT_LEVEL
sep = sep or DEFAULT_SEP
format_components = format_components or DEFAULT_FORMAT_COMPONENTS
import logging

logger = logging.getLogger(name)
logger.setLevel(level)
if not logger.handlers:
handler = logging.StreamHandler()
formatter = logging.Formatter(fmt=sep.join(format_components))
handler.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(handler)
return logger
9 changes: 5 additions & 4 deletions dev/unsorted/2/execution.py → calmlib/utils/run_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 1) run external binary - basically any bash command
import threading
from subprocess import Popen, PIPE


def run_cmd(cmd, stdin=''):
# 1) run external binary - basically any bash command
def run_cmd(cmd, stdin=""):
"""
Execute any bash command. Return its output.
:param cmd:
Expand All @@ -19,9 +19,10 @@ def run_cmd(cmd, stdin=''):
return output.decode()


# 2) run python code - eval
# 3) run python function in backgroud - threading, subprocess etc.
# todo: 2) run python code - eval


# 3) run python function in backgroud - threading, subprocess etc.
def run_bg(func, *args, **kwargs):
"""
Execute any callable in a background thread
Expand Down
4 changes: 3 additions & 1 deletion dev/paused/setup/.bash_profile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

export PS1="\u: \w/$ "

# added by Miniconda3 4.7.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
Expand All @@ -15,4 +17,4 @@ else
fi
fi
unset __conda_setup
# <<< conda init <<<
# <<< conda init <<<
27 changes: 24 additions & 3 deletions dev/paused/setup/.bashrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,32 @@ esac

export PS1="\u: \w/$ "

#LS_COLORS='no=00;38;5;250:rs=0:di=01;38;5;198:ln=01;38;5;37:mh=00:pi=48;5;230;38;5;136;01:so=48;5;230;38;5;136;01:do=48;5;230;38;5;136;01:bd=48;5;230;38;5;244;01:cd=48;5;230;38;5;244;01:or=48;5;235;38;5;160:su=48;5;160;38;5;230:sg=48;5;136;38;5;230:ca=30;41:tw=48;5;64;38;5;230:ow=48;5;235;38;5;33:st=48;5;33;38;5;230:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:ex=01;38;5;82:*.cmd=00;38;5;82:*.exe=00;38;5;82:*.com=00;38;5;82:*.btm=00;38;5;82:*.bat=00;38;5;82:*.jpg=00;38;5;37:*.jpeg=00;38;5;37:*.png=00;38;5;37:*.gif=00;38;5;37:*.bmp=00;38;5;37:*.xbm=00;38;5;37:*.xpm=00;38;5;37:*.tif=00;38;5;37:*.tiff=00;38;5;37:*.pdf=00;38;5;98:*.odf=00;38;5;98:*.doc=00;38;5;98:*.ppt=00;38;5;98:*.pptx=00;38;5;98:*.db=00;38;5;98:*.aac=00;38;5;208:*.au=00;38;5;208:*.flac=00;38;5;208:*.mid=00;38;5;208:*.midi=00;38;5;208:*.mka=00;38;5;208:*.mp3=00;38;5;208:*.mpc=00;38;5;208:*.ogg=00;38;5;208:*.ra=00;38;5;208:*.wav=00;38;5;208:*.m4a=00;38;5;208:*.axa=00;38;5;208:*.oga=00;38;5;208:*.spx=00;38;5;208:*.xspf=00;38;5;208:*.mov=01;38;5;208:*.mpg=01;38;5;208:*.mpeg=01;38;5;208:*.3gp=01;38;5;208:*.m2v=01;38;5;208:*.mkv=01;38;5;208:*.ogm=01;38;5;208:*.mp4=01;38;5;208:*.m4v=01;38;5;208:*.mp4v=01;38;5;208:*.vob=01;38;5;208:*.qt=01;38;5;208:*.nuv=01;38;5;208:*.wmv=01;38;5;208:*.asf=01;38;5;208:*.rm=01;38;5;208:*.rmvb=01;38;5;208:*.flc=01;38;5;208:*.avi=01;38;5;208:*.fli=01;38;5;208:*.flv=01;38;5;208:*.gl=01;38;5;208:*.m2ts=01;38;5;208:*.divx=01;38;5;208:*.log=00;38;5;240:*.bak=00;38;5;240:*.aux=00;38;5;240:*.bbl=00;38;5;240:*.blg=00;38;5;240:*~=00;38;5;240:*#=00;38;5;240:*.part=00;38;5;240:*.incomplete=00;38;5;240:*.swp=00;38;5;240:*.tmp=00;38;5;240:*.temp=00;38;5;240:*.o=00;38;5;240:*.pyc=00;38;5;240:*.class=00;38;5;240:*.cache=00;38;5;240:';
export LS_COLORS

alias du='du -kh' # Makes a more readable output.
alias df='df -kTh'

#-------------------------------------------------------------
# The 'ls' family (this assumes you use a recent GNU ls).
#-------------------------------------------------------------
# Add colors for filetype and human-readable sizes by default on 'ls':
alias ls='ls -hG'
alias lx='ls -lXB' # Sort by extension.
alias lk='ls -lSr' # Sort by size, biggest last.
alias lt='ls -ltr' # Sort by date, most recent last.
alias lc='ls -ltcr' # Sort by/show change time,most recent last.
alias lu='ls -ltur' # Sort by/show access time,most recent last.

# The ubiquitous 'll': directories first, with alphanumeric sorting:
alias ll="ls -lv"
alias lm='ll |more' # Pipe through 'more'
alias lr='ll -R' # Recursive ls.
alias la='ll -A' # Show hidden files.
alias l='ls -CF'
alias tree='tree -Csuh' # Nice alternative to 'recursive ls' ...

# some more ls aliases
alias ll='ls -l'
alias la='ls -A'
alias l='ls -CF'
alias aps='sudo aptitude search'
alias ai='sudo aptitude install'

Expand Down
1 change: 1 addition & 0 deletions dev/paused/setup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Old profile files with lots of tricks - not sure I need them, but keep just in case..
9 changes: 8 additions & 1 deletion dev/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
- [ ] Look at "Documenting architectural decisions" format from that cool podcast

# Todos:
- [ ] Figure out logging.
- [ ] Figure out logging.
- [ ] Figure out dates and timezones
- [ ] cookbook -
- examples (calmlib and examples repo)
- pandas, plotting etc
- coding libs prompt template
- coding style
- libs that I use
21 changes: 0 additions & 21 deletions dev/unsorted/1/logging_utils.py

This file was deleted.

2 changes: 1 addition & 1 deletion dev/unsorted/3/found_on_the_web.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
import time

from calmlib import get_personal_logger
from calmlib.utils.logging_utils import get_personal_logger

logger = get_personal_logger(__name__)

Expand Down
7 changes: 3 additions & 4 deletions examples/e_archive/protobuf/compile_proto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from calmlib.proto_utils import compile_proto
from .proto_utils import compile_proto

if __name__ == '__main__':
compile_proto('./test.proto')

if __name__ == "__main__":
compile_proto("./test.proto")
77 changes: 77 additions & 0 deletions examples/e_archive/protobuf/pb2_example.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ def compile_proto(path, output_path=None, package_path=None):
"""
compile a proto file located at :path:
"""
from calmlib import run_cmd
from calmlib.utils.run_utils import run_cmd

# protoc -I=proto/ --python_out=proto/ proto/test.proto
path = Path(path)
if output_path is None:
Expand Down
10 changes: 4 additions & 6 deletions examples/e_archive/protobuf/touch_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
# 3. dump
# 4. load

from .test_pb2 import TUid
if __name__ == '__main__':
uid = TUid(Uid='uid1', AssociatedItems=['type1', 'type2'])

# str_dump = uid.

from .pb2_example import TUid

if __name__ == "__main__":
uid = TUid(Uid="uid1", AssociatedItems=["type1", "type2"])

# str_dump = uid.
Loading
Loading