update readme (#142)

* Add contacts shortcut and link to config file

* Remove logging in utils

* Remove unused imports and create script for checking formatting

* Remove unused import <Iterable> in models

* Fix check.sh script

* Reformat check.sh

* Update isort

* Add check flag for black
This commit is contained in:
Nameless 2020-07-16 04:26:14 +08:00 committed by GitHub
parent b37bba8fb7
commit 4aaf9d9d1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 30 deletions

View file

@ -1,28 +1,22 @@
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
@ -32,16 +26,8 @@ jobs:
- name: Install tools
run: |
pip install black==19.10b0 mypy==0.770 isort==4.3.21
pip install black==19.10b0 mypy==0.770 isort==5.1.0 flake8==3.8.3
- name: Check formatting with black
- name: Check formatting and run linters
run: |
black --check tg
- name: Check sort formatting
run: |
isort -c tg/*.py
- name: Check types with mypy
run: |
mypy tg --warn-redundant-casts --warn-unused-ignores --no-warn-no-return --warn-unreachable --strict-equality --ignore-missing-imports --warn-unused-configs --disallow-untyped-calls --disallow-untyped-defs --disallow-incomplete-defs --check-untyped-defs --disallow-untyped-decorators
sh check.sh

20
check.sh Executable file
View file

@ -0,0 +1,20 @@
#!/bin/sh
set -ex
echo Checking and formatting with black...
black --check .
echo Python type checking...
mypy tg --warn-redundant-casts --warn-unused-ignores \
--no-warn-no-return --warn-unreachable --strict-equality \
--ignore-missing-imports --warn-unused-configs \
--disallow-untyped-calls --disallow-untyped-defs \
--disallow-incomplete-defs --check-untyped-defs \
--disallow-untyped-decorators
echo Checking import sorting...
isort -c tg/*.py
echo Checking unused imports...
flake8 --select=F401

View file

@ -90,6 +90,8 @@ PHONE = "[your phone number]"
### Advanced configuration:
All configurable variables can be found [here](https://github.com/paul-nameless/tg/blob/master/tg/config.py)
```python
import os
@ -210,6 +212,7 @@ For navigation arrow keys also can be used.
- `p`: pin/unpin current chat
- `u`: mark read/unread
- `r`: read current chat
- `c`: show list of contacts
- `?`: show help
## Msgs:

View file

@ -9,6 +9,7 @@ from tempfile import NamedTemporaryFile
from typing import Any, Callable, Dict, List, Optional
from telegram.utils import AsyncResult
from tg import config
from tg.models import Model
from tg.msg import MsgProxy

View file

@ -2,7 +2,7 @@ import logging
import sys
import time
from collections import defaultdict
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
from typing import Any, Dict, List, Optional, Set, Tuple
from tg.msg import MsgProxy
from tg.tdlib import ChatAction, Tdlib, UserStatus

View file

@ -27,9 +27,6 @@ class ChatType(Enum):
channel = "channel"
chatTypeSecret = "secret"
def is_group(self, chat_type: "Union[str, ChatType]") -> bool:
return chat_type in (self.chatTypeSupergroup, self.chatTypeBasicGroup)
class UserStatus(Enum):
userStatusEmpty = ""
@ -276,3 +273,10 @@ def get_chat_type(chat: Dict[str, Any]) -> Optional[ChatType]:
except KeyError:
pass
return None
def is_group(chat_type: Union[str, ChatType]) -> bool:
return chat_type in (
ChatType.chatTypeSupergroup,
ChatType.chatTypeBasicGroup,
)

View file

@ -19,7 +19,7 @@ from subprocess import CompletedProcess
from types import TracebackType
from typing import Any, Optional, Tuple, Type
from tg import colors, config
from tg import config
log = logging.getLogger(__name__)
emoji_pattern = re.compile(
@ -240,7 +240,6 @@ def pretty_ts(ts: int) -> str:
diff = now - datetime.utcfromtimestamp(ts)
second_diff = diff.seconds
day_diff = diff.days
log.info("diff:: %s, %s, %s", ts, second_diff, day_diff)
if day_diff < 0:
return ""

View file

@ -1,14 +1,15 @@
import curses
import logging
from _curses import window # type: ignore
from datetime import datetime
from typing import Any, Dict, List, Optional, Tuple, Union, cast
from _curses import window # type: ignore
from tg import config
from tg.colors import bold, cyan, get_color, magenta, reverse, white, yellow
from tg.models import Model, UserModel
from tg.msg import MsgProxy
from tg.tdlib import ChatType, get_chat_type
from tg.tdlib import ChatType, get_chat_type, is_group
from tg.utils import emoji_pattern, get_color_by_str, num, truncate_to_len
log = logging.getLogger(__name__)
@ -215,7 +216,7 @@ class ChatView:
if user:
last_msg_sender = get_user_label(self.model.users, user)
chat_type = get_chat_type(chat)
if chat_type and chat_type.is_group(chat_type):
if chat_type and is_group(chat_type):
return last_msg_sender, last_msg
return None, last_msg
@ -629,7 +630,7 @@ def _get_action_label(users: UserModel, chat: Dict[str, Any]) -> Optional[str]:
if actioner and action:
label = f"{action}..."
chat_type = get_chat_type(chat)
if chat_type and chat_type.is_group(chat_type):
if chat_type and is_group(chat_type):
user_label = get_user_label(users, actioner)
label = f"{user_label} {label}"