Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Moosems/salve
Browse files Browse the repository at this point in the history
  • Loading branch information
Moosems committed Jun 17, 2024
2 parents 2d9805c + cdef951 commit 3795762
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 25 deletions.
4 changes: 4 additions & 0 deletions salve_ipc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from beartype.claw import beartype_this_package

from .ipc import IPC # noqa: F401
from .misc import COMMANDS, Response # noqa: F401
from .server_functions import ( # noqa: F401
Token,
generic_tokens,
is_unicode_letter,
)

beartype_this_package()
10 changes: 0 additions & 10 deletions salve_ipc/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from pathlib import Path
from random import randint

from beartype import beartype

from .misc import COMMANDS, Notification, Request, Response
from .server import Server

Expand All @@ -19,7 +17,6 @@ class IPC:
- IPC.kill_IPC()
"""

@beartype
def __init__(self, id_max: int = 15_000) -> None:
self.all_ids: list[int] = []
self.id_max = id_max
Expand Down Expand Up @@ -55,7 +52,6 @@ def create_server(self) -> None:
for filename, data in files_copy.items():
self.update_file(filename, data)

@beartype
def create_message(self, type: str, **kwargs) -> None:
"""Creates a Message based on the args and kwawrgs provided. Highly flexible. - internal API"""
id = randint(1, self.id_max) # 0 is reserved for the empty case
Expand Down Expand Up @@ -95,7 +91,6 @@ def create_message(self, type: str, **kwargs) -> None:
}
self.requests_queue.put(notification)

@beartype
def request(
self,
command: str,
Expand Down Expand Up @@ -130,7 +125,6 @@ def request(
definition_starters=definition_starters,
)

@beartype
def cancel_request(self, command: str):
"""Cancels a request of type command - external API"""
if command not in COMMANDS:
Expand All @@ -141,7 +135,6 @@ def cancel_request(self, command: str):

self.current_ids[command] = 0

@beartype
def parse_response(self, res: Response) -> None:
"""Parses main_server output line and discards useless responses - internal API"""
id = res["id"]
Expand All @@ -162,7 +155,6 @@ def check_responses(self) -> None:
while not self.response_queue.empty():
self.parse_response(self.response_queue.get())

@beartype
def get_response(self, command: str) -> Response | None:
"""Runs IPC.check_responses() and returns the current response of type command if it has been returned - external API"""
if command not in COMMANDS:
Expand All @@ -176,7 +168,6 @@ def get_response(self, command: str) -> Response | None:
self.newest_responses[command] = None
return response

@beartype
def update_file(self, filename: str, current_state: str) -> None:
"""Updates files in the system - external API"""

Expand All @@ -186,7 +177,6 @@ def update_file(self, filename: str, current_state: str) -> None:
"notification", filename=filename, contents=current_state
)

@beartype
def remove_file(self, filename: str) -> None:
"""Removes a file from the main_server - external API"""
if filename not in list(self.files.keys()):
Expand Down
5 changes: 0 additions & 5 deletions salve_ipc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from multiprocessing.queues import Queue as GenericClassQueue
from time import sleep

from beartype import beartype
from pyeditorconfig import get_config

from .misc import COMMANDS, Notification, Request, Response
Expand All @@ -18,7 +17,6 @@
class Server:
"""Handles input from the user and returns output from special functions designed to make the job easy. Not an external API."""

@beartype
def __init__(
self,
server_end: Connection,
Expand All @@ -41,7 +39,6 @@ def __init__(
self.run_tasks()
sleep(0.0025)

@beartype
def simple_id_response(self, id: int, cancelled: bool = True) -> None:
response: Response = {
"id": id,
Expand All @@ -50,7 +47,6 @@ def simple_id_response(self, id: int, cancelled: bool = True) -> None:
}
self.response_queue.put(response)

@beartype
def parse_line(self, message: Request | Notification) -> None:
id: int = message["id"]
match message["type"]:
Expand Down Expand Up @@ -83,7 +79,6 @@ def cancel_all_ids_except_newest(self) -> None:

self.all_ids = []

@beartype
def handle_request(self, request: Request) -> None:
command: str = request["command"]
id: int = self.newest_ids[command]
Expand Down
10 changes: 0 additions & 10 deletions salve_ipc/server_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from re import Match, Pattern, compile
from unicodedata import category

from beartype import beartype
from pygments import lex
from pygments.lexer import Lexer
from pygments.lexers import get_lexer_by_name
Expand Down Expand Up @@ -43,7 +42,6 @@
Token = tuple[tuple[int, int], int, str]


@beartype
def get_new_token_type(old_token: str) -> str:
"""Turns pygments token types into a generic predefined Token"""
new_type: str = generic_tokens[0]
Expand All @@ -57,7 +55,6 @@ def get_new_token_type(old_token: str) -> str:
url_regex: Pattern = compile(r"(ftp|http|https):\/\/[a-zA-Z0-9_-]")


@beartype
def get_urls(lines: list[str], start_line: int = 1) -> list[Token]:
start_pos: tuple[int, int] = (start_line, 0)
url_toks: list[Token] = []
Expand Down Expand Up @@ -149,7 +146,6 @@ def get_urls(lines: list[str], start_line: int = 1) -> list[Token]:
}


@beartype
def find_hidden_chars(lines: list[str], start_line: int = 1) -> list[Token]:
hidden_char_indexes: list[tuple[tuple[int, int], str]] = [
((line_index + start_line, char_index), char)
Expand All @@ -163,7 +159,6 @@ def find_hidden_chars(lines: list[str], start_line: int = 1) -> list[Token]:
return tok_list


@beartype
def get_highlights(
full_text: str,
language: str = "text",
Expand Down Expand Up @@ -205,13 +200,11 @@ def get_highlights(
return new_tokens


@beartype
def is_unicode_letter(char: str) -> bool:
"""Returns a boolean value of whether a given unicode char is a letter or not (includes "_" for code completion reasons)"""
return char == "_" or category(char).startswith("L")


@beartype
def find_words(full_text: str) -> list[str]:
"""Returns a list of all words in a given piece of text"""
words_list = []
Expand All @@ -237,7 +230,6 @@ def find_words(full_text: str) -> list[str]:
return words_list


@beartype
def find_autocompletions(
full_text: str, expected_keywords: list[str], current_word: str
) -> list[str]:
Expand Down Expand Up @@ -271,7 +263,6 @@ def find_autocompletions(
return autocomplete_matches


@beartype
def get_replacements(
full_text: str, expected_keywords: list[str], replaceable_word: str
) -> list[str]:
Expand Down Expand Up @@ -306,7 +297,6 @@ def get_replacements(
return ranked_matches


@beartype
def get_definition(
full_text: str,
definition_starters: list[tuple[str, str]],
Expand Down

0 comments on commit 3795762

Please sign in to comment.