Skip to content

Commit

Permalink
cleanup: FInishing up rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jun 6, 2024
1 parent 69eb989 commit 98483f8
Show file tree
Hide file tree
Showing 87 changed files with 1,190 additions and 1,038 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# biscuit
data/
extensions/*

# nuitka
biscuit.build
Expand Down
32 changes: 18 additions & 14 deletions extensions/black.py
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
from __future__ import annotations

__version__ = '0.0.1'
__version_info__ = tuple([ int(num) for num in __version__.split('.')])
__version__ = "0.0.1"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

import subprocess as sp
import typing

if typing.TYPE_CHECKING:
from biscuit import ExtensionsAPI
from src.biscuit import ExtensionsAPI


class Extension:
"""Black extension for Biscuit (author: @billyeatcookies)
Extension will automatically install black if not installed.
Contributes:
- a command to format python code in the active editor.
"""

def __init__(self, api: ExtensionsAPI) -> None:
self.api = api
self.base = api.base

def run(self) -> None:
self.check_black_installation()
self.api.commands.register_command('Black Formatter: Format active editor', self.format)

self.api.commands.register_command(
"Black Formatter: Format active editor", self.format
)

def check_black_installation(self):
reqs = sp.check_output(['pip', 'freeze'])
reqs = sp.check_output(["pip", "freeze"])
if not "black".encode() in reqs:
try:
sp.check_call(['pip', 'install', 'black'])
sp.check_call(["pip", "install", "black"])
except sp.CalledProcessError:
self.api.notifications.warning("Python extension requires black to be installed")
self.api.notifications.warning(
"Python extension requires black to be installed"
)

def format(self, *_) -> str:
editor = self.api.editorsmanager.active_editor
if not (editor and editor.content and editor.content.editable):
return

text = editor.content.text
if not text:
return

before = text.get_all_text()
try:
output = sp.check_output(['black', '-'], input=before.encode(text.encoding))
output = sp.check_output(["black", "-"], input=before.encode(text.encoding))
after = output.decode(text.encoding)
if before != after:
text.load_text(after)
Expand Down
10 changes: 6 additions & 4 deletions extensions/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

from __future__ import annotations

__version__ = '0.0.1'
__version_info__ = tuple([ int(num) for num in __version__.split('.')])
__version__ = "0.0.1"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

import typing

if typing.TYPE_CHECKING:
from src import ExtensionsAPI
from src.biscuit import ExtensionsAPI

# 4. Create a class named `Extension` as follows:


class Extension:
"""Dev Mode extension for Biscuit (author: @billyeatcookies)
Expand All @@ -30,4 +31,5 @@ def __init__(self, api: ExtensionsAPI) -> None:
def run(self) -> None:
self.api.notifications.info(f"Dev mode is enabled!")

# 5. Start customizing your extension!

# 5. Start customizing your extension!
34 changes: 19 additions & 15 deletions extensions/isort.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,57 @@
from __future__ import annotations

__version__ = '0.0.2'
__version_info__ = tuple([ int(num) for num in __version__.split('.')])
__version__ = "0.0.2"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

import subprocess as sp
import typing

if typing.TYPE_CHECKING:
from biscuit import ExtensionsAPI
from src.biscuit import ExtensionsAPI


class Extension:
"""Isort extension for Biscuit (author: @billyeatcookies)
Extension will automatically install isort if not installed.
Contributes:
- a command to reorder python imports in the active editor.
"""

def __init__(self, api: ExtensionsAPI) -> None:
self.api = api
self.base = api.base

def run(self) -> None:
self.check_isort_installation()
self.api.commands.register_command('Isort: Reorder imports in active editor ', self.format)

self.api.commands.register_command(
"Isort: Reorder imports in active editor ", self.format
)

def check_isort_installation(self):
reqs = sp.check_output(['pip', 'freeze'])
reqs = sp.check_output(["pip", "freeze"])
if not "isort".encode() in reqs:
try:
sp.check_call(['pip', 'install', 'isort'])
sp.check_call(["pip", "install", "isort"])
except sp.CalledProcessError:
self.api.notifications.warning("Python extension requires isort to be installed")
self.api.notifications.warning(
"Python extension requires isort to be installed"
)

def format(self, *_) -> str:
editor = self.api.editorsmanager.active_editor
if not (editor and editor.content and editor.content.editable):
return

text = editor.content.text
if not text:
return

before = text.get_all_text()
try:
output = sp.check_output(['isort', '-'], input=before.encode(text.encoding))
after = output.decode(text.encoding).replace('\r\n', '\n')
output = sp.check_output(["isort", "-"], input=before.encode(text.encoding))
after = output.decode(text.encoding).replace("\r\n", "\n")
if before != after:
text.load_text(after)
except sp.CalledProcessError as e:
Expand Down
38 changes: 22 additions & 16 deletions extensions/pastemyst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import webbrowser

__version__ = '0.0.1'
__version_info__ = tuple([ int(num) for num in __version__.split('.')])
__version__ = "0.0.1"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

import subprocess as sp
import typing

if typing.TYPE_CHECKING:
from biscuit import ExtensionsAPI
from src.biscuit import ExtensionsAPI


class Extension:
"""PasteMyst extension for Biscuit (author: @billyeatcookies)
Expand All @@ -23,34 +24,39 @@ def __init__(self, api: ExtensionsAPI) -> None:

def run(self) -> None:
self.check_pastemyst_installation()
self.api.commands.register_command('create paste', self.create_paste)
self.api.commands.register_command("create paste", self.create_paste)

def check_pastemyst_installation(self):
reqs = sp.check_output(['pip', 'freeze'])
reqs = sp.check_output(["pip", "freeze"])
if not "pastemyst".encode() in reqs:
try:
sp.check_call(['pip', 'install', 'pastemyst'])
sp.check_call(["pip", "install", "pastemyst"])
except sp.CalledProcessError:
self.api.notifications.warning("PasteMyst extension requires pypi/pastemyst to be installed")
self.api.notifications.warning(
"PasteMyst extension requires pypi/pastemyst to be installed"
)

def create_paste(self, *_) -> None:
"""Create a new paste on paste.myst.rs
Returns:
- str: The URL of the created paste
"""
editor = self.api.editors.active_editor()
if not editor or not editor.content or not editor.content.editable:
return self.api.notifications.warning("Active editor is not text type.")

try:
from pastemyst import Client, Paste, Pasty
paste = Paste(title=editor.filename,
pasties=[
Pasty(
title=editor.filename,
code=editor.content.text.get_all_text())
])

paste = Paste(
title=editor.filename,
pasties=[
Pasty(
title=editor.filename, code=editor.content.text.get_all_text()
)
],
)
client = Client()
paste = client.create_paste(paste)
webbrowser.open(paste.url)
Expand Down
50 changes: 32 additions & 18 deletions extensions/pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,73 @@
import os
import threading

__version__ = '0.0.1'
__version_info__ = tuple([ int(num) for num in __version__.split('.')])
__version__ = "0.0.1"
__version_info__ = tuple([int(num) for num in __version__.split(".")])


import subprocess as sp
import typing

if typing.TYPE_CHECKING:
from biscuit import ExtensionsAPI
from src.biscuit import ExtensionsAPI


class Extension:
"""pycodestyle extension for Biscuit (author: @billyeatcookies)
Extension will automatically install pycodestyle if not installed.
Contributes:
- problems panel logs
"""

def __init__(self, api: ExtensionsAPI):
self.api = api
self.base = api.base
self.problems = self.base.problems
self.em = self.base.editorsmanager

def run(self):
reqs = sp.check_output(['pip', 'freeze'])
reqs = sp.check_output(["pip", "freeze"])
if not "pycodestyle".encode() in reqs:
try:
sp.check_call(['pip', 'install', 'pycodestyle'])
sp.check_call(["pip", "install", "pycodestyle"])
except sp.CalledProcessError:
self.api.notifications.warning("Extension requires pycodestyle to be installed.")

self.api.commands.register_command('python: check style (all files)', self.check_all_files)
self.api.commands.register_command('python: check style (active file)', self.check_file)
self.api.notifications.warning(
"Extension requires pycodestyle to be installed."
)

self.api.commands.register_command(
"python: check style (all files)", self.check_all_files
)
self.api.commands.register_command(
"python: check style (active file)", self.check_file
)

def check_file(self, *_):
if not self.em.active_editor:
return self.check_all_files()

path = os.path.abspath(self.em.active_editor.path)
try:
output = sp.run(f'pycodestyle --first {path}', shell=True, capture_output=True, text=True)
output = sp.run(
f"pycodestyle --first {path}",
shell=True,
capture_output=True,
text=True,
)
self.problems.write(output.stdout)
except sp.CalledProcessError as e:
self.problems.clear()

def check_all_files(self, *_):
threading.Thread(target=self.threaded_check_all_files, daemon=True).start()

def threaded_check_all_files(self):
try:
output = sp.run('pycodestyle --first .', shell=True, capture_output=True, text=True)
output = sp.run(
"pycodestyle --first .", shell=True, capture_output=True, text=True
)
self.problems.write(output.stdout)
except sp.CalledProcessError as e:
self.problems.clear()
self.problems.clear()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "biscuit"
version = "2.80.0"
version = "2.90.0"
description = "The uncompromising code editor"
authors = ["Billy <billydevbusiness@gmail.com>"]
license = "MIT"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes
Binary file added resources/linux/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Binary file added resources/win32/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
6 changes: 3 additions & 3 deletions scripts/linux.spec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from PyInstaller.utils.hooks import collect_data_files
from PyInstaller.utils.hooks import collect_all

datas = [('../biscuit/res/*', 'res/')]
datas = [('../resources/*', 'resources/')]
binaries = []
hiddenimports = []
datas += collect_data_files('sv_ttk')
Expand All @@ -13,7 +13,7 @@ datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]


a = Analysis(
['../biscuit/__main__.py'],
['../src/__main__.py'],
pathex=[],
binaries=binaries,
datas=datas,
Expand Down Expand Up @@ -45,5 +45,5 @@ exe = EXE(
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon=['logo.ico'],
icon=['../resources/windows/logo.png'],
)
4 changes: 2 additions & 2 deletions scripts/macos.spec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_data_files, collect_dynamic_libs

datas = [('../biscuit/res/*', 'res/')]
datas = [('../resources/*', 'resources/')]
datas += collect_data_files('sv_ttk')
datas += collect_data_files('tkextrafont')
datas += collect_data_files('tkinterweb')
Expand All @@ -15,7 +15,7 @@ block_cipher = None


a = Analysis(
['../biscuit/__main__.py'],
['../src/__main__.py'],
pathex=[],
binaries=binaries,
datas=datas,
Expand Down
Loading

0 comments on commit 98483f8

Please sign in to comment.