Skip to content

Commit

Permalink
Start using isort, thonny#1274
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed Feb 16, 2022
1 parent de7bfd4 commit 77b1fc6
Show file tree
Hide file tree
Showing 122 changed files with 389 additions and 416 deletions.
2 changes: 2 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
venv310\Scripts\python.exe -m isort thonny
venv310\Scripts\python.exe -m black thonny

4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

. venv/bin/activate

#echo "isorting ..."
#isort -rc thonny
echo "isorting ..."
isort thonny

echo
echo "blackening ..."
Expand Down
1 change: 1 addition & 0 deletions misc/jedi_problem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from operator import abs

from jedi import Script

code = """print(end"""
s = Script(code=code)
comps = s.complete(line=1, column=len(code), fuzzy=True)
Expand Down
7 changes: 4 additions & 3 deletions misc/mp/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
"""

import ast
import os
import sys
import time
import os
import ast

try:
stdout = sys.stdout.buffer
Expand Down Expand Up @@ -212,8 +212,9 @@ class ProcessPtyToTerminal:
this PTY."""

def __init__(self, cmd):
import subprocess
import re
import subprocess

import serial

self.subp = subprocess.Popen(
Expand Down
3 changes: 2 additions & 1 deletion misc/mp/threads_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pyboard
import time

import pyboard

thread_script = """
import machine
from machine import Pin
Expand Down
3 changes: 2 additions & 1 deletion misc/mp_paste_mode.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import serial
import time

import serial

PORT = "/dev/ttyACM0"

# The output of following code tells me whether the code was received intact or not
Expand Down
3 changes: 2 additions & 1 deletion misc/mp_repl_experiment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import serial
import time

import serial

PORT = "/dev/ttyACM0"

MODE = "paste" # "paste" or "raw"
Expand Down
3 changes: 2 additions & 1 deletion misc/mp_thread_exp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import serial
import time

import serial

PORT = "/dev/ttyACM0"

CTRL_C = b"\x03"
Expand Down
7 changes: 4 additions & 3 deletions misc/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@
"""

import ast
import os
import sys
import time
import os
import ast

try:
stdout = sys.stdout.buffer
Expand Down Expand Up @@ -212,8 +212,9 @@ class ProcessPtyToTerminal:
this PTY."""

def __init__(self, cmd):
import subprocess
import re
import subprocess

import serial

self.subp = subprocess.Popen(
Expand Down
5 changes: 3 additions & 2 deletions misc/thre.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import signal
from _thread import interrupt_main
from threading import Thread
from time import sleep
import os
import signal


def inter():
Expand All @@ -18,6 +18,7 @@ def inter():
#Thread(target=inter).start()
#"""
import tkinter

root = tkinter.Tk()
#root.focus_set()
root.mainloop()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Bootstrap script for Thonny as an application bundle.
# Inspired by https://github.com/python/cpython/blob/master/Mac/IDLE/IDLE.app/Contents/Resources/idlemain.py
import sys, os.path
import os.path
import sys

# Make sure sys.executable points to the python interpreter inside the
# framework, instead of at the helper executable inside the application
Expand Down
2 changes: 1 addition & 1 deletion packaging/mac/make_scripts_relocatable.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import sys
import os.path
import sys

target_dir = sys.argv[1]
script_dir = os.path.abspath(os.path.dirname(__file__))
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from setuptools import find_packages, setup


def recursive_files(directory):
paths = []
for (path, _, filenames) in os.walk(directory):
Expand Down
8 changes: 4 additions & 4 deletions thonny/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from thonny.common import is_virtual_executable, is_private_python
from thonny.common import is_private_python, is_virtual_executable

_last_module_count = 0
_last_modules = set()
Expand Down Expand Up @@ -38,8 +38,8 @@ def report_time(label: str) -> None:

report_time("After defining report_time")

import os.path
import logging
import os.path
from typing import TYPE_CHECKING, Optional, cast

SINGLE_INSTANCE_DEFAULT = True
Expand Down Expand Up @@ -248,14 +248,14 @@ def launch():
return 0

except SystemExit as e:
from tkinter import messagebox, _default_root
from tkinter import _default_root, messagebox

messagebox.showerror("System exit", str(e), master=_default_root)
return -1

except Exception:
from logging import exception
import traceback
from logging import exception

exception("Internal launch or mainloop error")
from thonny import ui_utils
Expand Down
8 changes: 4 additions & 4 deletions thonny/assistance.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import ast
import datetime
from logging import getLogger
import os.path
import subprocess
import sys
import textwrap
import tkinter as tk
from collections import namedtuple
from logging import getLogger
from tkinter import messagebox, ttk
from typing import Dict # pylint disable=unused-import
from typing import List # pylint disable=unused-import
Expand All @@ -19,14 +19,14 @@
import thonny
from thonny import get_runner, get_workbench, rst_utils, tktextext, ui_utils
from thonny.common import (
REPL_PSEUDO_FILENAME,
STRING_PSEUDO_FILENAME,
ToplevelResponse,
read_source,
STRING_PSEUDO_FILENAME,
REPL_PSEUDO_FILENAME,
)
from thonny.languages import tr
from thonny.misc_utils import levenshtein_damerau_distance, running_on_mac_os
from thonny.ui_utils import CommonDialog, scrollbar_style, get_hyperlink_cursor
from thonny.ui_utils import CommonDialog, get_hyperlink_cursor, scrollbar_style

logger = getLogger(__name__)

Expand Down
27 changes: 13 additions & 14 deletions thonny/backend.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# -*- coding: utf-8 -*-
import warnings

import _thread
import io
from logging import getLogger
import os.path
import pathlib
import queue
Expand All @@ -12,30 +9,32 @@
import threading
import time
import traceback
from abc import abstractmethod, ABC
from typing import BinaryIO, Callable, List, Dict, Optional, Iterable, Union, Any
import warnings
from abc import ABC, abstractmethod
from logging import getLogger
from typing import Any, BinaryIO, Callable, Dict, Iterable, List, Optional, Union

import thonny
from thonny import report_time
from thonny.common import IGNORED_FILES_AND_DIRS # TODO: try to get rid of this
from thonny.common import (
BackendEvent,
CommandToBackend,
EOFCommand,
ImmediateCommand,
InlineCommand,
InlineResponse,
InputSubmission,
MessageFromBackend,
ToplevelCommand,
ToplevelResponse,
UserError,
parse_message,
serialize_message,
ImmediateCommand,
MessageFromBackend,
CommandToBackend,
universal_dirname,
read_one_incoming_message_str,
serialize_message,
try_load_modules_with_frontend_sys_path,
UserError,
universal_dirname,
)
from thonny.common import IGNORED_FILES_AND_DIRS # TODO: try to get rid of this

NEW_DIR_MODE = 0o755

Expand Down Expand Up @@ -395,8 +394,8 @@ def _cmd_get_editor_calltip(self, cmd):
)

