Skip to content

Commit

Permalink
perf: improve startup performance (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
hnicke committed Mar 10, 2022
1 parent eb882bc commit aed211b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ type-coverage: ${reportDir}/linecount.txt
.PHONY: type-coverage







# logs are written to journald in order not to interfere with the TUI
logs:
journalctl --identifier sodalite --follow
Expand Down Expand Up @@ -89,6 +84,11 @@ setup-hooks:
done


import-profile: deps
${activate} \
&& pip install tuna \
&& tuna <(python -X importtime -m sodalite 2>&1 1>/dev/null)
.PHONY: import-profile

###################
#### Installer
Expand Down
8 changes: 5 additions & 3 deletions sodalite/core/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from pathlib import Path
from typing import Optional

from binaryornot import check

from sodalite.core import rating, config
from sodalite.core.hook import Hook
from sodalite.core.key import Key
Expand Down Expand Up @@ -116,7 +114,11 @@ def is_hidden(self) -> bool:

@functools.cached_property
def is_plain_text_file(self) -> bool:
return self.is_file and not self.name.endswith('.pdf') and not check.is_binary(str(self.path))
if self.is_file:
from binaryornot import check
return not self.name.endswith('.pdf') and not check.is_binary(str(self.path))
else:
return False

@functools.cached_property
def is_dir(self) -> bool:
Expand Down
3 changes: 1 addition & 2 deletions sodalite/ui/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from typing import Callable, Tuple, Optional
from typing import TYPE_CHECKING

import pyperclip

from sodalite.core import key as key_module, hook, buffer, operate, Navigator
from sodalite.core.action import Action
from sodalite.core.action_def import ActionName
Expand Down Expand Up @@ -154,6 +152,7 @@ def yank_file_content_to_clipboard(self) -> None:
self.yank_to_clipboard(entry.content)

def yank_to_clipboard(self, text: str) -> None:
import pyperclip
try:
pyperclip.copy(text)
text_to_log = text[0:60].replace("\n", "")
Expand Down
12 changes: 5 additions & 7 deletions sodalite/ui/highlighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
from pathlib import Path
from typing import Pattern, Generator

import pygments
from pygments import lexers, token
from pygments.lexers.shell import BashLexer

from sodalite.core.entry import Entry
from sodalite.ui import theme

Expand All @@ -21,6 +17,7 @@ def __init__(self, content, line_number):
self.numbered_content = [formatted_line_number] + content

def bold_headings(self, content):
from pygments import token
heading = None
new_content = []
for attr, word in content:
Expand All @@ -47,16 +44,17 @@ def compute_highlighting(entry: Entry) -> Generator[HighlightedLine, None, None]


def find_lexer(file: Path, content: str):
import pygments
try:
if file.name in ('.gitignore', '.dockerignore'):
from pygments.lexers.shell import BashLexer
lexer = BashLexer()
else:
lexer = lexers.guess_lexer_for_filename(str(file), content, stripnl=False,
ensurenl=False)
lexer = pygments.lexers.guess_lexer_for_filename(str(file), content, stripnl=False, ensurenl=False)
logger.debug('Detected lexer by filename')
except pygments.util.ClassNotFound:
try:
lexer = lexers.guess_lexer(content, stripnl=False, ensurenl=False)
lexer = pygments.lexers.guess_lexer(content, stripnl=False, ensurenl=False)
logger.debug('Detected lexer by file content')
except pygments.util.ClassNotFound:
lexer = BashLexer(stripnl=False, ensurenl=False)
Expand Down

0 comments on commit aed211b

Please sign in to comment.