Skip to content

Commit

Permalink
fix: Upward compatibility with 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
zlj-zz committed Jun 2, 2024
1 parent f2b87b1 commit 54b09f0
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 32 deletions.
20 changes: 11 additions & 9 deletions pigit/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def __init__(
self,
x: int = 1,
y: int = 1,
size: Tuple[int, int] | None = None,
content: List[str] | None = None,
size: Optional[Tuple[int, int]] = None,
content: Optional[List[str]] = None,
) -> None:
super().__init__(x, y, size, content)

Expand All @@ -45,7 +45,9 @@ def on_key(self, key: str):
c = repo_handle.load_file_diff(
f.name, f.tracked, f.has_staged_change, path=self.repo_path
).split("\n")
self.emit("goto", target="display_panel", source=self.NAME, key=f.name, content=c)
self.emit(
"goto", target="display_panel", source=self.NAME, key=f.name, content=c
)
elif key in {"a", " "}:
repo_handle.switch_file_status(f, self.repo_path)
self.fresh()
Expand All @@ -64,8 +66,8 @@ def __init__(
self,
x: int = 1,
y: int = 1,
size: Tuple[int, int] | None = None,
content: List[str] | None = None,
size: Optional[Tuple[int, int]] = None,
content: Optional[List[str]] = None,
) -> None:
super().__init__(x, y, size, content)

Expand Down Expand Up @@ -116,8 +118,8 @@ def __init__(
self,
x: int = 1,
y: int = 1,
size: Tuple[int, int] | None = None,
content: List[str] | None = None,
size: Optional[Tuple[int, int]] = None,
content: Optional[List[str]] = None,
) -> None:
super().__init__(x, y, size, content)

Expand Down Expand Up @@ -156,7 +158,7 @@ def __init__(
super().__init__(x, y, size, "")

self.come_from = ""
self.i_cache_key = ''
self.i_cache_key = ""
self.i_cache = {}

def fresh(self):
Expand All @@ -167,7 +169,7 @@ def update(self, action, **data):
self.i_cache[self.i_cache_key] = self._i

self.come_from = data.get("source", "")
self.i_cache_key = data.get('key', '')
self.i_cache_key = data.get("key", "")
self._content = data.get("content", "")

self._i = self.i_cache.get(self.i_cache_key, 0)
Expand Down
14 changes: 5 additions & 9 deletions pigit/cmdparse/completion/zsh.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,15 @@ def args2complete(self, args_dict: Dict) -> str:
for opt_name, opt_args in _sub_opts.items()
]

_sub_opt_str = (
textwrap.dedent(
"""
_sub_opt_str = textwrap.dedent(
"""
######################
# sub-commands helper
######################
"""
)
+ _TEMP_V
% (
"sub_opt",
textwrap.indent("\n".join(_subs), " "),
)
) + _TEMP_V % (
"sub_opt",
textwrap.indent("\n".join(_subs), " "),
)

self._process_sub_commands(
Expand Down
2 changes: 1 addition & 1 deletion pigit/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .ext.log import logger
from .ext.singleton import Singleton
from .ext.utils import confirm, strtobool ,traceback_info
from .ext.utils import confirm, strtobool, traceback_info


CONF_ERROR = "==error=="
Expand Down
8 changes: 4 additions & 4 deletions pigit/console_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


@time_it
def _active(prefixes:Optional[List] = None):
def _active(prefixes: Optional[List] = None):
try:
_args = (prefixes or []) + sys.argv[1:]
pigit(_args)
Expand All @@ -17,6 +17,6 @@ def _active(prefixes:Optional[List] = None):
# =============================================
# terminal entry
# =============================================
main = lambda :_active()
g = lambda :_active(["cmd"])
r = lambda :_active(["repo"])
main = lambda: _active()
g = lambda: _active(["cmd"])
r = lambda: _active(["repo"])
1 change: 0 additions & 1 deletion pigit/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,3 @@ def _(args: "Namespace", _):
console.echo(msg)

# yapf: enable

6 changes: 3 additions & 3 deletions pigit/ext/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
SILENT: Final = 1 << 5 # silent mode. output will be discarded.


def _detect_encoding(data:ByteString)->str:
encodings = ['utf-8', 'gbk','latin-1','iso-8859-1']
def _detect_encoding(data: ByteString) -> str:
encodings = ["utf-8", "gbk", "latin-1", "iso-8859-1"]

for encoding in encodings:
try:
Expand All @@ -42,7 +42,7 @@ def _detect_encoding(data:ByteString)->str:
except UnicodeDecodeError:
continue

return ''
return ""


@dataclasses.dataclass
Expand Down
6 changes: 3 additions & 3 deletions pigit/ext/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def strtobool(s: str) -> bool:
"""
s = s.lower()

if s in {"y", "yes", 't', 'true', "on", "1"}:
if s in {"y", "yes", "t", "true", "on", "1"}:
return True
elif s in {"n", "no", "f", "false", "off", "0"}:
return False
else:
raise ValueError('Not support string.')
raise ValueError("Not support string.")


def traceback_info(extra_msg: str = "null") -> str:
Expand Down Expand Up @@ -113,7 +113,7 @@ def similar_command(command: str, all_commands: Iterable) -> str:
# Square of sum of squares of word frequency difference.
frequency_sum_square: list[Tuple[str, int]] = list(
map(
lambda item: (item[0], int(sqrt(sum(map(lambda i: i**2, item[1]))))),
lambda item: (item[0], int(sqrt(sum(map(lambda i: i ** 2, item[1]))))),
frequency_difference.items(),
)
)
Expand Down
1 change: 0 additions & 1 deletion pigit/git/ignore/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# https://github.com/github/gitignore
# Generate by script `gitignore.py`.

Expand Down
1 change: 1 addition & 0 deletions pigit/git/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def get_file_str(self) -> str:

return file_name


@dataclass
class Commit:
"""Model class of a git commit."""
Expand Down
4 changes: 3 additions & 1 deletion pigit/git/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,9 @@ def cd_repo(self, repo: Optional[str] = None):
input_num = int(input("Please input the index:"))
if 0 <= input_num <= len(cur_cache):
path = exist_repos[cur_cache[input_num]]["path"]
print(self.executor.exec(command.format(path), cwd=".", flags=WAITING))
print(
self.executor.exec(command.format(path), cwd=".", flags=WAITING)
)
else:
print("Error: index out of range.")
except Exception:
Expand Down

0 comments on commit 54b09f0

Please sign in to comment.