def _cmd_get_shell_calltip(self, cmd):
from thonny import jedi_utils
import __main__
from thonny import jedi_utils

signatures = jedi_utils.get_interpreter_signatures(
cmd.source, [__main__.__dict__], sys_path=self._get_sys_path_for_analysis()
Expand Down Expand Up @@ -704,7 +703,7 @@ def __init__(self, host, user, password, interpreter, cwd):
# UploadDownloadMixin.__init__(self)
try:
import paramiko
from paramiko.client import SSHClient, AutoAddPolicy
from paramiko.client import AutoAddPolicy, SSHClient
except ImportError:
print(
"\nThis back-end requires an extra package named 'paramiko'."
Expand Down
17 changes: 9 additions & 8 deletions thonny/base_file_browser.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import datetime
from logging import getLogger
import os.path
import shutil
import stat
import subprocess
import time
import tkinter as tk
from tkinter import messagebox, ttk, simpledialog
import stat, shutil
from logging import getLogger
from tkinter import messagebox, simpledialog, ttk
from typing import Optional

from thonny import get_runner, get_workbench, misc_utils, tktextext
from thonny.common import InlineCommand, get_dirs_children_info, UserError
from thonny.common import InlineCommand, UserError, get_dirs_children_info
from thonny.languages import tr
from thonny.misc_utils import running_on_windows, sizeof_fmt, running_on_mac_os
from thonny.misc_utils import running_on_mac_os, running_on_windows, sizeof_fmt
from thonny.ui_utils import (
CommonDialog,
ask_one_from_choices,
ask_string,
create_string_var,
get_hyperlink_cursor,
lookup_style_option,
scrollbar_style,
show_dialog,
ask_string,
ask_one_from_choices,
get_hyperlink_cursor,
)

_dummy_node_text = "..."
Expand Down
2 changes: 1 addition & 1 deletion thonny/codeview.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from thonny import get_workbench, roughparse, tktextext, ui_utils
from thonny.common import TextRange
from thonny.tktextext import EnhancedText
from thonny.ui_utils import EnhancedTextWithLogging, scrollbar_style, ask_string
from thonny.ui_utils import EnhancedTextWithLogging, ask_string, scrollbar_style

_syntax_options = {} # type: Dict[str, Union[str, int]]
# BREAKPOINT_SYMBOL = "•" # Bullet
Expand Down
8 changes: 4 additions & 4 deletions thonny/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
"""
Classes used both by front-end and back-end
"""
from logging import getLogger
import os.path
import site
from dataclasses import dataclass

import sys
from collections import namedtuple
from typing import List, Optional, Dict, Tuple, Callable, Any # @UnusedImport
from dataclasses import dataclass
from logging import getLogger
from typing import Any, Callable, Dict, List, Optional, Tuple # @UnusedImport

logger = getLogger(__name__)

Expand Down Expand Up @@ -620,6 +619,7 @@ def get_windows_network_locations():

def get_windows_lnk_target(lnk_file_path):
import subprocess

import thonny

script_path = os.path.join(os.path.dirname(thonny.__file__), "res", "PrintLnkTarget.vbs")
Expand Down
4 changes: 1 addition & 3 deletions thonny/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
import ast
import configparser
import datetime
from logging import getLogger
import os.path
import sys
import tkinter as tk
from configparser import ConfigParser
from logging import exception
from logging import exception, getLogger

from thonny import THONNY_USER_DIR


logger = getLogger(__name__)

_manager_cache = {}
Expand Down
2 changes: 1 addition & 1 deletion thonny/config_ui.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from logging import getLogger
import tkinter as tk
from logging import getLogger
from tkinter import ttk
from typing import Optional

Expand Down
6 changes: 3 additions & 3 deletions thonny/editor_helpers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from logging import getLogger
import tkinter as tk
import traceback
from typing import Optional, Tuple, List
from logging import getLogger
from typing import List, Optional, Tuple

from thonny import get_workbench
from thonny.codeview import SyntaxText, CodeViewText, get_syntax_options_for_tag
from thonny.codeview import CodeViewText, SyntaxText, get_syntax_options_for_tag
from thonny.common import SignatureInfo, SignatureParameter
from thonny.editors import Editor
from thonny.misc_utils import running_on_mac_os
Expand Down
Loading

0 comments on commit 77b1fc6

Please sign in to comment.